From 1678bf0cb8f4540069e06237671f42fa6750dbf4 Mon Sep 17 00:00:00 2001 From: purocean Date: Wed, 9 Oct 2024 22:23:45 +0800 Subject: [PATCH] fix: fix export pdf scale param --- src/renderer/components/ExportPanel.vue | 8 +++++--- src/renderer/types.ts | 9 ++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/renderer/components/ExportPanel.vue b/src/renderer/components/ExportPanel.vue index 1f9cbe22..05060660 100644 --- a/src/renderer/components/ExportPanel.vue +++ b/src/renderer/components/ExportPanel.vue @@ -43,7 +43,7 @@
@@ -116,7 +116,7 @@ export default defineComponent({ pdfOptions: { landscape: '', pageSize: 'A4' as 'A4' | 'A3' | 'A5' | 'Legal' | 'Letter' | 'Tabloid', - scaleFactor: '100', + scaleFactor: 100, printBackground: true, } }) @@ -152,12 +152,14 @@ export default defineComponent({ await printCurrentDocument() } else { const { landscape, pageSize, scaleFactor, printBackground } = convert.pdfOptions + convert.pdfOptions.scaleFactor = Math.min(200, Math.max(10, convert.pdfOptions.scaleFactor)) + const buffer = await printCurrentDocumentToPDF({ pageSize, printBackground, landscape: Boolean(landscape), - scaleFactor: Number(scaleFactor) + scale: scaleFactor / 100, }) downloadContent(name + '.pdf', buffer, 'application/pdf') diff --git a/src/renderer/types.ts b/src/renderer/types.ts index 95266b8e..30eac8fa 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -1,5 +1,5 @@ import type { VNode } from 'vue' -import type { OpenDialogOptions } from 'electron' +import type { OpenDialogOptions, PrintToPDFOptions } from 'electron' import type { Language, MsgPath } from '@share/i18n' import type { Doc, FileItem, PathItem, Repo } from '@share/types' import type MarkdownIt from 'markdown-it' @@ -264,12 +264,7 @@ export type SettingGroup = 'repos' | 'appearance' | 'editor' | 'image' | 'proxy' export type RegistryHostname = 'registry.npmjs.org' | 'registry.npmmirror.com' export type Keybinding = { type: 'workbench' | 'editor' | 'application', keys: string | null, command: string } -export type PrintOpts = { - landscape?: boolean, - pageSize?: 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6' | 'Legal' | 'Letter' | 'Tabloid' | 'Ledger' | { height: number, width: number } - scaleFactor?: number, - printBackground?: boolean, -} +export type PrintOpts = PrintToPDFOptions export type ConvertOpts = { fromType: 'markdown' | 'html',