The HiQPdf software is able to merge loaded PDF documents and created PDF documents using the PdfDocumentAddDocument(PdfDocument) method.
Merge PDF Demo
In this demo you can learn how to merge multiple PDF document into a single PDF document. Initially is created an empty document which will become the final document. Then the two PDF files are loaded into two PdfDocuments objects which are added to the empty document.
Demo Source Code
C#
private void buttonMergePdf_Click(object sender, EventArgs e) { // create an empty document which will become the final document after merge PdfDocument resultDocument = new PdfDocument(); // load the first document to be merged from a file string pdfFile1 = Application.StartupPath + @"\DemoFiles\Pdf\WikiHtml.pdf"; PdfDocument document1 = PdfDocument.FromFile(pdfFile1); // load the second document to be merged from a FileStream to exemplify the PDF loading from a stream // The stream must remain open until the result document is saved. The stream is closed when the document2 // will be closed string pdfFile2 = Application.StartupPath + @"\DemoFiles\Pdf\WikiPdf.pdf"; FileStream pdfStream = new FileStream(pdfFile2, FileMode.Open, FileAccess.Read, FileShare.Read); PdfDocument document2 = PdfDocument.FromStream(pdfStream); // add the two documents to the result document resultDocument.AddDocument(document1); resultDocument.AddDocument(document2); Cursor = Cursors.WaitCursor; string pdfFile = Application.StartupPath + @"\DemoOutput\MergePdf.pdf"; try { resultDocument.WriteToFile(pdfFile); } catch (Exception ex) { MessageBox.Show(String.Format("Cannot create the PDF document. {0}", ex.Message)); return; } finally { // close the result document resultDocument.Close(); // close the merged documents // this will also close the pdfStream from which document 2 was loaded document1.Close(); document2.Close(); Cursor = Cursors.Arrow; } // open the created PDF document try { System.Diagnostics.Process.Start(pdfFile); } catch (Exception ex) { MessageBox.Show(String.Format("The PDF document was created but cannot open '{0}'. {1}", pdfFile, ex.Message)); } }
See Also