2

I am developing an extension for Google Chrome and I'm wanting to generate a PDF with a HTML content stored in a variable of the plugin. I thought about using the same system that the browser uses to generate PDF pages, is it possible? How? Note: I do not want to use a system hosted on a server for it ...

Augusto
  • 193
  • 1
  • 2
  • 15
  • Maybe [**this**](http://stackoverflow.com/questions/742271/generating-pdf-files-with-javascript) will help. – blex Jul 15 '14 at 19:34

1 Answers1

2

In fact, you don't even need an extension to create a PDF. You can use usual JavaScript in a web page (either with a JS library or not)

You can just use base64 encoding to simply load this URL with the PDF data as DATA:

window.location.href="data:application/pdf;base64,DATA"

Otherwise, as blex mentioned, you can use a library like jsPDF to create something more easily; for example:

((new jsPDF()).text(20, 20, 'Hello world.')).save('Test.pdf');

Does that satisfy your need?

Community
  • 1
  • 1
Nir Lanka
  • 379
  • 1
  • 4
  • 13