mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java
public void PDFAttachGenericFile(PDDocument doc, String filename,
			String relationship, String description, String subType, byte[] data)
			throws IOException {
		PDComplexFileSpecification fs = new PDComplexFileSpecification();
		fs.setFile(filename);

		COSDictionary dict = fs.getCOSDictionary();
		dict.setName("AFRelationship", relationship);
		dict.setString("UF", filename);
		dict.setString("Desc", description);

		ByteArrayInputStream fakeFile = new ByteArrayInputStream(data);
		PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile);
		ef.setSubtype(subType);
		ef.setSize(data.length);
		ef.setCreationDate(new GregorianCalendar());

		ef.setModDate(GregorianCalendar.getInstance());

		fs.setEmbeddedFile(ef);

		// In addition make sure the embedded file is set under /UF
		dict = fs.getCOSDictionary();
		COSDictionary efDict = (COSDictionary) dict
				.getDictionaryObject(COSName.EF);
		COSBase lowerLevelFile = efDict.getItem(COSName.F);
		efDict.setItem(COSName.UF, lowerLevelFile);

		// now add the entry to the embedded file tree and set in the document.
		PDDocumentNameDictionary names = new PDDocumentNameDictionary(
				doc.getDocumentCatalog());
		PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles();
		if (efTree == null) {
			efTree = new PDEmbeddedFilesNameTreeNode();
		}

		Map<String, COSObjectable> namesMap = new HashMap<String, COSObjectable>();
		Map<String, COSObjectable> oldNamesMap = efTree.getNames();
		if (oldNamesMap != null) {
			for (String key : oldNamesMap.keySet()) {
				namesMap.put(key, oldNamesMap.get(key));
			}
		}
		namesMap.put(filename, fs);
		efTree.setNames(namesMap);

		names.setEmbeddedFiles(efTree);
		doc.getDocumentCatalog().setNames(names);

		// AF entry (Array) in catalog with the FileSpec
		COSArray cosArray = (COSArray) doc.getDocumentCatalog()
				.getCOSDictionary().getItem("AF");
		if (cosArray == null) {
			cosArray = new COSArray();
		}
		cosArray.add(fs);
		doc.getDocumentCatalog().getCOSDictionary().setItem("AF", cosArray);
	}
/**
	 * Embeds an external file (generic - any type allowed) in the PDF.
	 *
	 * @param doc
	 *            PDDocument to attach the file to.
	 * @param filename
	 *            name of the file that will become attachment name in the PDF
	 * @param relationship
	 *            how the file relates to the content, e.g. "Alternative"
	 * @param description
	 *            Human-readable description of the file content
	 * @param subType
	 *            type of the data e.g. could be "text/xml" - mime like
	 * @param data
	 *            the binary data of the file/attachment
	 */
Embeds an external file (generic - any type allowed) in the PDF.

