返回 slidev
exporting.md
根目录 / docs / guide / exporting.md
1 ---
2 outline: deep
3 ---
4
5 # Exporting
6
7 Usually the slides are displayed in a web browser, but you can also export them to PDF, PPTX, PNG, or Markdown files for sharing or printing. This feature is available through the CLI command [`slidev export`](../builtin/cli#export).
8
9 However, interactive features in your slides may not be available in the exported files. You can build and host your slides as a web application to keep the interactivity. See [Building and Hosting](./hosting) for more information.
10
11 ## The Browser Exporter <Badge> Recommended </Badge> {#browser}
12
13 > Available since v0.50.0-beta.11
14
15 Slidev provides a UI in the browser for exporting your slides. You can access it by clicking the "Export" button in "More options" menu in the [navigation bar](./ui#navigation-bar), or go to `http://localhost:<port>/export` directly.
16
17 In the UI, you can export the slides as PDF, or capture the slides as images and download them as a PPTX or zip file.
18
19 Note that browsers other than **modern Chromium-based browsers** may not work well with the exporting UI. If you encounter any issues, please try use the CLI instead.
20
21 > The following content of this page is for the CLI only.
22
23 ## The CLI {#cli}
24
25 Exporting to PDF, PPTX, or PNG relies on [Playwright](https://playwright.dev) for rendering the slides. Therefore [`playwright-chromium`](https://npmjs.com/package/playwright-chromium) is required to be installed in your project:
26
27 ::: code-group
28
29 ```bash [pnpm]
30 $ pnpm add -D playwright-chromium
31 ```
32
33 ```bash [npm]
34 $ npm i -D playwright-chromium
35 ```
36
37 ```bash [yarn]
38 $ yarn add -D playwright-chromium
39 ```
40
41 ```bash [bun]
42 $ bun add -D playwright-chromium
43 ```
44
45 ```bash [deno]
46 $ deno add -D npm:playwright-chromium
47 ```
48
49 :::
50
51 ## Formats
52
53 ### PDF
54
55 After installing `playwright-chromium` as described above, you can export your slides to PDF using the following command:
56
57 ```bash
58 $ slidev export
59 ```
60
61 By default, the PDF will be placed at `./slides-export.pdf`.
62
63 ### PPTX
64
65 Slidev can also export your slides as a PPTX file:
66
67 ```bash
68 $ slidev export --format pptx
69 ```
70
71 Note that all the slides in the PPTX file will be exported as images, so the text will not be selectable. Presenter notes will be conveyed into the PPTX file on a per-slide basis.
72
73 In this mode, the `--with-clicks` option is enabled by default. To disable it, pass `--with-clicks false`.
74
75 ### PNGs and Markdown
76
77 When passing in the `--format png` option, Slidev will export PNG images for each slide instead of a PDF:
78
79 ```bash
80 $ slidev export --format png
81 ```
82
83 You can also compile a markdown file composed of compiled png using `--format md`:
84
85 ```bash
86 $ slidev export --format md
87 ```
88
89 ## Options
90
91 Here are some common options you can use with the `slidev export` command. For a full list of options, see the [CLI documentation](../builtin/cli#export).
92
93 ### Export Clicks Steps
94
95 By default, Slidev exports one page per slide with clicks animations disabled. If you want to export slides with multiple steps into multiple pages, pass the `--with-clicks` option:
96
97 ```bash
98 $ slidev export --with-clicks
99 ```
100
101 ### Output Filename
102
103 You can specify the output filename with the `--output` option:
104
105 ```bash
106 $ slidev export --output my-pdf-export
107 ```
108
109 Or in the headmatter configuration:
110
111 ```yaml
112 ---
113 exportFilename: my-pdf-export
114 ---
115 ```
116
117 ### Export with Range
118
119 By default, all slides in the presentation are exported. If you want to export a specific slide or a range of slides you can set the `--range` option and specify which slides you would like to export:
120
121 ```bash
122 $ slidev export --range 1,6-8,10
123 ```
124
125 This option accepts both specific slide numbers and ranges. The example above would export slides 1,6,7,8 and 10.
126
127 ### Multiple Exports
128
129 You can also export multiple slides at once:
130
131 ```bash
132 $ slidev export slides1.md slides2.md
133 ```
134
135 Or (only available in certain shells):
136
137 ```bash
138 $ slidev export *.md
139 ```
140
141 In this case, each input file will generate its own PDF file.
142
143 ### Dark Mode
144
145 In case you want to export your slides using the dark version of the theme, use the `--dark` option:
146
147 ```bash
148 $ slidev export --dark
149 ```
150
151 ### Timeouts
152
153 For big presentations, you might want to increase the Playwright timeout with `--timeout`:
154
155 ```bash
156 $ slidev export --timeout 60000
157 ```
158
159 ### Wait
160
161 Some parts of your slides may require a longer time to render. You can use the `--wait` option to have an extra delay before exporting:
162
163 ```bash
164 $ slidev export --wait 10000
165 ```
166
167 There is also a `--wait-until` option to wait for a state before exporting each slide. If you keep encountering timeout issues, you can try setting this option:
168
169 ```bash
170 $ slidev export --wait-until none
171 ```
172
173 Possible values:
174
175 - `'networkidle'` - (_default_) consider operation to be finished when there are no network connections for at least `500` ms. This is the safest, but may cause timeouts.
176 - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
177 - `'load'` - consider operation to be finished when the `load` event is fired.
178 - `'none'` - do not wait for any event.
179
180 ::: warning
181 When specifying values other than `'networkidle'`, please make sure the printed slides are complete and correct. If some contents are missing, you may need to use the `--wait` option.
182 :::
183
184 ### Executable Path
185
186 Chromium may miss some features like codecs that are required to decode some videos. You can set the browser executable path for Playwright to your Chrome or Edge using `--executable-path`:
187
188 ```bash
189 $ slidev export --executable-path [path_to_chromium]
190 ```
191
192 ### PDF Outline
193
194 > Available since v0.36.10
195
196 You can generate the PDF outline by passing the `--with-toc` option:
197
198 ```bash
199 $ slidev export --with-toc
200 ```
201
202 ### Omit Background
203
204 When exporting to PNGs, you can remove the default browser background by passing `--omit-background`:
205
206 ```bash
207 $ slidev export --omit-background
208 ```
209
210 The default browser background is the white background visible on all browser windows and is different than other backgrounds applied throughout the application using CSS styling. [See Playwright docs](https://playwright.dev/docs/api/class-page#page-screenshot-option-omit-background). You will then need to apply additional CSS styling to the application to reveal the transparency.
211
212 Here is a basic example that covers all backgrounds in the application:
213
214 ```css
215 * {
216 background: transparent !important;
217 }
218 ```
219
220 ## Troubleshooting
221
222 ### Missing Content or Animation not Finished
223
224 If you find that some content is missing or the animations are not finished in the exported PDF, you can try adding a wait time before exporting each slide:
225
226 ```bash
227 $ slidev export --wait 1000
228 ```
229
230 ### Broken Emojis
231
232 If the PDF or PNG are missing Emojis, you are likely missing required fonts (such as. e.g. [Google's _Noto Emoji_](https://fonts.google.com/noto/specimen/Noto+Emoji)) in your environment.
233
234 This can affect e.g. CI/CD-like in-container sort of Linux environments. It can be fixed e.g. like this:
235
236 ```bash
237 $ curl -L --output NotoColorEmoji.ttf https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf
238 $ sudo mv NotoColorEmoji.ttf /usr/local/share/fonts/
239 $ fc-cache -fv
240 ```
241
242 ### Wrong Context in Global Layers
243
244 See the tip in https://sli.dev/features/global-layers.
245
245 lines MARKDOWN