1T3XT info wrote:
>
> 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
>
I actually think the library is quite powerful, but I find many aspects of
it far too convoluted. Good design practices strive to hide the underlying
complexities, which is apparently not a primary goal of iText. You imply
that I haven't already studied the PDF reference manual on the basis that I
asked for help in understanding a particular feature of the iText library.
Requiring all developers to study the PDF reference manual for anything
other than extremely complex tasks is absurd. Does the Java team require
users to study ZIP/JAR reference manuals in order to use the corresponding
libraries? Adding attachments with iText is very simple, so why not simply
provide convenience methods to get a specific attachment, get a list of
attachments, replace an attachment, remove an attachment, or remove all
attachments?
Anyway, I am reposting the code solution, that contains one additional
method call (in bold text) required to free the unused objects. I hope
others will find this useful.
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);
}
reader.removeUnusedObjects();
}
}
}
--
View this message in context:
http://www.nabble.com/Managing-PDF-attachments-with-iText-tp21712325p21752969.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
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