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

    The ImportedPage class can be used 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 will import a page and add page elements to it.

    [Java]
        Document document = new Document();
        ImportedPage page = new ImportedPage("[PhysicalPath]/DocumentA.pdf", 1);
        page.getElements().add(new Label("Label Text", 100, 100, 100, 12));
        page.getElements().add(new Label("Label Text2", 100, 120, 100, 12));
        document.getPages().add(page);
        document.draw("[PhysicalPath]/MyDocument.pdf");
    

    Importing a Page From a Stream

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

    [Java]
        Document document = new Document();
        PdfDocument pdfDocument = new PdfDocument(FileInputStream fileStream);
        ImportedPage page = new ImportedPage(pdfDocument.getPage(1));
        page.getElements().add(new Label("Label Text", 100, 100, 100, 12));
        page.getElements().add(new Label("Label Text2", 100, 120, 100, 12));
        document.getPages().add(page);
        document.draw("[PhysicalPath]/MyDocument.pdf");
    

     

    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