ceTe Software Help Library for Java August - 2020
DynamicPDF Generator for Java / Programming with Generator for Java / Document Output
In This Topic
    Document Output
    In This Topic

    DynamicPDF Generator for Java can output PDF documents to a file or any java.io.OutputStream object that supports writing. The draw and drawToWeb methods of the Document class handle all document output. These methods are overloaded and give many options for the output of the PDF document.

    Output to a Servlets/JSP page

    From the Servlets/JSP page call the Document's drawToWeb method and pass in the current page object along with a download file name.

    [Java]
        // Outputs the PDF document to the page object.
        document.drawToWeb(request, response, outputStream, downloadAsFileName");
    

    You can choose to have the document downloaded instead of being viewed in the browser.

    [Java]
        // Outputs the PDF document to the page object.
        document.drawToWeb(request, response, outputStream, true);
    

    Output to a file

    Specify the file path and name for the file in the Document's draw method.

    [Java]
        // Outputs the PDF document to a file.
        document.draw("[PhysicalPath]/MyDocument.pdf");
    

    Output to a java.io.OutputStream object

    Specify the Stream object to receive the output in the Document's draw method.

    [Java]
        // Outputs the PDF document to a stream.
        document.draw(stream);
    

    Output to a byte array

    When calling the draw method with no parameters, it will return the PDF data as a byte array. This is useful when storing the PDF in a database or returning it from a Web Service.

    [Java]
        // Outputs the PDF document to a byte array.
        byte[] data;
        data = document.draw();
    
    See Also