1

This is a little bit of a different request regarding PDFs. I don't want to use a 3rd party library to create PDFs I want to create a PDF writer like iTextSharp in order to create PDFs from any data source. In essence I want to create my OWN PDF Tools.

This is not a requirement to convert existing documents to PDF (I already know how to use the word interop to do that and I have experience with iTextSharp).

What I am really struggling to find information on is how would I create PDFs from scratch ? There is very little to no information that I can find in my searches on what you need to do in order to create a PDF.

I have read through the PDF standards: https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf

I understand the formatting requirements that all PDFs need to adhere to in order to work with PDF readers like Acrobat and FoxPDF but the standards are obviously technology independent and only work as a guide line.

So what I am asking I guess is for a little bit of guidance on starting this project. I am specifically looking for tutorials that pertain to C# (.NET or Mondo) or even just a few lines to point me in the right direction.

Kind regards, Helgard Wagener

HWagener
  • 21
  • 1
  • 1
    I can recommend jsreport. It is a open-source library to create PDF files. You can check it out to have "some" knowledge about what you want to do. The link page: https://github.com/jsreport/jsreport-core – Lewis86 Oct 29 '18 at 10:21
  • If you really want to create your own PDF generation code (i.e. just-another-PDF-library) and you already know there are open source PDF generators (iText, PDF Clown, ...), why not simply looking at their code? As an aside, implementing a PDF generator supporting the larger part of the PDF format will require quite a lot of work. If you instead want only something very very simple, you can start from the code in [this answer](https://stackoverflow.com/a/25244100/1729265), a very simple Java (easy to port) PDF generator supporting only a minute part of the PDF features, but a start at least. – mkl Oct 29 '18 at 15:18
  • Considering your meanwhile deleted answer - which code *was exactly what you were looking for*? We can create a proper answer (instead of a mere comment) you can accept. – mkl Oct 31 '18 at 18:24

1 Answers1

3

One reason you probably haven't found much information on creating your own PDF writer from scratch is because most software developers realize through experience it's usually better not to reinvent the wheel. (Though I recognize that sometimes there are circumstances where you have no choice.)

Technically the specification gives you the information you need to create a PDF that should be readable by most any PDF reader. You'd need to write the header, the body of objects, a cross-reference table, and a trailer for example to make up a basic PDF.

However let me caution you, a PDF file can become enormously complicated and the problems that can occur in writing PDFs that play nice with the rest of the world can be equally complicated.

Reading a file format specification from front to back like a book however is not in my experience helpful, it's more useful as a reference to use after you have a bit of experience. One thing you could do is to use a PDF writer like Acrobat and create a very simple PDF with say "Hello World" text in it and save it to disk and then examine it in your favorite file editor to have a look at the structure and see how the concepts from the specification look in practice, e.g. the trailer, objects in the body, etc.

Then you could start thinking about how to structure you code to build up a simple PDF and piece by piece add your features of interest.

If this is simply an academic exercise more power to you. However if this is for a work project, I'd repeat my refrain from above that you should reach for an existing tool. But as a caveat, there are many players in the PDF space, but they aren't all created equal.

JosephA
  • 1,187
  • 3
  • 13
  • 27
  • Hi JosephA, thanks for the feedback its really appreciated, I know its 8 months down the line but I have made some significant progress, which was ultimately dropped because other libraries like iTextSharp just fit the bill the best. I am sharing this post so that everyone can avoid spending months "reinventing the wheel" – HWagener Jul 21 '19 at 15:38