I wanted to know how to generate a PDF. I have seen few frameworks across like jsPDF and others but am eager to build up my own framework so as to understand better how to work with PDF and how does the entire concept of pdf works. Please let me know proper place where I can get a head start with the following and can plan out how to start to build a framework. Any suggestions are highly appreciated. Resources are welcomed too.I want to do the entire thing in JavaScript, so please feel free to guide me.
-
Why invent the wheel again when someone else already have done it? If there is a framework which fits our requirements, then use it.paly– paly2011-12-22 07:36:21 +00:00Commented Dec 22, 2011 at 7:36
-
1@paly: Never hurts to 'reinvent the wheel' when you want to learn to build a cart no? He might want to do it for educational purposes?ChrisR– ChrisR2011-12-22 07:39:10 +00:00Commented Dec 22, 2011 at 7:39
-
1@paly I actually want to learn how to do it so that I can implement it better and increase my knowledge upon the same. I am really not aware hoe the PDF generators work and am really keen to know about it. I guess reinventing helps ;)Shiv Kumar Ganesh– Shiv Kumar Ganesh2011-12-22 07:43:02 +00:00Commented Dec 22, 2011 at 7:43
-
1@Shiv Kumar Ganesh: Then carry on if you want to learn something new, I like own implementation, but I have to decide what reinvent and what not. Good luck ;)paly– paly2011-12-22 07:49:14 +00:00Commented Dec 22, 2011 at 7:49
-
@Shiv Kumar Ganesh what progress have you done on this matter? I want to do the same thing, implement a PDF library for my favorite front end programming language called elm. Because currently, there is no way to create PDF documents from elm directly. I don't know where to start, i can't understand what the main idea behind PDF is. How JavaScript is actually transformed in PDF? With inspect element, the pdf appears as composed from a bunch of divs. This can'tberight. What is the actual underlining language behind pdf? Can you please tell me what should i do in my current situation? Thanks :)AIon– AIon2017-05-01 20:22:13 +00:00Commented May 1, 2017 at 20:22
2 Answers
The very first thing you need to do is make yourself familiar with the PDF standard - see http://www.adobe.com/devnet/pdf.html and http://www.adobe.com/devnet/pdf/pdf_reference.html .
Then you need to decide if you want to implement the full standard, parts of it, a renderer and/or generator etc.
After that you should concentrate on studying any opensource framework which implements what you are after...
Then start coding... and come back with any specific questions as they arise.
4 Comments
If you want to build a framework because you think there isn't a library for this, you should check jsPDF. It's a javascript library for PDF generation.
http://code.google.com/p/jspdf/
I've not used it in a large project, but it's very easy to use.
From the demo (http://snapshotmedia.co.uk/blog/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.addPage();
doc.text(20, 20, 'Do you like that?');
// Output as Data URI
doc.output('datauri');