Placing Imported Pages

Use the ImportedPageArea and ImportedPageData classes to create a page element using the data from a page in an existing PDF document. These classes can then be rotated, scaled, or clipped and placed on a Page or ImportedPage.

The following code imports two pages and place them side by side on a new page.

Document document = new Document();
Page page = new Page(PageSize.Tabloid, PageOrientation.Landscape);
page.Elements.Add(new ImportedPageData("doc-text.pdf", 1, -306, 0));
page.Elements.Add(new ImportedPageData("DocumentA.pdf", 2, 306, 0));
document.Pages.Add(page);
document.Draw(outputPath);      
Dim document As New Document()
Dim page As New Page(PageSize.Tabloid, PageOrientation.Landscape)
page.Elements.Add(New ImportedPageData("doc-text.pdf", 1, -306, 0))
page.Elements.Add(New ImportedPageData("DocumentA.pdf", 2, 306, 0))
document.Pages.Add(page)
document.Draw(outputPath) 

placing Figure 1. Importing pages and placing.

The following code will import and clip a page and place it on a new page.

Document document = new Document();
Page page = new Page(PageSize.Tabloid, PageOrientation.Landscape);
ImportedPageArea importedPageArea = new ImportedPageArea("DocumentC.pdf", 1, 0, 0, 0.5f);
importedPageArea.Contents.ClipLeft = 100;
importedPageArea.Contents.ClipTop = 100;
importedPageArea.Contents.ClipRight = 100;
importedPageArea.Contents.ClipBottom = 100;
page.Elements.Add(importedPageArea);
document.Pages.Add(page);
document.Draw(outputPath);     
Dim document As New Document()
Dim page As New Page(PageSize.Tabloid, PageOrientation.Landscape)
Dim importedPageArea As New ImportedPageArea("DocumentC.pdf", 1, 0, 0, 0.5F)
importedPageArea.Contents.ClipLeft = 100
importedPageArea.Contents.ClipTop = 100
importedPageArea.Contents.ClipRight = 100
importedPageArea.Contents.ClipBottom = 100
page.Elements.Add(importedPageArea)
document.Pages.Add(page)
document.Draw(outputPath)

clipping Figure 2. Importing page and clipping.

Page Content Reuse

When using the same page contents within the same document, it is important to only use an ImportedPageContents object once, and to then use it in the ImportedPageArea and ImportedPageData class constructors. Using these elements only once prevents embedding the page contents in a document multiple times and shares the data and reduces the overall size of your document.

The examples in this topic show how to import pages that are not reused multiple times. For details on how to most efficiently handle pages used multiple times, see the Performance Considerations topic.

In this topic