-
-
Save yk2kus/b56823ad8a39ee7492023f428b589ba8 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment