Search code examples
pdfitextxmp

Set XMP Data with itextSharp 5.3.3


I am struggling witha creation of a PDF/A with itextSharp I still use the PdfAWriter that return a PDF file that looks good, but i I try to validate the file here, something goes wrong. this validation tool return the following messages:

  • dc:title/*[0] :: Missing language qualifier.
  • dc:description/*[0] :: Missing language qualifier.
  • The required XMP property 'pdfaid:part' is missing
  • The required XMP property 'pdfaid:conformance' is missing
  • The required XMP property 'xmp:CreateDate' for the document information entry 'CreationDate' is missing.
  • The required XMP property 'xmp:ModifyDate' for the document information entry 'ModDate' is missing

This is the code I am using:

oWriter = PdfAWriter.GetInstance(oDoc, New FileStream(sNomeFileOut, FileMode.Create), PdfAConformanceLevel.PDF_A_1B)
oWriter.PdfVersion = PdfAWriter.VERSION_1_5
Dim pdfD As New PdfDictionary()
pdfD.Put(New PdfName("Keywords"), New PdfString("DESADV"))
pdfD.Put(New PdfName("Creator"), New PdfString("TESI eIntegration"))
pdfD.Put(New PdfName("Author"), New PdfString("TESI eIntegration"))
pdfD.Put(New PdfName("Title"), New PdfString("DESADV PDS version"))
pdfD.Put(New PdfName("Subject"), New PdfString("DESADV PDS version"))
pdfD.Put(New PdfName("pdfaid:conformance"), New PdfString("PDF/A 1B"))
pdfD.Put(New PdfName("xmp:CreateDate"), New PdfString(DateTime.Now.ToShortDateString()))
pdfD.Put(New PdfName("xmp:ModifyDate"), New PdfString(DateTime.Now.ToShortDateString()))
Dim stream As New MemoryStream
Dim xmp As New XmpWriter(stream, pdfD, PdfAConformanceLevel.PDF_A_1B)
xmp.Close()
oWriter.XmpMetadata = stream.ToArray()
oWriter.PageEvent = New PdfPageEventHandler

Someone can halp to solve this problem?


Solution

  • You can have iTextSharp create the XMP metadata automatically based on the metadata you set on the Document and the PDF/A conformance level. Try something like this:

    Document oDoc = new Document();
    PdfWriter oWriter = PdfAWriter.GetInstance(oDoc,
      new FileStream(sNomeFileOut, FileMode.Create), PdfAConformanceLevel.PDF_A_1B);
    oDoc.AddTitle("Some title");
    oDoc.AddSubject("Subject");
    oDoc.AddKeywords("Keywords, go, here");
    oDoc.AddCreator("Some app");
    oDoc.AddAuthor("Author");
    oWriter.CreateXmpMetadata();
    oDoc.Open();
    //...
    

    Like Bruno already commented, upgrading is a good idea: a lot of PDF/A related changes were done since 5.3.3.