demonstr8r wrote:
>
> demonstr8r wrote:
>> I am working on an utility that automates the generation of PDF files with
>> attachments using the iText Java library. So far, I can honsetly say
>> using
>> iText has saved me a bunch of time and effort. However, I ran into a bit
>> of
>> a snag this week related to removing and/or overwriting attachments within
>> a
>> PDF. Is this supported and if so how? Any advice is greatly appreciated.
>>
>
> I managed to figure out a partial solution after studying the PdfReader
> implemenation on sourceforge.net. Removing or overwriting a specific
> attachment appears to be quite a bit more involved. If you have a solution
> for that, please post it here.
>
> public void removeAttachments(PdfReader reader)
> {
> PdfDictionary catalog = reader.getCatalog();
> PdfDictionary names = (PdfDictionary)
> PdfReader.getPdfObject(catalog.get(PdfName.NAMES));
> if( names != null )
> {
> PdfDictionary files = (PdfDictionary)
> PdfReader.getPdfObject(names.get(PdfName.EMBEDDEDFILES));
> if( files != null )
> {
> for( Object key : files.getKeys() )
> {
> files.remove((PdfName)key);
> }
> }
> }
> }
The keys correspond with values. The values are references to stream
objects. The stream objects contain the attachments. If you want to
remove the attachments, you have to remove those streams too.
This is all possible with iText, but you need to study the PDF reference
manual, and then find out how to remove/replace a stream object with
iText. Here you can find some code snippets that explain how to replace
an Image stream: http://itext.ugent.be/library/question.php?id=66
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
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