Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

iOS / Guides / Insert pages


PDFTron is now Apryse, learn more here.

Insert or merge PDF pages on iOS

To insert/copy/merge several PDF documents into one.

PTPDFDoc *new_doc = [[PTPDFDoc alloc] init];
int page_num = 15;
for (int i=1; i<=page_num; ++i)
    NSString *input_file = [output_filename stringByAppendingFormat: @"_split_page_%d.pdf", i]; 
    PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: input_file];
    [new_doc InsertPages: i src_doc: doc start_page: 1 end_page: [doc GetPageCount] flag: e_ptinsert_none];
[new_doc SaveToFile: [output_filename stringByAppendingString:@"_merge_pages.pdf"] flags: e_ptlinearized];

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().

About 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

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.

[dest_doc InsertPages: 2 src_doc: source_doc start_page: 3 end_page: 3 flag: e_ptinsert_none];

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:

[dest_doc InsertPages: [dest_doc GetPageCount] + 1 src_doc: source_doc start_page: 2 end_page: 4 flag: e_ptinsert_none];

Get the answers you need: Support