You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Frédéric Ravetier <fr...@vikta.com> on 2023/10/30 12:57:28 UTC

Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Hi,

I am using the same code and PDFbox2 to add annotations on PDF.
The annotations are not displayed and I think they are not in the final PDF
when I am using one specific PDF.
This is the PDF :
https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing

This is the PDF where I added annotation and save using incrementalSave :
https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing

Do you have any ideas ? Do you need more information ?

Best regards,
Fred

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Frédéric Ravetier <fr...@vikta.com>.
I added that :

Get the COSObject of the new annotation (stamp), add it to the set of
COSToWrite and pass this information to the saveIncremental.

Set<COSDictionary> setCOSObjectToWrite =  new HashSet<COSDictionary>() ;
setCOSObjectToWrite.add(stamp.getCOSObject());

doc.saveIncremental(resultFile, setCOSObjectToWrite);

And then it works.

But it sounds like a bug in PDF2...







Le mar. 31 oct. 2023 à 08:32, Tilman Hausherr <TH...@t-online.de> a
écrit :

> Hi,
> I don't have time right now to test my theory, which would require
> setting update marks on the intermediate pagetree objects.
> In the meantime please try using the other saveIncremental call, where
> you pass COSDictionary objects. You'll probably need to only pass the
> page and your annotation and the appearance stuff, but not the catalog.
> (Unless you did other changes)
>
> I'll test my theory later, but this will likely only result in an
> improved javadoc.
>
> Tilman
>
> On 30.10.2023 21:16, Frédéric Ravetier wrote:
> > Thanks for your answer Tilman,
> >
> > * I was using 2.0.29
> > * this code is working well with all the pdf I used until now
> > * I did a test using pdfbox3 and it works but my code using pdf3 is not
> > production ready :(
> >
> > I prepare a test class that you can use
> >
> https://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
> > It uses another PDF that I shared with you :
> >
> https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing
> >
> > You need to place both PDF into testfiles/input/
> >
> > testB is using a PDF where it works
> > testC is using the PDF I shared before where it does not work.
> >
> > Fred
> >
> > Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr <TH...@t-online.de> a
> > écrit :
> >
> >> Hi,
> >>
> >> The annotations are missing in the incremental part. My guess is that
> >> you didn't include it in the update. You've updated the document catalog
> >> but not the page. Read the javadoc of the saveIncremental() carefully.
> >> If you can't get it to work, please share the smallest possible code
> >> that reproduces the effect.
> >>
> >> The current 2 version is 2.0.29.
> >>
> >> However I'm also wondering whether you hit a bug, or rather a problem.
> >> The page tree has several levels so if you use the "classic" incremental
> >> save then there is no direct path from the catalog to the page.
> >>
> >> Tilman
> >>
> >> On 30.10.2023 13:57, Frédéric Ravetier wrote:
> >>> Hi,
> >>>
> >>> I am using the same code and PDFbox2 to add annotations on PDF.
> >>> The annotations are not displayed and I think they are not in the final
> >> PDF
> >>> when I am using one specific PDF.
> >>> This is the PDF :
> >>>
> >>
> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
> >>> This is the PDF where I added annotation and save using
> incrementalSave :
> >>>
> >>
> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
> >>> Do you have any ideas ? Do you need more information ?
> >>>
> >>> Best regards,
> >>> Fred
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> >> For additional commands, e-mail: users-help@pdfbox.apache.org
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
I don't have time right now to test my theory, which would require 
setting update marks on the intermediate pagetree objects.
In the meantime please try using the other saveIncremental call, where 
you pass COSDictionary objects. You'll probably need to only pass the 
page and your annotation and the appearance stuff, but not the catalog. 
(Unless you did other changes)

I'll test my theory later, but this will likely only result in an 
improved javadoc.

Tilman

On 30.10.2023 21:16, Frédéric Ravetier wrote:
> Thanks for your answer Tilman,
>
> * I was using 2.0.29
> * this code is working well with all the pdf I used until now
> * I did a test using pdfbox3 and it works but my code using pdf3 is not
> production ready :(
>
> I prepare a test class that you can use
> https://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
> It uses another PDF that I shared with you :
> https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing
>
> You need to place both PDF into testfiles/input/
>
> testB is using a PDF where it works
> testC is using the PDF I shared before where it does not work.
>
> Fred
>
> Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr <TH...@t-online.de> a
> écrit :
>
>> Hi,
>>
>> The annotations are missing in the incremental part. My guess is that
>> you didn't include it in the update. You've updated the document catalog
>> but not the page. Read the javadoc of the saveIncremental() carefully.
>> If you can't get it to work, please share the smallest possible code
>> that reproduces the effect.
>>
>> The current 2 version is 2.0.29.
>>
>> However I'm also wondering whether you hit a bug, or rather a problem.
>> The page tree has several levels so if you use the "classic" incremental
>> save then there is no direct path from the catalog to the page.
>>
>> Tilman
>>
>> On 30.10.2023 13:57, Frédéric Ravetier wrote:
>>> Hi,
>>>
>>> I am using the same code and PDFbox2 to add annotations on PDF.
>>> The annotations are not displayed and I think they are not in the final
>> PDF
>>> when I am using one specific PDF.
>>> This is the PDF :
>>>
>> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
>>> This is the PDF where I added annotation and save using incrementalSave :
>>>
>> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
>>> Do you have any ideas ? Do you need more information ?
>>>
>>> Best regards,
>>> Fred
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Tilman Hausherr <TH...@t-online.de>.
I don't know if there is any risk. Mostly that you forget to add enough 
objects. But if you do, you'll notice if you look at the file and don't 
see the changes.

Tilman

On 01.11.2023 10:34, Frédéric Ravetier wrote:
> Thank you for this solution.
>
> What is the risk to use the second incrementalSave with COS in param ?
>
> Le mar. 31 oct. 2023 à 19:38, Tilman Hausherr <TH...@t-online.de> 
> a écrit :
>
>     I got it to work with the classic method by adding this code
>     before saving:
>
>
>                 COSDictionary parent =
>     page.getCOSObject().getCOSDictionary(COSName.PARENT);
>                 while (parent != null)
>                 {
>                     parent.setNeedToBeUpdated(true);
>                     parent = parent.getCOSDictionary(COSName.PARENT);
>                 }
>
>     In the screenshot below, the mouse is positioned on the page. The
>     /Parent link goes back to the top of the page tree (object 436
>     which is seen twice, but it's the same)
>
>
>     Tilman
>
>     On 30.10.2023 21:16, Frédéric Ravetier wrote:
>>     Thanks for your answer Tilman,
>>
>>     * I was using 2.0.29
>>     * this code is working well with all the pdf I used until now
>>     * I did a test using pdfbox3 and it works but my code using pdf3 is not
>>     production ready :(
>>
>>     I prepare a test class that you can use
>>     https://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
>>     It uses another PDF that I shared with you :
>>     https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing
>>
>>     You need to place both PDF into testfiles/input/
>>
>>     testB is using a PDF where it works
>>     testC is using the PDF I shared before where it does not work.
>>
>>     Fred
>>
>>     Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr<TH...@t-online.de>  <ma...@t-online.de>  a
>>     écrit :
>>
>>>     Hi,
>>>
>>>     The annotations are missing in the incremental part. My guess is that
>>>     you didn't include it in the update. You've updated the document catalog
>>>     but not the page. Read the javadoc of the saveIncremental() carefully.
>>>     If you can't get it to work, please share the smallest possible code
>>>     that reproduces the effect.
>>>
>>>     The current 2 version is 2.0.29.
>>>
>>>     However I'm also wondering whether you hit a bug, or rather a problem.
>>>     The page tree has several levels so if you use the "classic" incremental
>>>     save then there is no direct path from the catalog to the page.
>>>
>>>     Tilman
>>>
>>>     On 30.10.2023 13:57, Frédéric Ravetier wrote:
>>>>     Hi,
>>>>
>>>>     I am using the same code and PDFbox2 to add annotations on PDF.
>>>>     The annotations are not displayed and I think they are not in the final
>>>     PDF
>>>>     when I am using one specific PDF.
>>>>     This is the PDF :
>>>>
>>>     https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
>>>>     This is the PDF where I added annotation and save using incrementalSave :
>>>>
>>>     https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
>>>>     Do you have any ideas ? Do you need more information ?
>>>>
>>>>     Best regards,
>>>>     Fred
>>>>
>>>     ---------------------------------------------------------------------
>>>     To unsubscribe, e-mail:users-unsubscribe@pdfbox.apache.org
>>>     For additional commands, e-mail:users-help@pdfbox.apache.org
>>>
>>>
>

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Frédéric Ravetier <fr...@vikta.com>.
Thank you for this solution.

What is the risk to use the second incrementalSave with COS in param ?

Le mar. 31 oct. 2023 à 19:38, Tilman Hausherr <TH...@t-online.de> a
écrit :

> I got it to work with the classic method by adding this code before saving:
>
>
>             COSDictionary parent =
> page.getCOSObject().getCOSDictionary(COSName.PARENT);
>             while (parent != null)
>             {
>                 parent.setNeedToBeUpdated(true);
>                 parent = parent.getCOSDictionary(COSName.PARENT);
>             }
>
> In the screenshot below, the mouse is positioned on the page. The /Parent
> link goes back to the top of the page tree (object 436 which is seen twice,
> but it's the same)
>
>
> Tilman
>
> On 30.10.2023 21:16, Frédéric Ravetier wrote:
>
> Thanks for your answer Tilman,
>
> * I was using 2.0.29
> * this code is working well with all the pdf I used until now
> * I did a test using pdfbox3 and it works but my code using pdf3 is not
> production ready :(
>
> I prepare a test class that you can usehttps://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
> It uses another PDF that I shared with you :https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing
>
> You need to place both PDF into testfiles/input/
>
> testB is using a PDF where it works
> testC is using the PDF I shared before where it does not work.
>
> Fred
>
> Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr <TH...@t-online.de> <TH...@t-online.de> a
> écrit :
>
>
> Hi,
>
> The annotations are missing in the incremental part. My guess is that
> you didn't include it in the update. You've updated the document catalog
> but not the page. Read the javadoc of the saveIncremental() carefully.
> If you can't get it to work, please share the smallest possible code
> that reproduces the effect.
>
> The current 2 version is 2.0.29.
>
> However I'm also wondering whether you hit a bug, or rather a problem.
> The page tree has several levels so if you use the "classic" incremental
> save then there is no direct path from the catalog to the page.
>
> Tilman
>
> On 30.10.2023 13:57, Frédéric Ravetier wrote:
>
> Hi,
>
> I am using the same code and PDFbox2 to add annotations on PDF.
> The annotations are not displayed and I think they are not in the final
>
> PDF
>
> when I am using one specific PDF.
> This is the PDF :
>
>
> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
>
> This is the PDF where I added annotation and save using incrementalSave :
>
>
> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
>
> Do you have any ideas ? Do you need more information ?
>
> Best regards,
> Fred
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
>

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Tilman Hausherr <TH...@t-online.de>.
I got it to work with the classic method by adding this code before saving:


             COSDictionary parent = 
page.getCOSObject().getCOSDictionary(COSName.PARENT);
             while (parent != null)
             {
                 parent.setNeedToBeUpdated(true);
                 parent = parent.getCOSDictionary(COSName.PARENT);
             }

In the screenshot below, the mouse is positioned on the page. The 
/Parent link goes back to the top of the page tree (object 436 which is 
seen twice, but it's the same)


Tilman

On 30.10.2023 21:16, Frédéric Ravetier wrote:
> Thanks for your answer Tilman,
>
> * I was using 2.0.29
> * this code is working well with all the pdf I used until now
> * I did a test using pdfbox3 and it works but my code using pdf3 is not
> production ready :(
>
> I prepare a test class that you can use
> https://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
> It uses another PDF that I shared with you :
> https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing
>
> You need to place both PDF into testfiles/input/
>
> testB is using a PDF where it works
> testC is using the PDF I shared before where it does not work.
>
> Fred
>
> Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr<TH...@t-online.de>  a
> écrit :
>
>> Hi,
>>
>> The annotations are missing in the incremental part. My guess is that
>> you didn't include it in the update. You've updated the document catalog
>> but not the page. Read the javadoc of the saveIncremental() carefully.
>> If you can't get it to work, please share the smallest possible code
>> that reproduces the effect.
>>
>> The current 2 version is 2.0.29.
>>
>> However I'm also wondering whether you hit a bug, or rather a problem.
>> The page tree has several levels so if you use the "classic" incremental
>> save then there is no direct path from the catalog to the page.
>>
>> Tilman
>>
>> On 30.10.2023 13:57, Frédéric Ravetier wrote:
>>> Hi,
>>>
>>> I am using the same code and PDFbox2 to add annotations on PDF.
>>> The annotations are not displayed and I think they are not in the final
>> PDF
>>> when I am using one specific PDF.
>>> This is the PDF :
>>>
>> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
>>> This is the PDF where I added annotation and save using incrementalSave :
>>>
>> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
>>> Do you have any ideas ? Do you need more information ?
>>>
>>> Best regards,
>>> Fred
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail:users-help@pdfbox.apache.org
>>
>>

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Frédéric Ravetier <fr...@vikta.com>.
Thanks for your answer Tilman,

* I was using 2.0.29
* this code is working well with all the pdf I used until now
* I did a test using pdfbox3 and it works but my code using pdf3 is not
production ready :(

I prepare a test class that you can use
https://drive.google.com/file/d/1Nqkck4VZXZXjFxEY9XlvVNuF-SOrKH6S/view?usp=sharing
It uses another PDF that I shared with you :
https://drive.google.com/file/d/1G66GxpbxWuETGmO9DM6m8Y-EZlTw_I1h/view?usp=sharing

You need to place both PDF into testfiles/input/

testB is using a PDF where it works
testC is using the PDF I shared before where it does not work.

Fred

Le lun. 30 oct. 2023 à 19:12, Tilman Hausherr <TH...@t-online.de> a
écrit :

> Hi,
>
> The annotations are missing in the incremental part. My guess is that
> you didn't include it in the update. You've updated the document catalog
> but not the page. Read the javadoc of the saveIncremental() carefully.
> If you can't get it to work, please share the smallest possible code
> that reproduces the effect.
>
> The current 2 version is 2.0.29.
>
> However I'm also wondering whether you hit a bug, or rather a problem.
> The page tree has several levels so if you use the "classic" incremental
> save then there is no direct path from the catalog to the page.
>
> Tilman
>
> On 30.10.2023 13:57, Frédéric Ravetier wrote:
> > Hi,
> >
> > I am using the same code and PDFbox2 to add annotations on PDF.
> > The annotations are not displayed and I think they are not in the final
> PDF
> > when I am using one specific PDF.
> > This is the PDF :
> >
> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
> >
> > This is the PDF where I added annotation and save using incrementalSave :
> >
> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
> >
> > Do you have any ideas ? Do you need more information ?
> >
> > Best regards,
> > Fred
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: Annotations + incrementalSave + specific PDF (pdfbox2) = no annotation displayed

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

The annotations are missing in the incremental part. My guess is that 
you didn't include it in the update. You've updated the document catalog 
but not the page. Read the javadoc of the saveIncremental() carefully. 
If you can't get it to work, please share the smallest possible code 
that reproduces the effect.

The current 2 version is 2.0.29.

However I'm also wondering whether you hit a bug, or rather a problem. 
The page tree has several levels so if you use the "classic" incremental 
save then there is no direct path from the catalog to the page.

Tilman

On 30.10.2023 13:57, Frédéric Ravetier wrote:
> Hi,
>
> I am using the same code and PDFbox2 to add annotations on PDF.
> The annotations are not displayed and I think they are not in the final PDF
> when I am using one specific PDF.
> This is the PDF :
> https://drive.google.com/file/d/1iyPlWZkU9SgPjUCCCI5_A190xAz8b4-5/view?usp=sharing
>
> This is the PDF where I added annotation and save using incrementalSave :
> https://drive.google.com/file/d/1jlkknjPtbofGuTqj4urLWfXjZt9CjH0d/view?usp=sharing
>
> Do you have any ideas ? Do you need more information ?
>
> Best regards,
> Fred
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org