@param doc
PDDocument to attach the file to.
@param filename
name of the file that will become attachment name in the PDF
@param relationship
how the file relates to the content, e.g. "Alternative"
@param description
Human-readable description of the file content
@param subType
type of the data e.g. could be "text/xml" - mime like
@param data
the binary data of the file/attachment
Embeds an external file ( generic - any type allowed ) in the PDF . @param doc PDDocument to attach the file to . @param filename name of the file that will become attachment name in the PDF @param relationship how the file relates to the content e . g . " Alternative " @param description Human - readable description of the file content @param subType type of the data e . g . could be " text / xml " - mime like @param data the binary data of the file / attachment
public void PDFAttachGenericFile(PDDocument doc, String filename,
			String relationship, String description, String subType, byte[] data)
			throws IOException {
		PDComplexFileSpecification fs = new PDComplexFileSpecification();
		fs.setFile(filename);
		COSDictionary dict = fs.getCOSDictionary();
		dict.setName("AFRelationship", relationship);
		dict.setString("UF", filename);
		dict.setString("Desc", description);
		ByteArrayInputStream fakeFile = new ByteArrayInputStream(data);
		PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile);
		ef.setSubtype(subType);
		ef.setSize(data.length);
		ef.setCreationDate(new GregorianCalendar());
		ef.setModDate(GregorianCalendar.getInstance());
		fs.setEmbeddedFile(ef);
		dict = fs.getCOSDictionary();
		COSDictionary efDict = (COSDictionary) dict
				.getDictionaryObject(COSName.EF);
		COSBase lowerLevelFile = efDict.getItem(COSName.F);
		efDict.setItem(COSName.UF, lowerLevelFile);
		PDDocumentNameDictionary names = new PDDocumentNameDictionary(
				doc.getDocumentCatalog());
		PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles();
		if (efTree == null) {
			efTree = new PDEmbeddedFilesNameTreeNode();
		}
		Map<String, COSObjectable> namesMap = new HashMap<String, COSObjectable>();
		Map<String, COSObjectable> oldNamesMap = efTree.getNames();
		if (oldNamesMap != null) {
			for (String key : oldNamesMap.keySet()) {
				namesMap.put(key, oldNamesMap.get(key));
			}
		}
		namesMap.put(filename, fs);
		efTree.setNames(namesMap);
		names.setEmbeddedFiles(efTree);
		doc.getDocumentCatalog().setNames(names);
		COSArray cosArray = (COSArray) doc.getDocumentCatalog()
				.getCOSDictionary().getItem("AF");
		if (cosArray == null) {
			cosArray = new COSArray();
		}
		cosArray.add(fs);
		doc.getDocumentCatalog().getCOSDictionary().setItem("AF", cosArray);
	}
public void PDFAttachGenericFile ( PDDocument doc , String filename , String relationship , String description , String subType , byte [ ] data ) throws IOException { PDComplexFileSpecification fs = new PDComplexFileSpecification ( ) ; fs . setFile ( filename ) ; COSDictionary dict = fs . getCOSDictionary ( ) ; dict . setName ( "AFRelationship" , relationship ) ; dict . setString ( "UF" , filename ) ; dict . setString ( "Desc" , description ) ; ByteArrayInputStream fakeFile = new ByteArrayInputStream ( data ) ; PDEmbeddedFile ef = new PDEmbeddedFile ( doc , fakeFile ) ; ef . setSubtype ( subType ) ; ef . setSize ( data . length ) ; ef . setCreationDate ( new GregorianCalendar ( ) ) ; ef . setModDate ( GregorianCalendar . getInstance ( ) ) ; fs . setEmbeddedFile ( ef ) ; dict = fs . getCOSDictionary ( ) ; COSDictionary efDict = ( COSDictionary ) dict . getDictionaryObject ( COSName . EF ) ; COSBase lowerLevelFile = efDict . getItem ( COSName . F ) ; efDict . setItem ( COSName . UF , lowerLevelFile ) ; PDDocumentNameDictionary names = new PDDocumentNameDictionary ( doc . getDocumentCatalog ( ) ) ; PDEmbeddedFilesNameTreeNode efTree = names . getEmbeddedFiles ( ) ; if ( efTree == null ) { efTree = new PDEmbeddedFilesNameTreeNode ( ) ; } Map < String , COSObjectable > namesMap = new HashMap < String , COSObjectable > ( ) ; Map < String , COSObjectable > oldNamesMap = efTree . getNames ( ) ; if ( oldNamesMap != null ) { for ( String key : oldNamesMap . keySet ( ) ) { namesMap . put ( key , oldNamesMap . get ( key ) ) ; } } namesMap . put ( filename , fs ) ; efTree . setNames ( namesMap ) ; names . setEmbeddedFiles ( efTree ) ; doc . getDocumentCatalog ( ) . setNames ( names ) ; COSArray cosArray = ( COSArray ) doc . getDocumentCatalog ( ) . getCOSDictionary ( ) . getItem ( "AF" ) ; if ( cosArray == null ) { cosArray = new COSArray ( ) ; } cosArray . add ( fs ) ; doc . getDocumentCatalog ( ) . getCOSDictionary ( ) . setItem ( "AF" , cosArray ) ; }
Embeds an external file (generic - any type allowed) in the PDF.
Embeds an external file ( generic - any type allowed ) in the PDF .
// In addition make sure the embedded file is set under /UF
 // now add the entry to the embedded file tree and set in the document.
 // AF entry (Array) in catalog with the FileSpec
