Importing Pages

Use the ImportedPage class to import a page from an existing document as a template and add page elements to it. The dimensions of the imported page are preserved. The following code imports a page and add page elements to the page.

Document document = new Document();
ImportedPage page = new ImportedPage( pdfFilePath, 1 );
page.Elements.Add( new Label( "Label Text", 100, 100, 100, 12 ) );
page.Elements.Add( new Label( "Label Text2", 100, 120, 100, 12 ) );
document.Pages.Add( page );
document.Draw(pdfFilePath);        
Dim MyDocument As Document = New Document()
Dim MyPage As ImportedPage = New ImportedPage( pdfFilePath, 1 )
MyPage.Elements.Add( New Label( "Label Text", 100, 100, 100, 12 ) )
MyPage.Elements.Add( New Label( "Label Text2", 100, 120, 100, 12 ) )
MyDocument.Pages.Add( MyPage )
MyDocument.Draw(pdfFilePath)   

Importing a Page From a Stream

The following code shows how to import a page from a stream object.

Document document = new Document();
PdfDocument pdfDocument = new PdfDocument( stream );
ImportedPage page = new ImportedPage( pdfDocument.GetPage( 1 ) );
page.Elements.Add( new Label( "Label Text", 100, 100, 100, 12 ) );
page.Elements.Add( new Label( "Label Text2", 100, 120, 100, 12 ) );
document.Pages.Add( page );
document.Draw(pdfFilePath);        
Dim MyDocument As Document = New Document()
Dim MyPdfDocument As PdfDocument = New PdfDocument( MyStream )
Dim MyPage As ImportedPage = New ImportedPage( MyPdfDocument.GetPage(1) )
MyPage.Elements.Add( New Label( "Label Text", 100, 100, 100, 12 ) )
MyPage.Elements.Add( New Label( "Label Text2", 100, 120, 100, 12 ) )
MyDocument.Pages.Add( MyPage )
MyDocument.Draw(pdfFilePath)   

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

In this topic