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

    DynamicPDF Merger for Java is designed to allow highly efficient reuse of imported PDF document data. The PdfDocument class is included for this purpose. This class holds the pages and resources of a PDF document and can be used in the constructors of MergeDocument, ImportedPage and ImportedPageData as well as the append method of MergeDocument. Using a PdfDocument object optimizes performance by minimizing the number of times that PDF data needs to be parsed and allowing for the efficient reuse of shared PDF resources.

    PdfDocument objects are thread safe and can be added set to a static member variable of your class. This static member variable can then be used wherever the document or pages from the document are needed. This is highly recommended for documents, or pages from documents, such as templates or cover pages, which will be reused many times in your application.

    IMPORTANT: A PdfDocument class can be used anywhere a file path to an existing PDF document can be specified such as the constructors of MergeDocument, ImportedPage and ImportedPageData as well as the append method of MergeDocument. The overloads of those constructors and methods allow PDFs to be specified by file path for convenience. PDFs should only be specified by file path there if they are not going to be reused.

    The following example shows how to most efficiently reuse a template page and PDF document in your class.

    [Java]
        import com.cete.dynamicpdf.*;
        import com.cete.dynamicpdf.merger.*;
    
        class MyClass {
            private static PdfDocument template = new PdfDocument("[PhysicalPath]/MyTemplate.pdf");
            private static PdfDocument legalPages = new PdfDocument("[PhysicalPath]/MyLegalPages.pdf");
    
            public static createPdf(String fullName) {
                // Create a MergeDocument object
                MergeDocument document = new MergeDocument();
                // Create a page out of the first page in the template PDF
                ImportedPage page = new ImportedPage(template.getPage( 1 ));
                // Add the full name to the template
                page.getElements().add(new Label(fullName, 0, 0, 200, 12));
                // Add the page to the document
                document.getPages().add(page);
                // Append all the legal pages to the end of the document
                document.append(legalPages);
                // Save the PDF
                document.draw("[PhysicalPath]/" + fullName + ".pdf");
            }
        }
    

    See Also