5 ms·
Bless the heart of whoever looked at the PDF spec and said to themselves, "Nice, I'd like to writer a parser for this."
by user3939382 3y ago
Bless the heart of whoever looked at the PDF spec and said to themselves, "Nice, I'd like to writer a parser for this."
- hu3 3y agoNo joke. Yesterday I found out PDFs can have forms with JavaScript. https://tcpdf.org/examples/example_014/ https://tcpdf.org/examples/example_014/ How does this even work?
- lost_tourist 3y agobecause some viewers have built in javascript interpreters. In the pdf it's just text labelled as a script
- viraptor 3y agoI hope I can amuse you further: PDF embedded 3d models https://helpx.adobe.com/mt/acrobat/using/displaying-3d-models-pdfs.html https://helpx.adobe.com/mt/acrobat/using/displaying-3d-model... and interaction https://www.astrobetter.com/blog/2012/03/07/tutorial-for-embedding-3d-interactive-graphics-into-pdf/ https://www.astrobetter.com/blog/2012/03/07/tutorial-for-emb... You can also do animated page transitions like PowerPoint, but I don't have the right link available...
- hu3 3y agoYou did amuse me! Thanks! To me this is the kind of scope creep that causes a "simple" PDF renderer department to end up with 50 devs working in it full-time. I wonder... can a PDF have an iframe that opens itself? Causing an infinie loop of it loading itself?
- MilStdJunkie 3y agoPlease please don't mention 3d pdfs. Please. I had to implement this. 3d manipulation in a block inside of a print format that might make deliverables in the hundreds of gigs. It's . . it's one of the dumbest functional requirements I've ever seen, and the fact it exists. . I'm sorry, I have to go be by myself for a while.
- somat 3y agoThe stupidest part of the whole thing is that pdf is basically a neutered postscript. The problem with postscript as a document format, is that there is no good way to do metadata, jump to a specific page, count pages, etc. So pdf uses the rendering engine of postscript with all that annoying turing complete behavior torn out. Then at some point they wanted some computational capability in the document[1], but instead of reintroducing postscript into the mix they went with a third language, a wierd poorly designed one invent for browser scripting. 1. Yes we all know how stupid this was. but they wanted fillable forms and validating those forms made sense at the time. Really it was because they were trying to compete with the web.
- baal80spam 3y agoI remember someone wrote a game in a PDF document...
- temny 3y agoI think this is it: https://github.com/osnr/horrifying-pdf-experiments https://github.com/osnr/horrifying-pdf-experiments
- jimjimjim 3y agobadly
- viraptor 3y agoEven once you have a parser itself, actually figuring out what to display and where is... interesting. Especially in generated rather than hand-created documents. What's the element's position? Grab your math library, we're multiplying matrices! What does this text say? Let's write another parser for the table of very custom codepoints!
- VMG 3y agomapping coordinates via projection matrices pretty common tbh
- viraptor 3y agoIf you change/transform then on the fly - sure. If they're on a final, not-designed-as-editable format... Not that common. I don't really see any reason (beyond PS origins and its historical usage) for PDFs to not flatten the final positions/sizes.
- grishka 3y ago...in a memory-unsafe language!
- isatty 3y agoWhy is this comment under every post? Low quality bait.
- mkl 3y agoI think writing a parser for in-spec PDF files probably isn't too hard (though writing a complete renderer and interface certainly is), but many PDF files don't match the spec, so your parser has to be tolerant of invalid PDF files, because Adobe's is.
- izacus 3y agoHaving done that, PDF spec is in many ways much saner and better designed than plenty of "APIs" modern JS jockeys create. The original spec is a bit ugly because they were saving bytes in the format (using things like single letters for dictionary keys), but some things are actually quite well thought out (Appearance Streams are great for forward and backward compatibility and are probably no. 1 reason why nothing managed to replace PDF.)
- wolverine876 3y ago> Appearance Streams are great for forward and backward compatibility and are probably no. 1 reason why nothing managed to replace PDF. I've been wondering why they took that approach. Do you know their original reasoning? And how does it help compatibility?
- kjksf 3y ago(I wrote SumatraPDF). In fairness, I didn't write the PDF rendering. That is indeed quite a tall order. I used to use poppler and switched to mupdf (was more active at the time, poppler seems to have picked up pace since). The core PDF feature set isn't that bad to implement. From what I've seen, the bad / complex parts are: - stuff they added years later, like some XML stuff (of course you had to add XML in 2000!), JavaScript in forms - some more complex vector graphics features like masking with vectors, support for bunch of color spaces, cmyk separation - font handling, text rendering is surprisingly complex - rendering fast even if PDF was badly created - PDF is easy to screw up when you create it and boy, do people screw up in every imaginable way. You can't just say "it's bad PDF" when Adobe or Chrome opens it so a lot of effort by mupdf devs is adding heuristics to show even broken PDF docs
- omginternets 3y agoWhen I bought my first computer in 2005, I discovered SumatraPDF and good lord it was miles better than the bloated alternatives. In particular, it was lighter and faster than everything else, which for someone like me who had to buy used hardware, was a godsend. So thanks for that!
- user3939382 3y agoThat's an awesome insight that was clearly hard-earned. SumatraPDF is awesome, thank you very much for all your hard work on it.