Skip to content

Commit

Permalink
AF entry for catalog with FileSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman2200 committed Apr 8, 2014
1 parent 90c2efd commit 8167a23
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/pdfbox/PDFA3FileAttachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.apache.jempbox.xmp.XMPSchemaDublinCore;
import org.apache.jempbox.xmp.XMPSchemaPDF;
import org.apache.jempbox.xmp.pdfa.XMPSchemaPDFAId;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
Expand Down Expand Up @@ -71,7 +73,8 @@ private void attachSampleFile(PDDocument doc) throws IOException
fs.setFile("Test.txt");
COSDictionary dict = fs.getCOSDictionary();
// Relation "Source" for linking with eg. catalog
dict.setName("AFRelationship", "Source");
dict.setName("AFRelationship", "Alternative");
// dict.setName("AFRelationship", "Source");

dict.setString("UF", "Test.txt");
// fs.put(new PdfName("AFRelationship"), new PdfName("Source"));
Expand All @@ -85,14 +88,15 @@ private void attachSampleFile(PDDocument doc) throws IOException

ef.setSubtype("text/plain");
ef.setFile(fs);
// ef.getStream().setItem(COSName.UF, fs);

ef.setModDate(GregorianCalendar.getInstance());

// PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer,
// src.getAbsolutePath(), src.getName(), null, false, "image/jpeg",
// fileParameter);

// fs.put(new PdfName("AFRelationship"), new PdfName("Source"));
// fs.put(new PdfName("AFRelationship"), new PdfName("Source"));

ef.setSize(payload.length());
ef.setCreationDate(new GregorianCalendar());
Expand All @@ -111,10 +115,17 @@ private void attachSampleFile(PDDocument doc) throws IOException
* */
// attachments are stored as part of the "names" dictionary in the document
// catalog
PDDocumentCatalog catalog = doc.getDocumentCatalog();

PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
names.setEmbeddedFiles(efTree);

doc.getDocumentCatalog().setNames(names);
catalog.setNames(names);

// AF entry (Array) in catalog with the FileSpec
COSArray cosArray = new COSArray();
cosArray.add(fs);
catalog.getCOSDictionary().setItem("AF", cosArray);


}

Expand Down

0 comments on commit 8167a23

Please sign in to comment.