1

I made a simple webpage (html) with several JavaScripts, something like a quiz. Users fill in text fields and press buttons for answers and when they click Submit button after which the JavaScrript calculates the score and presents it.

So, my page is index.html, and when user clicks submit, it is still on this page, but it show the results, something like: WELL DONE! Name, id, email etc (get from text fields) Your score is: 144 (this is calculated by JS).

So, now, I want to add a button below this result, that will say for example "PDF". And when user clicks it, it will open in new tab a pdf document with the results on index.html after calculating. And the pdf should be formated like an index.html page.

I was trying to find out how to do this pdf thing, and I couldn't find a solution. The problem is that I want this page to open locally, not on a server. Can you suggest me how to do that, maybe to use PHP (but it won't work locally). I just want to copy paste html file and JavaScripts on whatever computer, and need to work there locally also. Just open in browser and complete quiz, and then export results as pdf.

Thanx

2 Answers 2

1

You can do what you want in javascript, use this library: http://parall.ax/products/jspdf

You have to format the output with the desire format for your pdf

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Does this jspdf library support CSS. I mean, can I format the output the way I like? And does this library supports UTF-8? I tried, but it seems to be a problem with that, doesn't support some letters :(
I think that it does not support CSS but there's some options in the library itself to change font colors and such. It should work with UTF8 because in the main page of the library(where there's an example of an image) if you modify the code (it's next to the pdf window) and enter UTF-8 characters in the title works well so I guess that it should work with UTF-8.I haven't tried all letters so maybe there's some limitations. There's a parameter to set the enconding :mrrio.github.io/jsPDF/doc/symbols/FontObject.html
1

Here is a simple PDF example with jsPDF:

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, 40, 'Do you like that?'); doc.output('save', 'filename.pdf');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script> <iframe id="pdf" type="application/pdf" src="" width="800" height="400"></iframe>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.