1
votes

Currently I am trying to create a PDF file with the conformance level A-1a with iText for C#. This is what I have so far:

var exportFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var exportFile = System.IO.Path.Combine(exportFolder, "Test.pdf");

var writer = new PdfWriter(exportFile);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
document.Add(new Paragraph("Hello World! Tom"));
document.Close();

How am I able to set the conformance level for this?

EDIT

I found this in their documentation: https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/chapter-7-creating-pdfua-and-pdfa-documents

But I don't get what I have to replace INTENT with in the third line of code. Is someone able to give me a full example with only a single line of Hello World. It doesn't necessarily has to be iText. I am open for other tools.

2
Please note that the documentation links to the full code sample here: developers.itextpdf.com/content/itext-7-jump-start-tutorial/…. INTENT links to a color profile required for PDF/A documents. You can find it here: git.itextsupport.com/projects/I5JS/repos/sandbox/browse/… - Jon Reilly
Thanks for your help. Does that mean I have to create a resources folder inside my project and a color folder and put the downloaded profile inside there? @JonReilly - Tom el Safadi
PdfOutputIntent's 5th argument accepts an InputStream object that holds the .icm file. Whether that is from disk, memory, or externally loaded is up to you. - Jon Reilly
@Anokrize everything you asked for is listed in the links provided by Jon. The second link even provides a .icm file for you to download and use with the code example in the first link. INTENT holds the path to the .icm file for the stream. You could just as easily loaded it up into a memory stream rather than from disk. - Nkosi
Indeed: all the examples can be found online. Adding the color profile is mandatory in PDF/A. The file shared by Jon is an example of such a file that people like you can use. Please don't abuse Stack Overflow to avoid having to study the bare minimum of technical knowledge you should have to do a good job. If you don't know ISO 19005, you shouldn't accept a job that requires compliance with ISO 19005. If you do, you should study the spec, and not expect other people to do that for you. It's quite frustrating to see that all the information was handed to you, but that you don't "accept" it. - Bruno Lowagie

2 Answers

4
votes

Step 1 :

Download a color profile.
You can use the one provided in the iText example. http://gitlab.itextsupport.com/itext7/samples/blob/develop/publications/jumpstart/src/main/resources/color/sRGB_CS_profile.icm

Step 2:

//Initialize PDFA document with output intent
PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
            ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream("sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read
            )));

Document document = new Document(pdf);

//Fonts need to be embedded
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("The quick brown "));

iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX));    
p.Add(foxImage);

p.Add(" jumps over the lazy ");

iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
p.Add(dogImage);

document.Add(p);
document.Close();
1
votes

Try to substitute this line

var pdf = new PdfDocument(writer);

with this

PdfADocument pdf = new PdfADocument(new PdfWriter(exportFile), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read
)));
Document document = new Document(pdf);
// Etc...

Apart from this, my advice is always to declare the class of the instantiation and not leave generic (with var) as you can see from my sample code.

Hope this will work! Cheers