loading...

How to Make a PDF File🤔🤔

aadityajha2004 profile image Aaditya ・1 min read

Just curious to know how can I generate a pdf file programmatically. I mean I know there are libraries in most of the programming languages to do so but I want to do it from scratch just like creating a text file. Open file.txt, write the data and close the file. But I guess, I can't do something like open a file.pdf, write data to it and then close the file. So How can I do it without any third party libraries.

Discussion

pic
Editor guide
Collapse
serhatteker profile image
Serhat Teker

Everything was fine till 'without any third party library'. Why the restriction?

I personally prefer using Pandoc.

"Pandoc is a free and open-source document converter, widely used as a writing tool and as a basis for publishing workflows."

Usage is as simple as that:

pandoc file.txt -o file.pdf
Collapse
dealloc profile image
Wannes Gennar

If you want to create a PDF file from scratch I'd recommend starting with reading the specification (tools.ietf.org/html/rfc7995 for example), learn how the format is structured and then you can write the code that generates that structure from arbitrary data

Collapse
aadityajha2004 profile image
Aaditya Author

I thought about it but it is almost like a never ending manual and I hate reading manuals (of course because I don't get it😅😅)

Collapse
dealloc profile image
Wannes Gennar

Reading RFC may seem daunting at first, but they're written in a very concise and clear way (since you shouldn't be able to misinterpret them).
Unless you find an article which breaks it down in simpler terms you're stuck reading RFC I'm afraid ;)

Collapse
serkzex profile image
Mujtaba Aldebes

Unless you want to develop your own tool, then you could use LATEX (sharelatex.com/). Your code your own text and then save it into a .pdf format.

Collapse
axiol profile image
Arnaud Delante

Our go to solution for that is wkhtmltopdf. You need to know HTML and CSS for that, but otherwise, it's pretty straightforward to use

Collapse
stokry profile image
Stokry

I don't know without any library, but you can do with, # FPDF library for PDF document generation in Python.