parallax/jsPDF

Support hyperlinks in html()

Open

#3,146 opened on 2021年4月21日

GitHub で見る
 (10 comments) (3 reactions) (0 assignees)JavaScript (4,596 forks)batch import
Feature Requestdifficulty:hardhelp wanted

Repository metrics

Stars
 (28,280 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

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.

コントリビューターガイド