diff --git a/docs/index.rst b/docs/index.rst index ff1470f16..12ddfb265 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,9 +32,10 @@ You can contribute to `pypdf on GitHub `_. user/encryption-decryption user/merging-pdfs user/cropping-and-transforming - user/add-watermark user/reading-pdf-annotations user/adding-pdf-annotations + user/add-watermark + user/add-javascript user/viewer-preferences user/forms user/streaming-data diff --git a/docs/user/add-javascript.md b/docs/user/add-javascript.md new file mode 100644 index 000000000..02951fb19 --- /dev/null +++ b/docs/user/add-javascript.md @@ -0,0 +1,21 @@ +# Adding JavaScript to a PDF + +PDF readers vary in the extent they support JavaScript, with some not supporting it at all. + +Adobe has documentation on its support here: +https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html + +## Launch print window on opening + +```python +from pypdf import PdfWriter + +writer = PdfWriter(clone_from="example.pdf") + +# Add JavaScript to launch the print window on opening this PDF. +writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});") + +# Write to pypdf-output.pdf. +with open("pypdf-output.pdf", "wb") as fp: + writer.write(fp) +``` diff --git a/docs/user/cropping-and-transforming.md b/docs/user/cropping-and-transforming.md index fb4d0d9e6..d3c23333e 100644 --- a/docs/user/cropping-and-transforming.md +++ b/docs/user/cropping-and-transforming.md @@ -24,12 +24,6 @@ page3.mediabox.upper_right = ( ) writer.add_page(page3) -# Add some JavaScript to launch the print window on opening this PDF. -# The password dialog may prevent the print dialog from being shown, -# comment the encryption lines, if that's the case, to try this out. -# https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html -writer.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});") - # Write to pypdf-output.pdf. with open("pypdf-output.pdf", "wb") as fp: writer.write(fp)