Skip to content

PDF A Standards Compliance

danfickle edited this page Mar 10, 2019 · 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/A1b
  • PDF/A1a
  • PDF/A2b
  • PDF/A2a
  • PDF/A2u

Example

            PdfAConformance conform = PdfAConformance.PDFA_1_A;
            PdfRendererBuilder builder = new PdfRendererBuilder();
            builder.useFastMode();
            builder.usePdfVersion(conform.getPart() == 1 ? 1.4f : 1.5f);
            builder.usePdfAConformance(conform);
            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();

Guidelines

  • 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/A1a, PDF/A2a) are meant to be accessible and are tagged. Therefore, all the guidelines from the PDF/UA wiki page apply.
  • In all cases, the built-in fonts are not available and you must supply your own.

Testing

  • 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.

Transparent Image Pre-processing Example

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"));