typemytype / drawbot

http://www.drawbot.com
Other
393 stars 61 forks source link

Internal Links on PDFs generated with DrawBot behave differently on Preview+Safari compared to Acrobat Reader #535

Closed roberto-arista closed 1 year ago

roberto-arista commented 1 year ago

Hey all!

Steps to reproduce:

Preview seems to get it wrong. Try the yellow and orange square. They both lead to the last page. Instead on Acrobat Reader they lead to two different pages.

justvanrossum commented 1 year ago

Can you create such a document in another way, and demonstrate that both Preview and Reader get it right? This to exclude the possibility the bug is in Preview rather than with DrawBot.

roberto-arista commented 1 year ago

I'll try to make something with indesign tomorrow

roberto-arista commented 1 year ago

I've generated this document with InDesign.

test_links.pdf

The links behave in the same way both in Preview and InDesign. So I guess it's a DrawBot bug.

typemytype commented 1 year ago

there isnt that much info:

and DrawBot sets this in the pdf context here: https://github.com/typemytype/drawbot/blob/master/drawBot/context/pdfContext.py#L403-L410

typemytype commented 1 year ago

if you change the script to make the destination points be more visible it makes more sense...

# a variable with the amount of pages we want
totalPages = 10
# create the first page with a index
newPage()
# set a font size
fontSize(30)
# start a loop over all wanted pages 
for i in range(totalPages):
    # set a random fill color
    fill(i/(totalPages-1), .5, i/(totalPages-1))
    # draw a rectangle
    rect(10, 50 * i, 50, 50)
    fill(1)
    textBox(f"{i}", (10, 50 * i, 50, 50))
    # add a clickable link rectangle with a unique name
    linkRect(f"beginPage_{i}", (10, 10 + 50 * i, 50, 50))

# start a loop over all wanted pages
for i in range(totalPages):
    # create a new page
    newPage()
    fontSize(200)
    text(f"Page {i}", (30, 30))
    # add a link destination with a given name
    # the name must refer to a linkRect name
    oval(width()/2-10, height()/2-10, 20, 20)
    linkDestination(f"beginPage_{i}", (width()/2, height()/2))
roberto-arista commented 1 year ago

Apparently Preview does not get it wrong. When in continuous scroll mode (⌘1) the view jumps immediately after the linkDestination location. If in Single Page Mode (⌘2) it shows the correct one. So I think we can close the issue. Sorry for the trouble.

I'll take this opportunity to update the example script with what @typemytype posted here.