Hi all,
Does anybody know how to merge two PDFs using Python while maintaning layers as shown on the attached picture?
I am using arcpy for ArcGIS Pro to export an 'Overview' PDF and a 'Detailed Location' PDF.
Both PDFs contain the layers once they're opened on PDF viewer. However, when I merge both PDF 'lots' within a single 'Map Book' PDF using 'arcpy.PDFDocumentCreate' and '<pdfDoc>.appendPages', those layers are lost.
I have also tried PdfFileMerger within PyPDF2 Library without success,
Any thoughts?
Thanks, Ana
Hi! In case anyone else needs it... Use the PDF merger from the Arcmap arcpy. The drawback is that for each PDF you have a list of layers, separately. I don't really like that.
def merge_all(dict_paths, out_dir):
for empl, pdfs in dict_paths.items():
out_pdf = os.path.join(out_dir,"{0}.pdf".format(empl))
# pdfDoc = arcpy.mp.PDFDocumentCreate(out_pdf) #this is for Pro
pdfDoc = arcpy.mapping.PDFDocumentCreate(out_pdf)
for pdf in pdfs:
pdfDoc.appendPages(pdf)
pdfDoc.updateDocProperties(pdf_open_view= "LAYERS")
pdfDoc.saveAndClose()