File tree 3 files changed +23
-7
lines changed
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ You can contribute to `pypdf on GitHub <https://github.com/py-pdf/pypdf>`_.
32
32
user/encryption-decryption
33
33
user/merging-pdfs
34
34
user/cropping-and-transforming
35
- user/add-watermark
36
35
user/reading-pdf-annotations
37
36
user/adding-pdf-annotations
37
+ user/add-watermark
38
+ user/add-javascript
38
39
user/viewer-preferences
39
40
user/forms
40
41
user/streaming-data
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -24,12 +24,6 @@ page3.mediabox.upper_right = (
24
24
)
25
25
writer.add_page(page3)
26
26
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
-
33
27
# Write to pypdf-output.pdf.
34
28
with open (" pypdf-output.pdf" , " wb" ) as fp:
35
29
writer.write(fp)
You can’t perform that action at this time.
0 commit comments