Skip to content

Commit ebcb86b

Browse files
committed
fix: respect aspect ratio for exporting
1 parent 7da22b6 commit ebcb86b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/slidev/node/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export async function build(
113113
output: join(config.build.outDir, 'slidev-exported.pdf'),
114114
base: config.base,
115115
dark: options.data.config.colorSchema === 'dark',
116+
width: 1920,
117+
height: Math.round(1920 / options.data.config.aspectRatio),
116118
})
117119
server.close()
118120
}

packages/slidev/node/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ cli.command(
276276
await server.listen(port)
277277
printInfo(options)
278278
parser.filterDisabled(options.data)
279+
const width = 1920
280+
const height = Math.round(width / options.data.config.aspectRatio)
279281
output = await exportSlides({
280282
port,
281283
total: options.data.slides.length,
@@ -285,6 +287,8 @@ cli.command(
285287
timeout,
286288
dark,
287289
routerMode: options.data.config.routerMode,
290+
width,
291+
height,
288292
})
289293
console.log(`${green(' ✓ ')}${dim('exported to ')}./${output}\n`)
290294
server.close()

packages/slidev/node/export.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export interface ExportOptions {
1616
timeout?: number
1717
dark?: boolean
1818
routerMode?: 'hash' | 'history'
19+
width?: number
20+
height?: number
1921
}
2022

2123
function createSlidevProgress() {
@@ -64,6 +66,8 @@ export async function exportSlides({
6466
timeout = 500,
6567
dark = false,
6668
routerMode = 'history',
69+
width = 1920,
70+
height = 1080,
6771
}: ExportOptions) {
6872
if (!packageExists('playwright-chromium'))
6973
throw new Error('The exporting for Slidev is powered by Playwright, please installed it via `npm i playwright-chromium`')
@@ -72,8 +76,8 @@ export async function exportSlides({
7276
const browser = await chromium.launch()
7377
const context = await browser.newContext({
7478
viewport: {
75-
width: 1920,
76-
height: 1080,
79+
width,
80+
height,
7781
},
7882
deviceScaleFactor: 1,
7983
})
@@ -105,8 +109,8 @@ export async function exportSlides({
105109
for (const i of pages) {
106110
await go(i)
107111
const pdf = await page.pdf({
108-
width: 1920,
109-
height: 1080,
112+
width,
113+
height,
110114
margin: {
111115
left: 0,
112116
top: 0,

0 commit comments

Comments
 (0)