Hi,

I'm trying to add Zugferd (http://www.ferd-net.de/) electronic invoicing
metadata to a PDF/A-1a created with OpenOffice

PdfBox (snippet attached) helps me to "convert" it to PDF/A-3a in a
first step, which seems to work, at least
http://www.pdf-tools.com/pdf/validate-pdfa-online.aspx validates.

In the second step (based on
http://pdfbox.apache.org/cookbook/workingwithattachments.html) I try to
embed a file but then the validator tells me
<<
The key UF is required but missing.
The content of the stream must not be in an external file.
The key AFRelationship is required but missing.
File specification 'Test.txt' not associated with an object.
>>


How do I get the content of the stream embedded (not "in an external
file") and do I need / how do I get the file specification 'Test.txt' to
be associated with the according object?                        


Is there a way to specify the UF key or AFRelationship ?
The UF key seems to be a unicode version of the F key and
for AFRelationship I would like to specify a "source" relationship.

Or maybe anybody has any example where I could have a look?

thanks a lot in advance (and happy holidays)!
Jochen

-- 
mit freundlichen Grüßen
Jochen Stärk

www.usegroup.de            (home office)
Albigerstr. 22             Huswertstraße 14
55232 Alzey                60435 Frankfurt

Tel: (069)569940-20
Fax: (069)569940-19
Mobil: (0177)4512645
//Step 1: "convert" PDF A-1 to A-3a

PDDocument doc = PDDocument.load(client.getTransactions()
        .getCurrentTransaction().getFilenamePDF());
PDDocumentCatalog cat = doc.getDocumentCatalog();
PDMetadata metadata = new PDMetadata(doc);
cat.setMetadata(metadata);
XMPMetadata xmp = new XMPMetadata();
XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp);
xmp.addSchema(pdfaid);
pdfaid.setConformance("A");
pdfaid.setPart(3);
pdfaid.setAbout("");

XMPSchemaDublinCore dc = xmp.addDublinCoreSchema();
String creator="Jochen Staerk";
String producer="My Software";
dc.addCreator(creator);
dc.setAbout("");
                            
                            
XMPSchemaBasic xsb=xmp.addBasicSchema();
xsb.setAbout("");

xsb.setCreatorTool(creator);
xsb.setCreateDate(GregorianCalendar.getInstance());
PDDocumentInformation pdi=new PDDocumentInformation();
pdi.setProducer(producer);
pdi.setAuthor(creator);
doc.setDocumentInformation(pdi);

XMPSchemaPDF pdf=xmp.addPDFSchema();
pdf.setProducer(producer);
pdf.setAbout("");
try {
        metadata.importXMPMetadata(xmp);
} catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
}

                                        
// Step 2: embed file   

PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();

 // create the file specification, which holds the embedded file
   
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFile( "Test.txt" );
 
                                  
// file content
String payload="This is a test";
// convert to input stream 
InputStream is = new ByteArrayInputStream(payload.getBytes());

PDEmbeddedFile ef = new PDEmbeddedFile(doc, is );
 //set some of the attributes of the embedded file
ef.setSubtype( "test/plain" );
ef.setFile(fs);
ef.setModDate(GregorianCalendar.getInstance());
ef.setSize( payload.length() );
ef.setCreationDate( new GregorianCalendar() );
fs.setEmbeddedFile( ef );

//now add the entry to the embedded file tree and set in the document.
Map efMap = new HashMap();
efMap.put( "My first attachment", fs );
efTree.setNames( efMap );
//attachments are stored as part of the "names" dictionary in the document 
catalog
PDDocumentNameDictionary names = new PDDocumentNameDictionary( 
doc.getDocumentCatalog() );
names.setEmbeddedFiles( efTree );
 
doc.getDocumentCatalog().setNames( names );

// step 3: save                           
                                        
doc.save("pdffilename.pdf");

Reply via email to