Since this post was published, we have released Foxit PDF SDK, the only true multi-platform SDK in the market, available for Windows, Mac, Linux, iOS, Android, UWP and Web. It features a single, consistent core API, as well as a built-in viewer and UI for faster development. Learn more.

Merging PDF files can save departments time and energy where document sourcing and manually copying data is involved. In this article, we will look at what functions are available to carry out this action and some code samples to show it in practice. There are two ways to merge PDF files with Foxit’s Quick PDF Library, merging two documents or merging a list of documents. There are many reasons why you would choose to do either one of these actions. For example:

  • You could have two people working on different parts of a project and want to pull together both of their literature into one document. For this, you can use the PDF function MergeDocument
  • You may have many chapters of a book in numerous different PDF Files, and you want to pull them together. In this instance, the function MergeFileList will produce this type of action

MergeDocument Function

To merge two PDF files, you can use the MergeDocument function. This function allows you to pull one PDF document into another one. During the merging process, form fields and annotations from both documents are preserved, but outlines (bookmarks) are not.

Sample Code

DPL.LoadFromFile("sample1.pdf", "");
PrimaryDoc = DPL.SelectedDocument(); // Load the first document

DPL.LoadFromFile(“sample2.pdf”, “”);
SecondaryDoc = DPL.SelectedDocument(); // Load the second document

DPL.SelectDocument(PrimaryDoc); // Select the first document

DPL.MergeDocument(SecondaryDoc); // Merge the second document with the first

DPL.SaveToFile(“merged_docs.pdf”); // Save the merged document

MergeFileList Function

The MergeFileList function is used to merge two or more PDF files. This function merges all the files in a range of files and saves the resulting merged document as a new file with a specified name. Annotations, Bookmarks and form fields from all documents are preserved. The ClearFileList function will erase the file list, and the MergeFileListFast function is used to merge documents fasters depending on the types of content and file sizes in question.

Sample Code

DPL.AddToFileList("FilesToMerge", "sample1.pdf");
DPL.AddToFileList("FilesToMerge", "sample2.pdf");
DPL.AddToFileList("FilesToMerge", "sample3.pdf"); // Add a range of files to a list

DPL.MergeFileList(“FilesToMerge”, “merged_file_list.pdf”); // Merge the list together in one PDF So there you are – two ways to merge PDF files in our PDF SDKs. Our Quick PDF Library is available as a free 30-day trial where you can get to know the product and start to test out your proof of concept. Test it out today!