Links in wrong position with a certain PDF

Discuss PDF file handling with the Polybios plugin here
Post Reply
User avatar
jPV
Posts: 260
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Links in wrong position with a certain PDF

Post by jPV » Sat Jul 13, 2019 12:57 pm

I came up with this one PDF file, which gives links in slightly wrong positions with Polybios, but they seem to be in correct positions, for example, with VPDF. So is there something wrong in Polybios regarding this?

Here's the file: kamera.pdf

This code draws the boxes where the links are... they are about half of their size in wrong positions.

Code: Select all

@REQUIRE "polybios", {Version=1, Revision=1}
pdf.OpenDocument(1, "kamera.pdf")
id, t = pdf.GetBrush(1, 5, 1, False, True)
ChangeDisplaySize(GetAttribute(#BRUSH,1,#ATTRWIDTH), GetAttribute(#BRUSH,1,#ATTRHEIGHT))
DisplayBrush(1,0,0)
DebugPrint(ListItems(t))
For Local i=0 To ListItems(t)-1
    Box(t[i].left, GetAttribute(#BRUSH,1,#ATTRHEIGHT)-t[i].top, t[i].right-t[i].left, t[i].top-t[i].bottom)
Next
WaitLeftMouse() 

User avatar
airsoftsoftwair
Posts: 3065
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Links in wrong position with a certain PDF

Post by airsoftsoftwair » Thu Jul 18, 2019 9:48 pm

Ok, so this is because the PDF in question defines a crop box and the coordinates returned by pdf.GetPageLinks() are relative to the crop box. I've now added two new functions to get a page's crop box and media box:

Code: Select all

- New: Added pdf.GetMediaBox() to get a page's media box and pdf.GetCropBox() to get a page's crop box
I've also added another function which might be the best choice to deal with all this stuff: pdf.PageToDevice(). This can be used to convert from page to device coordinates. It automatically takes the crop box into account and it will also convert the coordinates to Hollywood's top-left origin device space. So just using pdf.PageToDevice() on the coordinates you get from pdf.GetPageLinks() is probably the best and easiest choice.

Code: Select all

- New: Added pdf.PageToDevice() function and pdf.DeviceToPage(); these can be used to convert coordinates
  from page to device space and vice versa

Post Reply