Search in sources :

Example 1 with Matrix

use of org.apache.pdfbox.util.Matrix in project PdfLayoutManager by GlenKPeterson.

the class PdfLayoutMgr method logicalPageEnd.

//    void addLogicalPage(PageBuffer pb) {
//        pages.add(pb);
//    }
/**
     Call this when you are through with your current set of pages to commit all pending text and
     drawing operations.  This is the only method that throws an IOException because the purpose of
     PdfLayoutMgr is to buffer all operations until a page is complete so that it can safely be
     written to the underlying stream.  This method turns the potential pages into real output.
     Call when you need a page break, or your document is done and you need to write it out.

     @throws IOException - if there is a failure writing to the underlying stream.
     */
// Part of end-user public interface
@SuppressWarnings("UnusedDeclaration")
void logicalPageEnd(LogicalPage lp) throws IOException {
    // Write out all uncommitted pages.
    while (unCommittedPageIdx < pages.size()) {
        PDPage pdPage = new PDPage(pageSize);
        if (lp.orientation() == LogicalPage.Orientation.LANDSCAPE) {
            pdPage.setRotation(90);
        }
        PDPageContentStream stream = null;
        try {
            stream = new PDPageContentStream(doc, pdPage);
            doc.addPage(pdPage);
            if (lp.orientation() == LogicalPage.Orientation.LANDSCAPE) {
                stream.transform(new Matrix(0, 1, -1, 0, lp.pageWidth(), 0));
            }
            stream.setStrokingColor(colorSpace.getInitialColor());
            stream.setNonStrokingColor(colorSpace.getInitialColor());
            PageBuffer pb = pages.get(unCommittedPageIdx);
            pb.commit(stream);
            lp.commitBorderItems(stream);
            stream.close();
            // Set to null to show that no exception was thrown and no need to close again.
            stream = null;
        } finally {
            // Let it throw an exception if the closing doesn't work.
            if (stream != null) {
                stream.close();
            }
        }
        unCommittedPageIdx++;
    }
}
Also used : Matrix(org.apache.pdfbox.util.Matrix) PDPage(org.apache.pdfbox.pdmodel.PDPage) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream)

Aggregations

PDPage (org.apache.pdfbox.pdmodel.PDPage)1 PDPageContentStream (org.apache.pdfbox.pdmodel.PDPageContentStream)1 Matrix (org.apache.pdfbox.util.Matrix)1