Home > Mobile >  Use PDF as Background for another PDF PYTHON
Use PDF as Background for another PDF PYTHON

Time:09-30

I have two pdfs " file.pdf ; BACKGROUND.pdf ". i wanna use BACKGROUND.pdf as background for file.pdf with python.

i don't know where to start i'm a python developper beginner

CodePudding user response:

Maybe you could convert your first PDF to an image using this : https://www.geeksforgeeks.org/convert-pdf-to-image-using-python/

# import module
from pdf2image import convert_from_path
 
 
# Store Pdf with convert_from_path function
images = convert_from_path('example.pdf')
 
for i in range(len(images)):
   
      # Save pages as images in the pdf
    images[i].save('page'  str(i)  '.jpg', 'JPEG')

Then use the image as background for the second file.

Or use another util : How to programmatically add a background to a pdf?

CodePudding user response:

qpdf --underlay "background.pdf" -- file.pdf output.pdf

Should work for most cases.

Python users can use https://github.com/pikepdf/pikepdf a wrapper around qpdf
documentation at https://pikepdf.readthedocs.io/en/latest/
especially for this case Overlays, underlays, watermarks, n-up

  • Related