parallax/jsPDF

Support hyperlinks in html()

Open

#3.146 geöffnet am 21. Apr. 2021

Auf GitHub ansehen
 (10 Kommentare) (3 Reaktionen) (0 zugewiesene Personen)JavaScript (4.596 Forks)batch import
Feature Requestdifficulty:hardhelp wanted

Repository-Metriken

Stars
 (28.280 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

I'm running jsPDF 2.3.1 to render PDFs from HTML. I am able to generate PDF files, but hyperlinks are not always rendering correctly.

Here are two examples:

<a href="https://github.com">https://github.com</a>

<a href="https://github.com">GitHub</a>

The first example generates a clickable link in the PDF (good), while the second example just colors the text blue with no hyperlinking (bad).

Here's the code I'm using to generate this:

const doc = new jsPDF('portrait', 'pt', 'letter');
const fullDocBody = '<a href="https://github.com">GitHub</a>'; 
doc.html(fullDocBody, {
  // Callback function is called when html conversion to PDF completes
  callback: function (doc) {
    doc.save('test.pdf');   // Saves to a file
  },
  x: 60,
  y: 60
 });

Changing fullDocBody to one of the two link strings shown above will demonstrate the behavior I am describing.

My application needs to accept either link type, as it is taking HTML from a rich text editor component to render the PDF.

Thanks for your time.

Contributor Guide