[
https://issues.apache.org/jira/browse/PDFBOX-3467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15426575#comment-15426575
]
Tilman Hausherr commented on PDFBOX-3467:
-----------------------------------------
I have a possible solution after having a look at COSArrayList. Create a new
constructor there:
{code}
/**
* This constructor is to be used if the array doesn't exist, but is to be
created and added to
* the parent dictionary as soon as the first element is added to the array.
*
* @param dictionary The dictionary that holds the item, and will hold the
array if an item is
* added.
* @param dictionaryKey The key into the dictionary to set the item.
*/
public COSArrayList(COSDictionary dictionary, COSName dictionaryKey)
{
array = new COSArray();
actual = new ArrayList<E>();
parentDict = dictionary;
dictKey = dictionaryKey;
}
{code}
then the code you changed could be this instead:
{code}
return new COSArrayList<PDAnnotation>(page, COSName.ANNOTS);
{code}
in the add() method, COSArrayList would call setItem(), but only the first time.
Now tests pass.
> PDPage.getAnnotations() modifies the PDF
> ----------------------------------------
>
> Key: PDFBOX-3467
> URL: https://issues.apache.org/jira/browse/PDFBOX-3467
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 2.0.2
> Reporter: John Hewson
> Assignee: John Hewson
> Fix For: 2.1.0
>
>
> I stumbled across this bug while using PDFDebugger.
> PDPage.getAnnotations() writes to the Page's COSDictionary, adding a new
> Annots entry if it is missing.
> This violates one of the rules which we introduced for 2.0, that reading from
> a PDF file should not result in the file's COS model being modified.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]