Merge Multiple PDFs with a Cover Page
IronPDF for Python provides a concise set of methods for combining, restructuring, and extracting pages from PDF documents — merging multiple files, prepending cover pages, removing pages, and copying page subsets in just a few lines of code.
Getting Started
Load existing PDFs into a typed List[PdfDocument] collection and pass it to PdfDocument.Merge to combine them. From there, use PrependPdf, RemovePage, and CopyPages to further shape the document before saving.
Understanding the Code
List[PdfDocument](): A typed .NET-style list used to collect multiplePdfDocumentobjects before merging. Call.Add()to append each document.PdfDocument.FromFile(path): Opens an existing PDF file and returns it as aPdfDocumentobject.PdfDocument.Merge(pdfs): Combines all documents in the list into a singlePdfDocument, preserving page order.SaveAs(path): Writes the current state of the document to disk.PrependPdf(pdf): Inserts anotherPdfDocumentat the very beginning of the current document — used here to add a rendered HTML cover page as the first page.RemovePage(index): Removes a single page at the specified zero-based index.pdf.PageCount - 1targets the last page.CopyPages(ToPageList([4, 6])): Extracts specific pages by their zero-based indexes and returns them as a newPdfDocument.ToPageListconverts a Python list of indexes into the required page list format.eachPdf.Dispose(): Releases the underlying resources held by each loadedPdfDocumentafter the merge is complete.
Zero-Based Page Indexing
All page operations in IronPDF use zero-based indexes. Page 5 of a document is at index 4, page 7 is at index 6, and so on.






