Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting PDF Page on Existing PDF

Tags:

python

pdf

I'm trying to insert two pdfs, the first pdf is the main pdf and the second is the one I'd like to take and append to the first pdf, under the same name. The goal is to open the pdf and append and that's it.

import fitz
doc1 = fitz.open("test1.pdf")
doc2 = fitz.open("test2.pdf")
doc1.insertPDF(doc2)
doc2.save("test2.pdf")

I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\*****\AppData\Roaming\Python\Python37\site-packages\fitz\fitz.py", line 3537, in save
    raise ValueError("save to original must be incremental")
ValueError: save to original must be incremental

If there's any other way to do this please let me know, through Python

like image 760
Anfaaa Avatar asked Nov 16 '25 19:11

Anfaaa


1 Answers

If you just need to append your modifications to the existing pdf file (incremental save) you can use saveIncr() method which internally calls the save method with the correct arguments.

saveIncr() saves the document incrementally by calling

doc.save(doc.name, incremental=True, encryption=PDF_ENCRYPT_KEEP)
like image 160
Vishal Singh Avatar answered Nov 18 '25 10:11

Vishal Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!