0

I am developing a web application using JavaScript. in a certain case i want to extract the contents inside a div element and paste it to the pdf file when i click the link "download to pdf".

I received some answers regarding this by using jsPDF lib, but is there any other way without using jsPDF? jsPDF is not supporting such things

    <div id="panel">
      //some codes 
      <a href=javascript:downloadPDF();>Download to PDF</a>
    </div>

    <script>
     function downloadPDF()
     {
      what to write here to convert to PDF
     }
    </script>
CharlesB
  • 86,532
  • 28
  • 194
  • 218
Ree
  • 141
  • 1
  • 4
  • 15

2 Answers2

0

You can use jsPDF .jsPDF is an open-source library for generating PDF documents using nothing but Javascript.

http://jspdf.com/

https://code.google.com/p/jspdf/

psu
  • 379
  • 1
  • 5
  • 15
0

It can be done, but it's not a 10-line exercise.

The most compatible way to do it is to take the content you want to put in the PDF, send it to the server, and use any of several good libraries server-side to generate the PDF (in Java one option is iText, in .Net there's the excellent port of it, iTextSharp; there's a PHP module for doing PDF as well).

There's a JavaScript library called jspdf that can be used to generate PDFs in JavaScript, either server-side via NodeJS or similar, or to generate data: URIs on some browsers.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • i downloaded jsPDF zip file ... what to do next ? am new to javascript ... so pls guide me dude – Ree Mar 05 '13 at 12:37
  • 1
    @user2094950: What to do next? Work through JavaScript tutorials, work through the tutorials on the jsPDF website, make sure you're okay with the limitations (particular wrt browser support)... – T.J. Crowder Mar 05 '13 at 12:39