title: PDFBox 2 does not create PDF/A file
body: <p>I'm trying to create a PDF/A file using PDFBox 2. My code is based on the exmpale code <a href="https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java" rel="nofollow noreferrer">here</a>. The code runs wihtout errors. But if I validate the file using callas pdfPilot and veraPDF there is no XMP metadata and no PDF/A version info. Also the PDF file is version 1.4. Not 1.7 as set in the code.</p>
  
  <pre class="lang-java prettyprint-override"><code>// TTF font needed for Unicode support in OCR texts
  PDFont font = PDType0Font.load(document,
      PDDocument.class.getResourceAsStream("/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"), true);
  
  // Add metadata (needed by PDF/A)
  XMPMetadata xmp = XMPMetadata.createXMPMetadata();
  try {
      DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
      dc.setTitle("THE DOCUMENT TITLE");
      dc.addCreator("THE AUTHOR");
  
      PDFAIdentificationSchema id = xmp.createAndAddPFAIdentificationSchema();
      id.setPart(2);
      id.setConformance("B");
  
      XmpSerializer serializer = new XmpSerializer();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      serializer.serialize(xmp, baos, true);
  
      PDMetadata metadata = new PDMetadata(document);
      metadata.importXMPMetadata(baos.toByteArray());
      document.getDocumentCatalog().setMetadata(metadata);
  } catch (BadFieldValueException e) {
      throw new IllegalArgumentException("", e);
  }
  
  // Set color profile (needed by PDF/A)
  InputStream colorProfile = PDDocument.class.getResourceAsStream("/sRGB.icc");
  PDOutputIntent intent = new PDOutputIntent(document, colorProfile);
  intent.setInfo("sRGB IEC61966-2.1");
  intent.setOutputCondition("sRGB IEC61966-2.1");
  intent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
  intent.setRegistryName("http://www.color.org");
  document.getDocumentCatalog().addOutputIntent(intent);
  
  // Render all pages
  for (IPage page : pages) {
      ((PdfboxPage)page).setFont(font);
      page.renderPage(this);
      document.addPage((PDPage) page.getPage());
  }
  
  document.setVersion(1.7f);
  document.save(path);
  document.close();
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>I can see there is the xpacket in the PDF file. It includes the metadata. But it looks like PDFBox doesn't write this data in a valid way (for veraPDF and pdfPilot).</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Looks like PDFBox 2.0.12 builds invalid PDF/A. I converted the PDF using our commercial pdfPilot program. (PDF/A-1b)</p>
  
  <p><strong>PDFBox writes this to the PDF file</strong> (-> invalid in veraPDF and pdfPilot):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xpacket begin="
  " id="W5M0MpCehiHzreSzNTczkc9d"?&gt;
  &lt;x:xmpmeta xmlns:x="adobe:ns:meta/"&gt;
     &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
        &lt;rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about=""&gt;
           &lt;dc:title&gt;
              &lt;rdf:Alt&gt;
                 &lt;rdf:li lang="x-default"&gt;THE DOCUMENT TITLE&lt;/rdf:li&gt;
              &lt;/rdf:Alt&gt;
           &lt;/dc:title&gt;
           &lt;dc:creator&gt;
              &lt;rdf:Seq&gt;
                 &lt;rdf:li&gt;THE AUTHOR&lt;/rdf:li&gt;
              &lt;/rdf:Seq&gt;
           &lt;/dc:creator&gt;
        &lt;/rdf:Description&gt;
        &lt;rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about=""&gt;
           &lt;pdfaid:part&gt;1&lt;/pdfaid:part&gt;
           &lt;pdfaid:conformance&gt;B&lt;/pdfaid:conformance&gt;
        &lt;/rdf:Description&gt;
     &lt;/rdf:RDF&gt;
  &lt;/x:xmpmeta&gt;
  &lt;?xpacket end="w"?&gt;
  </code></pre>
  
  <p><strong>pdfPilot writes this to the PDF file</strong> (-> valid in veraPDF and pdfPilot):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xpacket begin="
  " id="W5M0MpCehiHzreSzNTczkc9d"?&gt;
  &lt;x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c015 81.159809, 2016/11/11-01:42:16        "&gt;
     &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
        &lt;rdf:Description rdf:about=""
              xmlns:dc="http://purl.org/dc/elements/1.1/"
              xmlns:xmp="http://ns.adobe.com/xap/1.0/"
              xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
              xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
              xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/"
              xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
              xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
              xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#"&gt;
           &lt;dc:format&gt;application/pdf&lt;/dc:format&gt;
           &lt;dc:creator&gt;
              &lt;rdf:Seq&gt;
                 &lt;rdf:li&gt;AUTOR&lt;/rdf:li&gt;
              &lt;/rdf:Seq&gt;
           &lt;/dc:creator&gt;
           &lt;dc:title&gt;
              &lt;rdf:Alt&gt;
                 &lt;rdf:li xml:lang="x-default"&gt;TITEL&lt;/rdf:li&gt;
              &lt;/rdf:Alt&gt;
           &lt;/dc:title&gt;
           &lt;xmp:ModifyDate&gt;2019-01-11T11:42:22+01:00&lt;/xmp:ModifyDate&gt;
           &lt;xmp:CreateDate&gt;2019-01-11T11:42:21+01:00&lt;/xmp:CreateDate&gt;
           &lt;xmp:MetadataDate&gt;2019-01-11T11:42:22+01:00&lt;/xmp:MetadataDate&gt;
           &lt;xmpMM:DocumentID&gt;uuid:b60f88c2-aa89-11b2-0a00-104bbf060000&lt;/xmpMM:DocumentID&gt;
           &lt;xmpMM:InstanceID&gt;uuid:b61148b9-aa89-11b2-0a00-60d9faa0ff7f&lt;/xmpMM:InstanceID&gt;
           &lt;xmpMM:RenditionClass&gt;default&lt;/xmpMM:RenditionClass&gt;
           &lt;xmpMM:VersionID&gt;1&lt;/xmpMM:VersionID&gt;
           &lt;xmpMM:History&gt;
              &lt;rdf:Seq&gt;
                 &lt;rdf:li rdf:parseType="Resource"&gt;
                    &lt;stEvt:action&gt;converted&lt;/stEvt:action&gt;
                    &lt;stEvt:instanceID&gt;uuid:b60f88c3-aa89-11b2-0a00-902dfba0ff7f&lt;/stEvt:instanceID&gt;
                    &lt;stEvt:parameters&gt;converted to PDF/A-1b&lt;/stEvt:parameters&gt;
                    &lt;stEvt:softwareAgent&gt;pdfaPilot&lt;/stEvt:softwareAgent&gt;
                    &lt;stEvt:when&gt;2019-01-11T11:42:22+01:00&lt;/stEvt:when&gt;
                 &lt;/rdf:li&gt;
              &lt;/rdf:Seq&gt;
           &lt;/xmpMM:History&gt;
           &lt;pdfaid:part&gt;1&lt;/pdfaid:part&gt;
           &lt;pdfaid:conformance&gt;B&lt;/pdfaid:conformance&gt;
           &lt;pdfaExtension:schemas&gt;
              &lt;rdf:Bag&gt;
                 &lt;rdf:li rdf:parseType="Resource"&gt;
                    &lt;pdfaSchema:namespaceURI&gt;http://ns.adobe.com/xap/1.0/mm/&lt;/pdfaSchema:namespaceURI&gt;
                    &lt;pdfaSchema:prefix&gt;xmpMM&lt;/pdfaSchema:prefix&gt;
                    &lt;pdfaSchema:schema&gt;XMP Media Management Schema&lt;/pdfaSchema:schema&gt;
                    &lt;pdfaSchema:property&gt;
                       &lt;rdf:Seq&gt;
                          &lt;rdf:li rdf:parseType="Resource"&gt;
                             &lt;pdfaProperty:category&gt;internal&lt;/pdfaProperty:category&gt;
                             &lt;pdfaProperty:description&gt;UUID based identifier for specific incarnation of a document&lt;/pdfaProperty:description&gt;
                             &lt;pdfaProperty:name&gt;InstanceID&lt;/pdfaProperty:name&gt;
                             &lt;pdfaProperty:valueType&gt;URI&lt;/pdfaProperty:valueType&gt;
                          &lt;/rdf:li&gt;
                          &lt;rdf:li rdf:parseType="Resource"&gt;
                             &lt;pdfaProperty:category&gt;internal&lt;/pdfaProperty:category&gt;
                             &lt;pdfaProperty:description&gt;The common identifier for all versions and renditions of a document.&lt;/pdfaProperty:description&gt;
                             &lt;pdfaProperty:name&gt;OriginalDocumentID&lt;/pdfaProperty:name&gt;
                             &lt;pdfaProperty:valueType&gt;URI&lt;/pdfaProperty:valueType&gt;
                          &lt;/rdf:li&gt;
                       &lt;/rdf:Seq&gt;
                    &lt;/pdfaSchema:property&gt;
                 &lt;/rdf:li&gt;
                 &lt;rdf:li rdf:parseType="Resource"&gt;
                    &lt;pdfaSchema:namespaceURI&gt;http://www.aiim.org/pdfa/ns/id/&lt;/pdfaSchema:namespaceURI&gt;
                    &lt;pdfaSchema:prefix&gt;pdfaid&lt;/pdfaSchema:prefix&gt;
                    &lt;pdfaSchema:schema&gt;PDF/A ID Schema&lt;/pdfaSchema:schema&gt;
                    &lt;pdfaSchema:property&gt;
                       &lt;rdf:Seq&gt;
                          &lt;rdf:li rdf:parseType="Resource"&gt;
                             &lt;pdfaProperty:category&gt;internal&lt;/pdfaProperty:category&gt;
                             &lt;pdfaProperty:description&gt;Part of PDF/A standard&lt;/pdfaProperty:description&gt;
                             &lt;pdfaProperty:name&gt;part&lt;/pdfaProperty:name&gt;
                             &lt;pdfaProperty:valueType&gt;Integer&lt;/pdfaProperty:valueType&gt;
                          &lt;/rdf:li&gt;
                          &lt;rdf:li rdf:parseType="Resource"&gt;
                             &lt;pdfaProperty:category&gt;internal&lt;/pdfaProperty:category&gt;
                             &lt;pdfaProperty:description&gt;Amendment of PDF/A standard&lt;/pdfaProperty:description&gt;
                             &lt;pdfaProperty:name&gt;amd&lt;/pdfaProperty:name&gt;
                             &lt;pdfaProperty:valueType&gt;Text&lt;/pdfaProperty:valueType&gt;
                          &lt;/rdf:li&gt;
                          &lt;rdf:li rdf:parseType="Resource"&gt;
                             &lt;pdfaProperty:category&gt;internal&lt;/pdfaProperty:category&gt;
                             &lt;pdfaProperty:description&gt;Conformance level of PDF/A standard&lt;/pdfaProperty:description&gt;
                             &lt;pdfaProperty:name&gt;conformance&lt;/pdfaProperty:name&gt;
                             &lt;pdfaProperty:valueType&gt;Text&lt;/pdfaProperty:valueType&gt;
                          &lt;/rdf:li&gt;
                       &lt;/rdf:Seq&gt;
                    &lt;/pdfaSchema:property&gt;
                 &lt;/rdf:li&gt;
              &lt;/rdf:Bag&gt;
           &lt;/pdfaExtension:schemas&gt;
        &lt;/rdf:Description&gt;
     &lt;/rdf:RDF&gt;
  &lt;/x:xmpmeta&gt;
  &lt;?xpacket end="w"?&gt;
  </code></pre>
  
  <p>And if I statically write this to the PDF file it produces a valid PDF/A file:</p>
  
  <pre class="lang-java prettyprint-override"><code>String xmpData = "&lt;?xpacket ......";
  PDMetadata metadata = new PDMetadata(document);
  metadata.importXMPMetadata(xmpData.getBytes());
  </code></pre>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>Adding this is valid and short:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?&gt;
  &lt;x:xmpmeta xmlns:x="adobe:ns:meta/" &gt;
      &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
          &lt;rdf:Description rdf:about=""
              xmlns:dc="http://purl.org/dc/elements/1.1/"
              xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/"&gt;
              &lt;dc:format&gt;application/pdf&lt;/dc:format&gt;
              &lt;dc:creator&gt;
              &lt;rdf:Seq&gt;
                  &lt;rdf:li&gt;AUTOR&lt;/rdf:li&gt;
              &lt;/rdf:Seq&gt;
              &lt;/dc:creator&gt;
              &lt;dc:title&gt;
              &lt;rdf:Alt&gt;
                  &lt;rdf:li xml:lang="x-default"&gt;TITEL&lt;/rdf:li&gt;
              &lt;/rdf:Alt&gt;
              &lt;/dc:title&gt;
              &lt;pdfaid:part&gt;1&lt;/pdfaid:part&gt;
              &lt;pdfaid:conformance&gt;B&lt;/pdfaid:conformance&gt;
          &lt;/rdf:Description&gt;
      &lt;/rdf:RDF&gt;
  &lt;/x:xmpmeta&gt;
  &lt;?xpacket end="w"?&gt;
  </code></pre>