Open morkai opened 1 year ago
I am not completely sure why, but the following approach seems to work (id est using the clone_from
version):
from pypdf import PdfReader, PdfWriter, Transformation
writer = PdfWriter(clone_from="blank_merge.input.pdf")
for page_no, page in enumerate(writer.pages):
print(page_no + 1)
footer_pdf = PdfReader("blank_merge.footer.pdf")
footer_page = footer_pdf.pages[0]
footer_page.add_transformation(Transformation().rotate(0).translate(tx=0, ty=0))
page.merge_page(footer_page)
writer.write("blank_merge.output.pdf")
@morkai Could you test the same PDF, but using pypdf version 3.10.0 ?
I have the same problem, after version 3.10.0 there is a problem.
@bigatti Yes, it works in 3.10.0 and breaks from 3.11.0.
I'm trying to add a short text to each page of an existing document. The input document I'm using for testing has 18 pages and after running it through the specified script two pages containing only text are blank.
I've got permission to share the first three pages of the document (one of the failing pages is the page number 3).
Environment
Which environment were you using when you encountered the problem?
Code + PDF
This is a minimal, complete example that shows the issue:
In the above script we are merging the
footer_page
into theinput_page
, but if we swap the order and merge theinput_page
into thefooter_page
everything works (but is noticably slower):blank_merge.input.pdf - the input PDF - notice that the 3rd page is all text blank_merge.footer.pdf - this is created through Chrome's 'Print to PDF' feature (PDF created with the reportlab package also doesn't work) blank_merge.output.pdf - the result of merging the footer into the input - notice that the 3rd page is blank blank_merge.output_reversed.pdf - the result of merging the input into the footer - notice that the 3rd page has the original contents and the extra footer