parallax/jsPDF

Support hyperlinks in html()

Open

#3146 aperta il 21 apr 2021

Vedi su GitHub
 (10 commenti) (3 reazioni) (0 assegnatari)JavaScript (4596 fork)batch import
Feature Requestdifficulty:hardhelp wanted

Metriche repository

Star
 (28.280 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor