Joining Two or More PDFs
IronPDF for Python can combine multiple PDF documents into a single file using the PdfDocument.Merge method, making it straightforward to assemble multi-part documents from separate sources.
Getting Started
Create or load two or more PdfDocument objects, then pass them to PdfDocument.Merge. The method returns a new PdfDocument containing all pages from the input documents in the order they were provided.
Understanding the Code
ChromePdfRenderer: Used here to render two HTML strings into separatePdfDocumentobjects. You can also load existing PDFs withPdfDocument.FromFile.RenderHtmlAsPdf(html): Converts an HTML string into aPdfDocument. Each rendered document becomes one section of the final merged PDF.PdfDocument.Merge(pdfdoc_a, pdfdoc_b): Combines twoPdfDocumentobjects into a single document. The pages frompdfdoc_aappear first, followed by the pages frompdfdoc_b.SaveAs("Merged.pdf"): Saves the merged document to the specified file path.
Merging More Than Two Documents
To merge more than two documents at once, pass a list of PdfDocument objects to PdfDocument.Merge:
merged = PdfDocument.Merge([doc_a, doc_b, doc_c])merged = PdfDocument.Merge([doc_a, doc_b, doc_c])





