6 ms·
The PDF spec is officially available here: http://www.adobe.com/go/pdfreference http://www.adobe.com/go/pdfreference There’s also this book which provides a go
by layer8 5y ago
The PDF spec is officially available here: http://www.adobe.com/go/pdfreference http://www.adobe.com/go/pdfreference
There’s also this book which provides a good introduction and overview and is useful for understanding how the format works (although the PDF reference itself is pretty decent too, as far as specs go): https://www.oreilly.com/library/view/developing-with-pdf/9781449327903/ https://www.oreilly.com/library/view/developing-with-pdf/978...
(You can find a PDF copy if you look around.)
EDIT: There’s also https://www.oreilly.com/library/view/pdf-explained/9781449321581/ https://www.oreilly.com/library/view/pdf-explained/978144932... which might be even better.
However, be warned that the PDF format can be quite complex and is not exactly for the faint of heart. It’s best to use an established library to generate PDF output, like PDFBox, iText, PDFSharp, PDFKit, etc. Those tend to have their own tutorials.
For emphasis: Do not generate PDFs “by hand”! You risk inadvertently generating PDFs that do not fully conform to the spec, and not noticing it because PDF readers are quite lenient in what they accept. A lot of PDFs in the wild are not standard-conforming in some way or other, because their generators were not carefully written against the spec, but against “whatever Acrobat Reader accepts”. This is the bane of every software on the receiving end that needs to process PDFs.
- userbinator 5y agoI've always found it amusing from a "bootstrapping" perspective that the PDF spec is itself a PDF. That said, if you're only writing and not reading existing ones, it's as straightforward or as complex as you want to make it. I wrote a little program many years ago to convert plaintext to PDF in <1kLoC of C --- and its output was actually often many times smaller than what the commercial PDF-generators do, because I just used the defaults and bare-minimum necessary. I wrote it after being confronted with a requirement to use PDF, and the output of contemporary generators seemed rather bloated in comparison. The spec has an example of a bare-minimum; it's quite easy to programmatically generate.
- WalterBright 5y agoPlease make your code available on github!
- whitten 5y agoThe plain text to PDF is easy if you use defaults for the font, and how many words and characters are per line, exclude control characters, exclude Unicode, most of the fancy stuff like letterheads, or such.
- gettalong 5y agoJust make sure that you follow the spec. Many such programs actually leave out mandatory parts of some objects, making the whole PDF invalid.
- arinlen 5y ago> The PDF spec is officially available here I'm afraid that's the old 2008 spec, which specifies versions up to PDF 1.7. The current standard is ISO 32000-2, released in 2020, which specifies PDF-2.0. I'd love to get my hands on it, but alas it's paywalled.
- layer8 5y agoPDF 2.0 isn’t very relevant currently, because there’s not a lot of software yet that fully supports it. On the other hand, there also hasn’t changed all that much since PDF 1.7. In any case, for generating PDFs it’s best to stick with 1.7 (or earlier) for the time being. This page lists the major changes: https://www.loc.gov/preservation/digital/formats/fdd/fdd000474.shtml https://www.loc.gov/preservation/digital/formats/fdd/fdd0004... The FDIS of PDF 2.0 is available here for those who are curious: https://cdn.standards.iteh.ai/samples/75839/ad216d84afd34f968b9207e13c4623f9/ISO-FDIS-32000-2.pdf https://cdn.standards.iteh.ai/samples/75839/ad216d84afd34f96... I don’t know if there are any significant changes between the FDIS and the published version, but it’s better to assume there may be some.
- shawnfrostx 5y agoThank you for the books and the suggestions. I understand the warnings since I did not really provide any information on my project in the post. Essentially, I am writing a batteries included language to act as a replacement for LaTeX (or at the moment, a small subset of it). I cannot use any existing library since they do not work for my own PL and I do not want to go through PostScript -> PDF since the reason I started this project was because the time delay between saving a .tex file and seeing the output on my pdf reader was becoming very long.
- layer8 5y agoThat’s fine, and I actually applaud avoiding complex dependencies like LaTeX/PostScript. Using a good PDF library might still make sense for your use case, as they generally provide enough low-level support. In particular for handling the COS object system, which you really don’t want to do by hand if you can avoid it. Or you can at least start with using a library to get familiar with the higher-level PDF peculiarities, and only switch to fully hand-written output later when and if you find that necessary.
- shawnfrostx 5y agoOk! I will look into those libraries. Thanks a lot.
- xigoi 5y agoWhy not make it compile to HTML instead? It's much more accessible.
- gettalong 5y agoWhich programming language are you using to write your LaTeX replacement? There are PDF libraries available in most languages (granted, there is wide spectrum of them with respect to how much/good they implement the PDF specification).
- kragen 5y agoIt's certainly true that there are a lot of PDF renderers out there with subtle incompatibilities (and bugs), and also a lot of PDF files with subtle nonconformances. However, that doesn't seem like a good reason to not write a new PDF generator! Instead, write a conformant one. Better, write one that not only conforms, but also isn't affected by any of the bugs in popular PDF renderers, by testing against all of them. Shawn Davis at LevelUp Research, working on the same DARPA project I'm currently on, has written the amazing SPARCLUR https://youtu.be/6I6E1N3CJzQ https://youtu.be/6I6E1N3CJzQ (no sound) https://github.com/levelupresearch/sparclur https://github.com/levelupresearch/sparclur https://pypi.org/project/sparclur/ https://pypi.org/project/sparclur/ which will feed your test PDF to Ghostscript, MuPDF, PDFium, PDFMiner, Poppler, QPDF, Xpdf, and some other PDF engines, and compare the results. That way you can see not only if any of them produce errors and warnings, but also if they render it differently or extract different text from it. SPARCLUR is Apache-licensed, written in Python, and very well integrated with Jupyter. (We've developed some other tools for this as well, but they're not as accessible.) SPARCLUR doesn't test your PDF against Adobe's implementation, or for that matter Foxit, and I don't remember why. But basically if you're going to generate PDF files you might as well feed them to SPARCLUR's Spotlight and automatically verify that they work identically, or near enough, in half a dozen independently implemented PDF renderers. Hopefully SPARCLUR will dramatically improve the software quality and compatibility of future PDF generators.
- zinekeller 5y ago> against Adobe's implementation Hard to automate, Windows, macOS and Linux versions have differences > Foxit No Linux version, even harder automation than Adobe's
- kragen 5y agoYeah, that would explain it.
- layer8 5y agoThat’s just a sanity check though, not an actual conformance test.
- aidos 5y agoThe spec is pretty amazing and very readable, for anyone wondering if they should look into it. My top tip for understanding PDFs is to take one that you have a decompress it then open with a text editor. mutool clean -d in.pdf out.pdf What you'll find is very approachable for a developer. It's a tree of nodes of different types. Some are dictionaries, some are streams of other data. All of them are documented in the spec. There's all sorts of wonderful corners, like spot printing colors. PDFs are actually ok, wait till you dig into the fonts. Now there's the real dark art of the ancients.
- the_only_law 5y ago> The PDF spec is officially available here: When did this happen? I swear some years ago I looked and it was a $300 standard?
- layer8 5y agoThe ISO version costs money, but the virtually identical Adobe version is available freely. I believe that has been the case since at least when version 1.7 was published in 2008.
- raxxorraxor 5y ago> Do not generate PDFs “by hand”! You risk inadvertently generating PDFs that do not fully conform to the spec, and not noticing it because PDF readers are quite lenient in what they accept. We have that with websites too. Sometimes it is even hard to spot an error like a missing tag because browsers just assume (often correctly) that it was missing in the first place. But yes, probably also a reason nobody wants to write new browser engines.
- CrimsonCape 5y agoI think Skia's PDF render support isn't fully compliant with the specification, and that's a Google product with dozens of Google engineers working on it. Can you comply with a subsection of the specification? I guess my point is that nobody will care to create an app with attention to the hundreds/thousands of programming tasks required for full compliance with a 600 page specification...