You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Jochen Stärk <js...@usegroup.de> on 2013/12/26 22:05:04 UTC

How can I embed files in PDF/A-3a?

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

Re: How can I embed files in PDF/A-3a?

Posted by Thomas Chojecki <in...@rayman2200.de>.
Am Thu, 26 Dec 2013 22:05:04 +0100
schrieb Jochen Stärk <js...@usegroup.de>:

> Hi,
Hi Jochen,

> 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.
> >>
As you already find out, UF is the Unicode filename. It is the
prefered way to store the filename in newer pdf versions.

In the 32000_2008 spec I couldn't find the AFRelationship key at all
but I found this site
http://www.digitalpreservation.gov/formats/fdd/fdd000360.shtml with some
PDF/A-3 notes that mention that key. I know there is a seperate
specification available for the PDF/A-3. Also there is the new PDF spec
32000_2012 (this spec is refered in the note)

> 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?			
Hard to say, the best way is to buy at least the PDF/A-3 spec and look
at it. Otherway try to find some low level infos someway about embedding
files. 

> 
> 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.
You can get the COSDictionary and write the specific key.

I think it is the PDComplexFileSpecification class where you need to
put the UF key. So do something like:

PDComplexFileSpecification embeddedFile = ...
COSDictionary dict = embeddedFile.getCOSDictionary();
dict.setString(COSNAME.UF,"Filename"); 

and for the AFRelationship you need to do similar low level
manipulation. There are setter for all kind of data. If you want to add
custom types you can also use the dict.setItem(...) to add other low
level COS objects like arrays or other cos dictionaries.

You can create Arrays with the COSArray object. 

"Relationship links are established from the document or parts of the
document by use of the AF key, which contains an array of file
specification dictionaries (as described above). Files associated with
the entire document are represented by an AF key in the Catalog for the
PDF file"

So try to associate the files inside the catalog. This is maybe the
simplest way.

PDDocument doc = ...
PDDocumentCatalog catalog = doc.getDocumentCatalog();
COSDictionary dict = catalog.getCOSDictionary();
COSArray array = new COSArray();
array.add(embeddedFile.getCOSDictionary()); // see below
dict.setItem("AF",array);

If this does not work and the note does not help you would need to buy
the spec or get this informations of the "Annex E of ISO 19005-3:2012"
to do this task.
 
If this work, please give us a feedback.

> Or maybe anybody has any example where I could have a look?
> 
> thanks a lot in advance (and happy holidays)!
> Jochen

Best regards
Thomas