Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Can you help me to create a pdf/A-3 with an embedded xml file with itextsharp . I am trying to create but got error "All the fonts must be embedded. This one isn't: Helvetica"
The sample code I have provided here

C#
using iTextSharp.text.pdf;
using  iTextSharp.text;

private void createPdfA()
{

    Document document = new Document();

    // Create PdfAWriter with PdfAConformanceLevel.PDF_A_3B option if you
    // want to get a PDF/A-3b compliant document.
    PdfAWriter writer = PdfAWriter.GetInstance(document,
            new FileStream("./xmp_metadata.pdf",FileMode.Create),
            PdfAConformanceLevel.PDF_A_3B);
    // Create XMP metadata. It's a PDF/A requirement.
    writer.CreateXmpMetadata();

    document.Open();

    // Set output intent. PDF/A requirement.
    ICC_Profile icc = ICC_Profile
            .GetInstance(
                   "./sRGB Color Space Profile.icm");
    writer.SetOutputIntents("Custom", "", "http://www.color.org",
            "sRGB IEC61966-2.1", icc);

    // All fonts shall be embedded. PDF/A requirement.

    var fonts=FontFactory.GetFont(          
            "./FreeSansBold.ttf",
            BaseFont.WINANSI, BaseFont.EMBEDDED, 10);
    Font normal9 = FontFactory.GetFont(
            "./FreeSans.ttf",
            BaseFont.WINANSI, BaseFont.EMBEDDED, 9);
    Font bold9 = FontFactory.GetFont(
            "./FreeSansBold.ttf",
            BaseFont.WINANSI, BaseFont.EMBEDDED, 9);
    Font normal8 = FontFactory.GetFont(
            "./FreeSans.ttf",
            BaseFont.WINANSI, BaseFont.EMBEDDED, 8);


    // Creating PDF/A-3 compliant attachment.
    PdfDictionary parameters = new PdfDictionary();
    parameters.Put(PdfName.MODDATE, new PdfDate());
    PdfFileSpecification fileSpec = PdfFileSpecification.FileEmbedded(
            writer, "./invoice.xml",
            "invoice.xml", null, "application/xml", parameters, 0);
    fileSpec.Put(new PdfName("AFRelationship"), new PdfName("Data"));
    writer.AddFileAttachment("invoice.xml", fileSpec);
    PdfArray array = new PdfArray();
    array.Add(fileSpec.Reference);
    writer.ExtraCatalog.Put(new PdfName("AF"), array);


    // From here on we can add content to the PDF just like we would do for
    // a regular PDF.

    // Building header.
    document.Add(new Paragraph("Invoice number: " + 1));
 //   document.Add(new Paragraph("\n", normal8));
    document.Add(new Paragraph("Dear " +"NAMEInvoice"));
    document.Add(new Paragraph(
            "Thank you "
            ));
    document.Add(new Paragraph("\n"));

    document.Close();
    writer.Close();
}
Posted
v8

1 solution

 
Share this answer
 
Comments
ajirahman 3-Oct-13 3:19am    
Thanks for your comments
Hi ajirahman,

Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Tadit
GeraldManickam 10-May-17 4:00am    
Thank you so much, This solution works for me. i will try with more samples and post my clarifications if any
I am glad that helped. Most welcome. :)
vineethnair 18-May-23 3:44am    
kindly guide me how you solve this error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900