Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am developing a project, In that I have a receipt page (this is the html page that I want to convert it into pdf) and I've to print it. While printing that page alignments are not coming properly.

If I convert it into pdf, then pdf only will take care of that alignments thus my work will become easy and effective. I was restricted to use either JavaScript or js libraries only to complete this task.

Could any of you please help me?

share|improve this question

closed as off topic by haylem, ChrisF Jun 12 '12 at 8:01

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Belongs to StackOverflow.com? –  haylem Jun 12 '12 at 7:10
This might be helpfull stackoverflow.com/questions/742271/… –  TiredProgrammer Jun 12 '12 at 7:11
Please don't cross post - stackoverflow.com/questions/10975694/… –  ChrisF Jun 12 '12 at 8:01
@ChrisF: :) especially if already asked AND answered yesterday... –  haylem Jun 12 '12 at 8:06
add comment

1 Answer

Use jsPDF to do what you want.

Here's a quick example:

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.text(20, 20, 'Do you like that?');

// Output as Data URI

To generate the content, then you'll need to process your DOM tree and programmatically transcribe to jsPDF calls.

There's also a nice example using jsPDF with Downloadify to produce a downloadable file.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.