Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am making a simple react application for pdf generation.

Libraries used:

-> jspdf

-> html2canvas

index.js

JSX:

<div className="App">
  <button onClick={exportToPdf}>Export</button>
  <div id="toRender">
   ------ Pdf print content ------
  <div>
</div>

PDF Export function:

  const exportToPdf = () => {
    let elem = document.getElementById("toRender");
    elem.scrollIntoView();
    h2c(elem).then((canvas) => {

    ---- Logic for exporting pdf ---

    })
  }

For complete code please refer the below working snippet.

Edit generate pdf with jspdf (forked)

Issue:

The issue is that if we click on export button, then the pdf gets downloaded but we are unable to select the text from the pdf .

I could understand the reason, that it happens because we are using addImage() in this line,

  pdf.addImage(img, "PNG", 0);

But while searching for the related issues here https://github.com/MrRio/jsPDF/issues , I couldn't get anything helpful..

Requirement:

Expectation is that the downloaded pdf is currently looks like an image because of which user unable to select any text from pdf and the need is that user should be able to select the text from pdf.

I am okay to implement any other library to make the html to pdf generation with selectable text as well..

Kindly someone please help me to generate pdf with selectable text instead of image for the above given example. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...