ceTe Software Help Library for Java August - 2020
DynamicPDF Merger for Java / Programming with Merger for Java / Placing Imported Pages
In This Topic
    Placing Imported Pages
    In This Topic

    The ImportedPageArea and ImportedPageData classes can be used to create a page element out of the data from a page in an existing PDF document. This can then be rotated, scaled, or clipped and placed on a Page or ImportedPage.

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

    [Java]
        Document document = new Document();
        Page page = new Page(PageSize.TABLOID, PageOrientation.LANDSCAPE);
        page.getElements().add(new ImportedPageData("[PhysicalPath]/DocumentA.pdf", 1, -306, 0));
        page.getElements().add(new ImportedPageData("[PhysicalPath]/DocumentA.pdf", 2, 306, 0));
        document.getPages().add(page);
        document.draw("[PhysicalPath]/MyDocument.pdf");
    

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

    [Java]
        Document document = new Document();
        Page page = new Page(PageSize.TABLOID, PageOrientation.LANDSCAPE);
        ImportedPageArea importedPageArea = new ImportedPageArea("[PhysicalPath]/DocumentA.pdf", 1, 0, 0);
        importedPageArea.getContents().setClipLeft(100);
        importedPageArea.getContents().setClipTop(100);
        importedPageArea.getContents().setClipRight(100);
        importedPageArea.getContents().setClipBottom(100);
        page.getElements().add(importedPageArea);
        document.getPages().add(page);
        document.draw("[PhysicalPath]/MyDocument.pdf");
    

    Page Content Reuse

    When using the same page contents many times within the same document, it is important to create an ImportedPageContents object once, and use it in the ImportedPageArea and ImportedPageData class constructors. Doing so will prevent the page contents from being embedded in the document multiple times and the data will be shared, reducing the overall size of your document.

    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.

     

    See Also