Skip to content

Commit f6cdd7c

Browse files
authored
DOC: Move JavaScript example (#2746)
1 parent 8e02580 commit f6cdd7c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

docs/index.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ You can contribute to `pypdf on GitHub <https://github.com/py-pdf/pypdf>`_.
3232
user/encryption-decryption
3333
user/merging-pdfs
3434
user/cropping-and-transforming
35-
user/add-watermark
3635
user/reading-pdf-annotations
3736
user/adding-pdf-annotations
37+
user/add-watermark
38+
user/add-javascript
3839
user/viewer-preferences
3940
user/forms
4041
user/streaming-data

docs/user/add-javascript.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Adding JavaScript to a PDF
2+
3+
PDF readers vary in the extent they support JavaScript, with some not supporting it at all.
4+
5+
Adobe has documentation on its support here:
6+
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html
7+
8+
## Launch print window on opening
9+
10+
```python
11+
from pypdf import PdfWriter
12+
13+
writer = PdfWriter(clone_from="example.pdf")
14+
15+
# Add JavaScript to launch the print window on opening this PDF.
16+
writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
17+
18+
# Write to pypdf-output.pdf.
19+
with open("pypdf-output.pdf", "wb") as fp:
20+
writer.write(fp)
21+
```

docs/user/cropping-and-transforming.md

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ page3.mediabox.upper_right = (
2424
)
2525
writer.add_page(page3)
2626

27-
# Add some JavaScript to launch the print window on opening this PDF.
28-
# The password dialog may prevent the print dialog from being shown,
29-
# comment the encryption lines, if that's the case, to try this out.
30-
# https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html
31-
writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
32-
3327
# Write to pypdf-output.pdf.
3428
with open("pypdf-output.pdf", "wb") as fp:
3529
writer.write(fp)

0 commit comments

Comments
 (0)