Some test text!

Copy/Merge PDF pages

Contents

About page copying/merging

To copy/merge several PDF documents into one.

PDFDoc new_doc = new PDFDoc();
int page_num = 15;
for (int i = 1; i <= page_num; ++i)
{
    PDFDoc in_doc = new PDFDoc(output_path + "newsletter_split_page_" + i + ".pdf");
    new_doc.InsertPages(i, in_doc, 1, in_doc.GetPageCount(), PDFDoc.InsertFlag.e_none);
}
new_doc.Save(output_path + "newsletter_merge_pages.pdf", SDFDoc.SaveOptions.e_remove_unused);

Merge, copy, delete, and rearrange PDF pages
Full code sample which illustrates how to copy pages from one document to another, how to delete, and rearrange pages and how to use ImportPages().

linkAbout page copying/merging

The recommended way to copy pages from one document to another is with PDFDoc.InsertPages(). Its arguments are:

  • insertBeforeThisPage: An integer specifying where the pages should be inserted
  • sourceDoc: A PDFDoc from which the pages should be read
  • startPage: An integer specifying the first page number to insert
  • endPage: An integer specifying the last page number to insert
  • flag: A PDFDoc.InsertFlag value (either e\insert_bookmark, meaning bookmarks should be inserted, or _enone_)

For example, suppose we want to insert the third page of one document after the first page of a second document. The following code snippet performs this with an insertBeforeThisPage value of 2 and startPage and endPage values of 3.

Console.WriteLine(
    "dest_doc has {0} pages prior to calling InsertPages. ",
    dest_doc.GetPageCount());

dest_doc.InsertPages(2, source_doc, 3, 3, PDFDoc.InsertFlag.e_none);

Console.WriteLine(
    "dest_doc has {0} pages following its call to InsertPages. ",
    dest_doc.GetPageCount());

We can also insert a range of pages. For example, the following code will insert the second, third, and fourth pages of one document into the end of the second document. We specify that we're inserting into the end of the document by using an insertBeforeThisPage value higher than the number of pages in the document:

Console.WriteLine(
    "dest_doc has {0} pages prior to calling InsertPages. ",
    dest_doc.GetPageCount());

dest_doc.InsertPages(dest_doc.GetPageCount() + 1,
    source_doc, 2, 4, PDFDoc.InsertFlag.e_none);

Console.WriteLine(
    "dest_doc has {0} pages following its call to InsertPages. ",
    dest_doc.GetPageCount());

Get the answers you need: Support

Contents

About page copying/merging