Last active
March 29, 2024 11:24
-
-
Save rms1000watt/177970ce9fb0970e765700f12695231d to your computer and use it in GitHub Desktop.
Python script to add JS to pdf so the pdf will print immediately when opened
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IE users need: https://get.adobe.com/reader/ | |
from PyPDF2 import PdfFileWriter, PdfFileReader | |
output = PdfFileWriter() | |
ipdf = PdfFileReader(open('old.pdf', 'rb')) | |
for i in xrange(ipdf.getNumPages()): | |
page = ipdf.getPage(i) | |
output.addPage(page) | |
with open('new.pdf', 'wb') as f: | |
output.addJS("this.print({bUI:true,bSilent:false,bShrinkToFit:true});") | |
output.write(f) |
Hi @RaymonDev,
This not working for Chrome, the PDF is opened without any action
what is the expected output for this.
I honestly have no idea. I just translated the code to 3.x, working on it though!!
Ok, Did you try it in Chrome ?
Yes, still not working
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version for python 3.x