Hot questions for Using PDFBox in java 8

Question:

I'm trying to overlay a PDF on-top of all pages in a PDF, at the top left hand side of each page. The PDFs that will be of different sizes. The PDF overlay is a constant size, which is smaller than all the pages of the PDF.

I can only seem to get PDFBox to put the overlay in the middle of the PDFs.

I would prefer not to convert the PDF overlay to a bitmap (PDImageXObject) and insert it onto the pages. Here is some rough code which I'm playing about with:-

public static void main(String[] args) throws Exception {
    String overlayPath = "C:\\OverlayPdf.pdf";
    String overlayOnMePath = "C:\\ToBeOverlayedOn.pdf";       
    PDDocument overlayOnMe = PDDocument.load(new File(overlayOnMePath)); //Document to write to.
    overlayPath = overlayPath + "Anno.pdf";

    HashMap<Integer, String> overlayGuide = new HashMap<>();
    for (int i = 0; i < overlayOnMe.getNumberOfPages(); i++) {
        overlayGuide.put(i + 1, overlayPath);
    }
    Overlay overlay = new Overlay();
    overlay.setInputPDF(overlayOnMe);
    overlay.setOverlayPosition(Overlay.Position.FOREGROUND);
    overlay.overlay(overlayGuide);

    overlayOnMe.save(new File(overlayOnMePath + "_OVERLAYED.pdf"));
    overlay.close();
}

My gut feeling is its an affine transformation but I couldn't get that working either.


Answer:

I have created a new issue and it allows to pass a transform, this will be in version 2.0.10 or higher. This will be done in calculateAffineTransform by extending the overlay class. To put the stamp on the top left, the new method would look like this:

protected AffineTransform calculateAffineTransform(PDPage page, PDRectangle overlayMediaBox)
{
    AffineTransform at = new AffineTransform();
    PDRectangle pageMediaBox = page.getMediaBox();
    at.translate(0, pageMediaBox.getHeight() - overlayMediaBox.getHeight());
    return at;
}

To use this before the release of 2.0.10, build the 2.0 branch yourself or get a snapshot here: https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.10-SNAPSHOT/ The change is in any build from 21.3.2018 or later.

Question:


Answer:

Stewardship

Be aware that Oracle stopped providing free-of-cost security updates to Java 8. See Oracle Java SE Support Roadmap.

Red Hat (IBM) has taken stewardship of the OpenJDK 8 & OpenJDK 11 LTS releases.

Oracle branded

Oracle JDK 8 Update 221 is available here. Be sure to read the terms of the license, and be aware of their intention towards further updates.

OpenJDK

The open-source distributions based on OpenJDK are available from various vendors.

The first that comes to mind is AdoptOpenJDK.net, providing Java 8 with Update 222 currently.

Amazon provides OpenJDK 8 Update 222 in their Corretto offering. Especially suitable if you deploy to AWS.

Zulu by Azul Systems also provides OpenJDK 8 Update 222, certified as Java. They offer optional support plans as well.

See the nifty diagram I made for sourcing Java 11. Some of those same vendors also provide Java 8, with and without paid support.