Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

javascript - Unable to select text from pdf

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

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...