[
https://issues.apache.org/jira/browse/PDFBOX-2786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14527972#comment-14527972
]
Tilman Hausherr edited comment on PDFBOX-2786 at 5/5/15 6:00 AM:
-----------------------------------------------------------------
Oh-oh, it gets more complex... a look at the source code shows this:
{code}
public int getPageNumber()
{
int retval = -1;
if( array.size() > 0 )
{
COSBase page = array.getObject( 0 );
if( page instanceof COSNumber )
{
retval = ((COSNumber)page).intValue();
}
}
return retval;
}
{code}
and this:
{code}
public int findPageNumber()
{
int retval = -1;
if( array.size() > 0 )
{
COSBase page = array.getObject( 0 );
if( page instanceof COSNumber )
{
retval = ((COSNumber)page).intValue();
}
else if (page instanceof COSDictionary)
{
COSBase parent = page;
while (((COSDictionary)
parent).getDictionaryObject(COSName.PARENT, COSName.P) != null)
{
parent = ((COSDictionary)
parent).getDictionaryObject(COSName.PARENT, COSName.P);
}
// now parent is the pages node
PDPageTree pages = new PDPageTree((COSDictionary) parent);
return pages.indexOf(new PDPage((COSDictionary) page)) + 1;
}
}
return retval;
}
{code}
So the first method is 0-based, the second one (introduced in PDFBOX-558 by
[~wulf]) is 1-based when the page is local (i.e. from an object), and 0-based
if the page is remote (i.e. explicit).
was (Author: tilman):
Oh-oh, it gets more complex... a look at the source code shows this:
{code}
public int getPageNumber()
{
int retval = -1;
if( array.size() > 0 )
{
COSBase page = array.getObject( 0 );
if( page instanceof COSNumber )
{
retval = ((COSNumber)page).intValue();
}
}
return retval;
}
{code}
and this:
{code}
public int findPageNumber()
{
int retval = -1;
if( array.size() > 0 )
{
COSBase page = array.getObject( 0 );
if( page instanceof COSNumber )
{
retval = ((COSNumber)page).intValue();
}
else if (page instanceof COSDictionary)
{
COSBase parent = page;
while (((COSDictionary)
parent).getDictionaryObject(COSName.PARENT, COSName.P) != null)
{
parent = ((COSDictionary)
parent).getDictionaryObject(COSName.PARENT, COSName.P);
}
// now parent is the pages node
PDPageTree pages = new PDPageTree((COSDictionary) parent);
return pages.indexOf(new PDPage((COSDictionary) page)) + 1;
}
}
return retval;
}
{code}
So the first method is 0-based, the second one (introduced in PDFBOX-558 by
[~wulf]) is 1-based :-(
> PDPageDestination page index off by one
> ---------------------------------------
>
> Key: PDFBOX-2786
> URL: https://issues.apache.org/jira/browse/PDFBOX-2786
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 1.8.9, 2.0.0
> Reporter: Johanneke Lamberink
> Attachments: Archive.zip
>
>
> When creating a new bookmark with the same page number as an existing
> bookmark, the resulting destination is offset by 1 compared to the old
> destination.
> This results in the bookmark being set for the next page, which could be a
> non-existing page.
> I've added a class with an example pdf and my own output pdf. Run with
> argument of a path to where you have the pdf, including a trailing slash.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]