Hi,
I am trying to extract the attachments from a pdf and add them to a new
PDF file. With the following code, everything works fine, except the
Modified date is failing. I am not able to get the Modified date metadata
of the attachment(I get null) and because of that in the new PDF it is
showing as Unknown.
It would be great if somebody help me to identify what is wrong with the
following code.
I tried pdfSpec.put(PdfName.MODDATE,new PDFDate()) too. But that is also
not working. I still get Modified date of attachment in the new PDF as
Unknown.


PdfDictionary embFiles = (PdfDictionary) PdfReader
                .getPdfObject(names.get(new PdfName("EmbeddedFiles")));
if (embFiles != null) {
        HashMap  embMap = PdfNameTree.readTree(embFiles);
        for (Iterator i = embMap.values().iterator(); i.hasNext();) {
                PdfDictionary filespec = (PdfDictionary) PdfReader
                                .getPdfObject((PdfObject)i.next());
                PdfFileSpecification attachment = new PdfFileSpecification();
                String filename = ((PdfString) PdfReader.getPdfObject(filespec
                                                        
.get(PdfName.F))).toString();
                String title =filename;
                 PdfDictionary pd=new PdfDictionary();
//get the byte array content from the attachment
                byte[] b = extractAttachmentContent(reader,filespec);
                PdfFileSpecification pdfSpec =
                                PdfFileSpecification.fileEmbedded(writer, 
filename,
                title,                                                          
b, true);
                pdfSpec.put(PdfName.TITLE,filespec.get(PdfName.TITLE));
                pdfSpec.put(PdfName.NAME,filespec.get(PdfName.NAME));
//The following line is not working.
                pdfSpec.put(PdfName.MODDATE,filespec.get(PdfName.MODDATE));
                pdfSpec.put(PdfName.SIZE,filespec.get(PdfName.SIZE));
                pdfSpec.put(PdfName.DESC,filespec.get(PdfName.DESC));
                writer.addFileAttachment(pdfSpec);

        }
}


Thanks
Santhosh





------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to