PDF/A-2

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

7th November 2015
admin-marketing

Switch code for this example

HelloPdfA2a.java
  1. /**
  2.  * Example written by Bruno Lowagie
  3.  */
  4. package sandbox.pdfa;
  5.  
  6. import com.itextpdf.text.Document;
  7. import com.itextpdf.text.DocumentException;
  8. import com.itextpdf.text.Font;
  9. import com.itextpdf.text.Paragraph;
  10. import com.itextpdf.text.pdf.BaseFont;
  11. import com.itextpdf.text.pdf.ICC_Profile;
  12. import com.itextpdf.text.pdf.PdfAConformanceLevel;
  13. import com.itextpdf.text.pdf.PdfAWriter;
  14.  
  15. import java.io.File;
  16. import java.io.FileInputStream;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import sandbox.WrapToTest;
  20.  
  21. @WrapToTest
  22. public class HelloPdfA2a {
  23.    
  24.     public static final String DEST = "results/pdfa/hello_pdf_a2a.pdf";
  25.     public static final String FONT = "resources/fonts/OpenSans-Regular.ttf";
  26.    
  27.     public static void main(String[] args) throws IOException, DocumentException {
  28.         File file = new File(DEST);
  29.         file.getParentFile().mkdirs();
  30.         new HelloPdfA2a().createPdf(DEST);
  31.     }
  32.    
  33.     public void createPdf(String dest) throws IOException, DocumentException {
  34.         Font font = new Font(BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 10);
  35.         Document document = new Document();
  36.         PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream(dest), PdfAConformanceLevel.PDF_A_2A);
  37.         writer.createXmpMetadata();
  38.         writer.setTagged();
  39.         document.open();
  40.         document.addLanguage("en-us");
  41.         File file = new File("resources/data/sRGB_CS_profile.icm");
  42.         ICC_Profile icc = ICC_Profile
  43.                 .getInstance(new FileInputStream(file));
  44.         writer.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
  45.         Paragraph p = new Paragraph("Hello World!", font);
  46.         document.add(p);
  47.         document.close();
  48.     }
  49. }
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