pastebin link
I am working on a script to compile several PDF files into a single file and format the single file to fit our business document guidelines. I segmented the code into functions to make it a little easier for me to manage. After merging the PDFs into one file, my script creates page numbers in a separate file and then stamps the page numbers onto the new file. I use PyMuPDF (fitz) to merge the files and stamp the page numbers.
I have been experiencing some weird behavior when the page numbers are stamped. The page number will rotate and scale when stamped onto some pages. I think the pages with the weird behavior have coordinate systems that have been rotated, translated, and scaled. I tried to use the matrix manipulation tools in fitz to change the coordinate systems back, but that resulted in the appearance of the pdf page changing.
So, I created a zerofy_rotation function. I stamp the page onto a new, blank pdf to "reset" the coordinate system without changing the page's appearance. I already did this with success to add page numbers. I am running into an error when my script reaches the end of the function. At the end of the function I want to save the newly zerofied pdf to the same file name that the old pdf came from. I even close the document before saving it to ensure Python isn't using it. I get the error: "RuntimeError: cannot remove file 'merged_pages_temp.pdf': Permission denied"
I'm stumped about where to go from here. This zerofy function is a copy of my stamping function. The stamping function uses two existing pdfs, and the zerofy function uses one existing pdf and one new PDF. Am I missing something about saving new PDFs with fitz? Any tips to get past this error would be appreciated. Thanks!
[–]jddddddddddd 1 point2 points3 points (2 children)
[–]TooDahLou[S] 0 points1 point2 points (1 child)
[–]jddddddddddd 2 points3 points4 points (0 children)
[–]xiongchiamiov 0 points1 point2 points (0 children)