Home > database >  How can I place a pdf asset into a empty PDF page?
How can I place a pdf asset into a empty PDF page?

Time:02-06

I have multiple PDF files with small sizes (e.g. 3cm x 2 cm) exported from Adobe Indesign. I want to compose many of these into one new PDF which has the size of a whole page. The small PDFs contain a plotter line in a special color which would get lost if I convert them into images.

How can I place these PDFs (at given positions) using python and without losing the special color.

I tried to read into pypdf, pypdf2 and reportlab but I got lost and the examples I found did not work. I do not need the full code, a hint into the right direction would be enough (even with another language if necessary).

Thanks

CodePudding user response:

Here is a sample code to do your task using PyPDF2.

from PyPDF2 import PdfFileMerger 
merger = PdfFileMerger() 
for pdf in pdf_files: 
    merger.append(pdf)   #pdf_files is a list of the pdf files (path) to be merged.
merger.write(output_pdf) #output_pdf is the path of the merged pdf file.
merger.close() 

CodePudding user response:

Try:

cpdf in.pdf -stamp-on stamp.pdf -pos-left "x y" AND -stamp-on stamp2.pdf -pos-left "x2 y2" AND ..... -o out.pdf

where in.pdf is a blank PDF of appropriate size, and x and y and x2 and y2 etc... are the coordinates required and ..... are parts of the command for the third, fourth etc. stamps.

  • Related