-
Notifications
You must be signed in to change notification settings - Fork 360
PDF A Standards Compliance
Quentin Ligier edited this page Mar 8, 2021
·
3 revisions
NOTE: Proper PDF/A support was released with RC-18.
An overview of PDF/A at Wikipedia.
This project is capable of generating PDFs compliant with the following standards:
- PDF/A-1b & PDF/A-1a
- PDF/A-2b, PDF/A-2a & PDF/A-2u
- PDF/A-3b, PDF/A-3a & PDF/A-3u
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useFastMode();
builder.usePdfAConformance(PdfAConformance.PDFA_1_A);
builder.useFont(new File("target/test/artefacts/Karla-Bold.ttf"), "TestFont");
builder.withHtmlContent(html, PdfATester.class.getResource("/html/").toString());
try (InputStream colorProfile = PdfATester.class.getResourceAsStream("/colorspaces/sRGB.icc")) {
byte[] colorProfileBytes = IOUtils.toByteArray(colorProfile);
builder.useColorProfile(colorProfileBytes);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
builder.toStream(baos);
builder.run();
- The required color profile is not distributed with this project, but can be downloaded from PDFBOX source tree.
- PDF/A 1 (PDF/A1a, PDF/A1b) standards specified a PDF standard version of 1.4. This version does not support transparency in images, so you must not include transparent images. See code example below showing how to pre-process an image to remove alpha channel.
- The versions ending in a (PDF/A-1a, PDF/A-2a, PDF/A-3a) are meant to be accessible and are tagged. Therefore, you should follow the guidelines from the PDF/UA wiki page whether you set the UA accessiblity flag (
builder.usePdfUaAccessbility(true)
) or not. - In all cases, the built-in fonts are not available and you must supply your own.
- You can find our PDF/A testing code in the pdfa-testing module. It should be noted that because the VeraPDF testing library is not licensed under a LGPL compatible license, this module is distributed under the GPL instead.
This example is based on similar code from StackOverflow.
BufferedImage img = ImageIO.read(new File("/Users/me/Documents/flyingsaucer.png"));
BufferedImage copy = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = copy.createGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, copy.getWidth(), copy.getHeight());
g2d.drawImage(img, 0, 0, null);
g2d.dispose();
ImageIO.write(copy, "png", new File("/Users/me/Documents/fyingsaucer-no-alpha.png"));