PDF/A-2

This is a code example of iText PDF, discover more.

31st May 2016
iText PDF

Switch code for this example

HelloPdfA2a.java
  1. /*
  2.  
  3.     This file is part of the iText (R) project.
  4.     Copyright (c) 1998-2016 iText Group NV
  5.  
  6. */
  7.  
  8. /**
  9.  * Example written by Bruno Lowagie
  10.  */
  11. package com.itextpdf.samples.sandbox.pdfa;
  12.  
  13. import com.itextpdf.io.font.PdfEncodings;
  14. import com.itextpdf.kernel.font.PdfFont;
  15. import com.itextpdf.kernel.font.PdfFontFactory;
  16. import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
  17. import com.itextpdf.kernel.pdf.PdfOutputIntent;
  18. import com.itextpdf.kernel.pdf.PdfString;
  19. import com.itextpdf.kernel.pdf.PdfWriter;
  20. import com.itextpdf.kernel.xmp.XMPException;
  21. import com.itextpdf.layout.Document;
  22. import com.itextpdf.layout.element.Paragraph;
  23. import com.itextpdf.pdfa.PdfADocument;
  24. import com.itextpdf.samples.GenericTest;
  25. import com.itextpdf.test.annotations.type.SampleTest;
  26.  
  27. import org.junit.experimental.categories.Category;
  28.  
  29. import java.io.File;
  30. import java.io.FileInputStream;
  31. import java.io.IOException;
  32.  
  33. @Category(SampleTest.class)
  34. public class HelloPdfA2a extends GenericTest {
  35.     public static final String DEST = "./target/test/resources/sandbox/pdfa/hello_pdf_a_2a.pdf";
  36.     public static final String FONT = "./src/test/resources/font/OpenSans-Regular.ttf";
  37.  
  38.     public static void main(String[] args) throws Exception {
  39.         File file = new File(DEST);
  40.         file.getParentFile().mkdirs();
  41.         new HelloPdfA2a().manipulatePdf(DEST);
  42.     }
  43.  
  44.     public void manipulatePdf(String dest) throws IOException, XMPException {
  45.         PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H);
  46.         FileInputStream is = new FileInputStream("./src/test/resources/data/sRGB_CS_profile.icm");
  47.         PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_2A,
  48.                 new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", is));
  49.         Document document = new Document(pdfDoc);
  50.         pdfDoc.setTagged();
  51.         pdfDoc.getCatalog().setLang(new PdfString("en-us"));
  52.         Paragraph p = new Paragraph("Hello World!").setFont(font).setFontSize(10);
  53.         document.add(p);
  54.         document.close();
  55.     }
  56. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now