PDF/A-2
hellopdfa2a
JAVA
JAVA
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
package com.itextpdf.samples.sandbox.pdfa;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
import com.itextpdf.kernel.pdf.PdfOutputIntent;
import com.itextpdf.kernel.pdf.PdfString;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.xmp.XMPException;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.pdfa.PdfADocument;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class HelloPdfA2a {
public static final String DEST = "./target/sandbox/pdfa/hello_pdf_a_2a.pdf";
public static final String FONT = "./src/main/resources/font/OpenSans-Regular.ttf";
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new HelloPdfA2a().manipulatePdf(DEST);
}
public void manipulatePdf(String dest) throws IOException {
PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H);
FileInputStream fileStream = new FileInputStream("./src/main/resources/data/sRGB_CS_profile.icm");
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_2A,
new PdfOutputIntent("Custom", "",
null, "sRGB IEC61966-2.1", fileStream));
Document document = new Document(pdfDoc);
// Specifies that document should contain tag structure
pdfDoc.setTagged();
pdfDoc.getCatalog().setLang(new PdfString("en-us"));
Paragraph p = new Paragraph("Hello World!").setFont(font).setFontSize(10);
document.add(p);
document.close();
}
}
C#
C#
using System;
using System.IO;
using iText.IO.Font;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Pdfa;
namespace iText.Samples.Sandbox.Pdfa
{
public class HelloPdfA2a
{
public static readonly string DEST = "results/sandbox/pdfa/hello_pdf_a_2a.pdf";
public static readonly String FONT = "../../../resources/font/OpenSans-Regular.ttf";
public static void Main(String[] args)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new HelloPdfA2a().ManipulatePdf(DEST);
}
private void ManipulatePdf(String dest)
{
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
FileStream fileStream = new FileStream("../../../resources/data/sRGB_CS_profile.icm",
FileMode.Open, FileAccess.Read);
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_2A,
new PdfOutputIntent("Custom", "",
null, "sRGB IEC61966-2.1", fileStream));
Document document = new Document(pdfDoc);
// Specifies that document should contain tag structure
pdfDoc.SetTagged();
pdfDoc.GetCatalog().SetLang(new PdfString("en-us"));
Paragraph p = new Paragraph("Hello World!").SetFont(font).SetFontSize(10);
document.Add(p);
document.Close();
}
}
}