Home > Mobile >  PDF - Fitz makes the merged page as flipped
PDF - Fitz makes the merged page as flipped

Time:12-15

Below is the code I use to add a watermark onto pdf pages. On some pages the watermark looks like flipped upside down (rotated 180 degrees and looks like in the mirror).

doc_report = fitz.open(report_pdf_path)
doc_watermark = fitz.open(watermark_pdf_path)

for i in xrange(doc_report.pageCount):
    page = doc_report.loadPage(i)
    page_front = fitz.open()
    page_front.insertPDF(doc_watermark, from_page=i, to_page=i)
    page.showPDFpage(page.rect, page_front, pno=0, keep_proportion=True, overlay=True, rotate=0, clip=None)

doc_report.save(save_path, encryption=fitz.PDF_ENCRYPT_KEEP)
doc_report.close()
doc_watermark.close()

While debugging I compared the rotation, transformation properties of the target and watermark page, they look identical. Could you please advise how can I resolve this?

CodePudding user response:

Thanks to K J, here is the updated code resolving the issue.

doc_report = fitz.open(report_pdf_path)
doc_watermark = fitz.open(watermark_pdf_path)

for i in xrange(doc_report.pageCount):
    page = doc_report.loadPage(i)
    page_front = fitz.open()
    
    # added this
    if not page._isWrapped:
        page._wrapContents()

    page_front.insertPDF(doc_watermark, from_page=i, to_page=i)
    page.showPDFpage(page.rect, page_front, pno=0, keep_proportion=True, overlay=True, rotate=0, clip=None)

doc_report.save(save_path, encryption=fitz.PDF_ENCRYPT_KEEP)
doc_report.close()
doc_watermark.close()
  • Related