foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.92k stars 1.16k forks source link

Enabling encryption prevents destination links from working. #1538

Closed chuckntaylor closed 4 months ago

chuckntaylor commented 4 months ago

Bug Report

Description of the problem

It seems that when a userPassword is set in the config, that destination links stop working.

Code sample

Setting up a new document

const doc = new PDFDocument({
      size: 'LETTER',
      layout: 'landscape',
      margin: 0,
      autoFirstPage: false,
      bufferPages: true,
      info: { Title: bookTitle, Author: '' },
      userPassword: 'somePassword'
    })

  // Then on one of the pages:
  doc.addNamedDestination('LINK');

// Later linking to the other page
doc.text('A goto', 20, 0, {
  goTo: 'LINK',
});

The links work when there is not userPassword set, but fail to work when set.

Your environment

chuckntaylor commented 4 months ago

In the docs I see that pdfVersion defaults to 1.3. Changing this to a later version (I've only tested 1.7ext3 and 1.7) seems to resolve the issue. My suspicion is that the encoding/decoding in 1.3 does something to the destination names. Anyway, gonna mark this as closed.