Links in wrong position with a certain PDF

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

Links in wrong position with a certain PDF

Post by jPV »

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))
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)

User avatar
Posts: 4667
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany

Re: Links in wrong position with a certain PDF

Post by airsoftsoftwair »

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