8 ms·
Minimal PDF
- ad_hominem 9y agoI've encountered .pdf files which internally embed a proprietary Adobe extension called XFA[1]. I think they are created using Adobe's LiveCycle product. They are a real pain because they render fine in Adobe Acrobat, but most other PDF renderers (including browser built-in ones) can't render them. Instead they render a blob of interstitial "loading..." text that is also embedded in the PDF (which the XFA rendering would then overwrite). It was a pain to me personally because I had to figure out a way to do programmatic form-filling of some fillable form XFAs, and most PDF libraries don't work with them (they expect traditional AcroForms fillable forms). But in reading the XFA specification I found it interesting it had its own JavaScript interpreter (including supporting XHR requests as part of some internet-integrated form-filling feature) and another proprietary scripting language called FormCalc. I guess it opened my eyes to PDFs being a container format and the kinds of things they allow you to embed. [1]: https://en.wikipedia.org/wiki/XFA https://en.wikipedia.org/wiki/XFA
- userbinator 9y agoThat's unfortunate. I guess the same thing that happened to HTML pages (turning into less accessible JS-based SPAs) is now happening to PDFs.
- cmurf 9y agoI'm frustrated by governments using PDF for full in forms and yet open source tools are very weak in this area. This is not better than paper and pencil, in terms of accessibility. And we need to do better somehow.
- fizixer 9y agoThis is good but Postscript is even better. Someday I'll learn it and see what I can do with it.
- chris_st 9y agoWhen you want to learn it, I recommend the "Blue Book", aka "PostScript Language Tutorial and Cookbook" By Adobe Systems Incorporated. It's a very thin book, but a great tutorial and example reference. I enjoyed going through it, and still occasionally generate PostScript for visualizations.
- protomyth 9y agoVery much worth learning, if for nothing else being an extremely cool stack language. I learned it for my first job that I only had Turbo C 2.0, foxbase, and an HP4 printer with the Postscript module to do graphical reporting on a dataset. chris_st's recommendations are how I learned it.
- pjmlp 9y agoYou lucky guy. I remember going though HP and Epson printer manuals, writing down their control escape codes into a xBase table so that our Clipper application could talk to the printers and do the respective formatiing. Having access to a PS printer would have been a much more positive experience.
- rcarmo 9y agoI used to hand-code Postscript files back when the Apple LaserWriter was launched. I had a little kaleidoscope-like thing that did patterns for Xmas decorations, and once I did a text-to-workflow routine to print out diagrams. It's all gone now (I did part of it on a VAX and part on an SE/30), but it was lots of fun at the time.
- perlgeek 9y agoPostscript is easier to get started with, IMHO. See this example: https://en.wikipedia.org/wiki/PostScript#.22Hello_world.22 https://en.wikipedia.org/wiki/PostScript#.22Hello_world.22 When I was actively play with Sudoku programs, I wrote a bit of code that generated sudoku images in svg, (e)ps and and a few other formats. It was a bit fiddly, but not really complicated.
- j_s 9y agoSee also on the same site: Hand-coded PDF tutorial | https://brendanzagaeski.appspot.com/0005.html https://brendanzagaeski.appspot.com/0005.html If you need more, the "free" (trade for your email) e-book from Syncfusion PDF Succinctly demonstrates manipulation barely one level of abstraction higher (not calculating any offsets manually): https://www.syncfusion.com/resources/techportal/details/ebooks/pdf https://www.syncfusion.com/resources/techportal/details/eboo... "With the help of a utility program called pdftk[1] from PDF Labs, we’ll build a PDF document from scratch, learning how to position elements, select fonts, draw vector graphics, and create interactive tables of contents along the way." [1] https://www.pdflabs.com/tools/pdftk-server/ https://www.pdflabs.com/tools/pdftk-server/
- logicallee 9y ago>If you need more, the "free" (trade for your email) Just a note that Google lets you get a new email address that isn't spammable, through security through obscurity: -> You can use your gmail address, add a + after it, and add a keyword. So if you are jsmith@gmail.com you can give out jsmith+syncfusionpdfsuccintly@gmail.com and then later if that starts getting spammed you can redirect it. NOTE: This is an incorrect solution (Google, please fix this) because anyone can run a regex removing the + part. Instead the correct solution is that if you have gmail open, in a single click you should be able to generate a high-entropy gmail address (that does not deplete the namespace) and link it on your end with "syncfusionpdfsuccintly". If I already have gmail open, 7 seconds to create a new gmail address as follows: 1. Click something to start the process 2. Type "syncfusionpdfsuccintly" to tag it on my end 3. Click something to copy a resulting high-entropy gmail name into the clipboard. I should then be able to paste it into a form, get it delivered straight into my inbox (never spam), and redirect it to spam if it starts getting spammed. This would allow people to contact us without ever getting into spam, while entirely removing their ability to contact us if this email address starts getting spammed. There are no downsides. I believe Google's engineers are smart enough to move from security through obscurity (relying on the knowledge that no spammer can ever invent and run the exact regex s/\+[.]+@/@/g to remove the security through obscurity, as this would entirely break this security, exposing the underlying "protected" email addresses) to something that works. Until that day comes you can rely on the security through obscurity to give out a secure email address that can't be spammed. Just add a + and a tag! Please. Google: I believe you are smart enough to understand this comment and implement this solution, which can be prototyped in 30 minutes and solves the spam problem forever. You can do it! I believe in you. You're 99.999% there and your security through obscurity works very well for me. I use it. I hope you will go above and beyond and solve the remaining 0.001%. It would just make me feel better to know that a 13-character regex couldn't defeat your solution.
- tptacek 9y agoThe biggest complexity (and security) problem with PDF is that it's also effectively an archive format, in which more or less every display file format conceived of before ~2007 can be embedded.
- jahewson 9y agoYeah pretty much. There's JBIG2, JPEG2000, CCITT Fax and Flash to name a few. Oh and a bunch of TIFF stuff without the wrapper. Some good news though: the PDF-A standards define various archive-safe subsets of PDF for which various verification tools exist.
- userbinator 9y agoOn the other hand, PDF is probably the only widespread use of formats like JBIG2 and JPEG2000 --- which are rarely encountered as individual files, unlike JPEG, PNG, or GIF. A lot of the scanned PDF ebooks on archive.org use JPEG2000+JBIG2, and the filesize vs. quality difference compared to more traditional formats like JPEG is quite apparent. They do take a noticeably longer time to render, however...
- izacus 9y ago> They do take a noticeably longer time to render, however... That's mostly due to distinct lack of good JPEG2000 decoding libraries. We're building a PDF renderer library and JPEG2000 is a constant pain int he ass due to it - JPEG decompression is hardware accelerated on many platforms and also has a bunch of SIMD optimized libraries. For JPEG2000 there's practically nothing and due to complexity of the format we count decoding times in seconds for some images even on fast mobile phones.
- userbinator 9y agoI've been playing around a bit with JPEG2000 (slowly learning about the format, trying to write a decoder for it) --- whereas JPEG normally uses Huffman compression for the bitstream, which although not really parallelisable is relatively fast (essentially 1 table lookup per output value), AFAIK the bottleneck in JPEG2000 decoding is the arithmetic compression, which can't be parallelised either, and involves quite a few more operations than Huffman's inner loop.
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]
- mp3geek 9y agoWould be nice if browsers would support saving pages directly as pdf using there own pdf librarys.
- kazinator 9y agoChrome has great HTML to PDF saving, which is in fact all I use it for. My home-brew accounting software generates HTML invoices; I need them in PDF also, though.
- mp3geek 9y agoSave page as? Note, I'm not refering to print to pdf here.
- Dylan16807 9y agoWhat's the difference?
- tempay 9y agoPrinting tries to reformat the page to fit on some paper size and often removes details such as the background. Often it would be nice to make a PDF that shows a screenshot of the full current page, extensions exist for this but ntjifn natively.
- kazinator 9y agoWhy PDF then; it could be saved as a PNG, which an ImageMagick one-liner can turn into a PDF (or several of them into a multi-pager). It would be good if a way was available for any application to take a full window screenshot, rather than the viewport screenshot.
- izacus 9y agoPNG is an image format which is usually significantly larger than the corresponding PDF document and rendered at fixed quality. PDF is (mostly) a vector format which can be resized at will.
- kazinator 9y agoPlain text ... but with hard offsets ... encoded as decimal integers. Yikes!
- ilaksh 9y agoPDF is literally the worst possible format for document exchange because it has the most unnecessary complexity of all document formats, which makes it the hardest to access. But popularity and merit are two totally different things.
- abritinthebay 9y agoThat’s unfair. It’s terrible from a technical perspective (due to cruft, mostly) but nothing comes close from a deliverable standpoint. It’s simply the most reliable print-ready format. It is a Portable Document Format in every way that matters to the end user There’s a reason one of the main uses of LaTeX is outputting to PDF
- kingkongjaffa 9y agoCompletely agree, as a dumb user of latex I only care that I can make a document and that it looks the same on every computer or browser or printed out. That solution just happens to be latex, especially since virtually all computers will have some way of viewing and printing pdfs by default.
- abritinthebay 9y agoI really wish there was a better solution to typesetting than LaTeX (well, XeTeX if you’re serious about Unicode & language support I guess, which you should be) I hate it so much, if it wasn’t for its excellent abilities in specific areas (hyphenation, etc) I’d much prefer CSS. Yes, TeX makes me prefer CSS for layout. That’s how painful I find it.
- amenghra 9y agoIf you like this you might enjoy this repo: https://github.com/mathiasbynens/small https://github.com/mathiasbynens/small
- ekr 9y agoSee also klange's resume: https://github.com/klange/resume https://github.com/klange/resume. Resume pdf that's also a valid ISO 9660, bootable toaru OS image.
- userbinator 9y agoLooks like he did it "the hard way" --- and unfortunately it's not a truly valid PDF since the startxref isn't within the last 1KB of the file and the version number in the header is corrupt. Not all PDF readers will accept that. On the other hand, it is possible to make a completely valid PDF and bootable ISO. The first 32KB of an ISO is officially "unused", which is probably why GRUB decided to put itself there, but that can be relocated somewhere else --- the El Torito boot descriptor will need to be updated to point to it --- and the PDF signature (which can be a valid one) and as many objects as will fit can be put in that area, with the rest anywhere else. The xref table can be moved to the very end and the offsets updated to point to the objects.
- Noctem 9y agoThis page was helpful to me a couple years ago while crafting the tiny PDF used for testing in Homebrew. https://github.com/Homebrew/legacy-homebrew/pull/36606 https://github.com/Homebrew/legacy-homebrew/pull/36606
- jimjimjim 9y agoPDF is like c++ it's used everywhere because you can do everything with it. This also leads to the problem where you can do anything with it. so each industry is kind of coming up with their own subset of pdf that applies some restrictions in the hopes of making them verifiable. the downside is that these subsets slowly start bloating until they allow everything anyway. i'm looking at you PDFa. grr.
- aidos 9y agoI've spent much of the last year down in the internals of pdfs. I recommend looking inside a PDF to see what's going on. PDF gets a hard time but once you've figured out the basics, it's actually pretty readable. Some top tips; if you decompress the streams first, you'll get something you can read and edit with a text editor mutool clean -d -i in.pdf out.pdf If you hand mess with the PDF, you can run it through mutool again to fix up the object positions. Text isn't flowed / layed out like HTML. Every glyph is more or less manually positioned. Text is generally done with subset fonts. As a result characters end up being mapped to \1, \2 etc. So you can't normally just search for strings but you can often - though not always easily find the characters from the Unicode map.
- gens 9y agoHere you go, a good talk about pdf. https://media.ccc.de/v/27c3-4221-en-omg_wtf_pdf https://media.ccc.de/v/27c3-4221-en-omg_wtf_pdf
- xyzxyz998 9y agoThat was informative, thank you. I think a lot of people in the dev/power uesr community would mind paying $1 for a Kindle ebook where you note all your findings. There have been so many instances where I wanted to do stuff with pdfs but ended up deflated. > subset fonts So you mean if a font has been embedded with three glyphs, 0x41=A, 0x61=a, 0x62=b, then string Aba would be \1\3\2?
- aidos 9y agoThat's correct. As a sibling has said, there other ways to do it but most the pdfs I need to work with are done by simply remapping in order of occurrence. (E.g., if an X is the first char in the doc, it's referenced as \1). You can tell subset fonts because they're named as RANDPREFIX+fontname so different subset fonts from the same base font won't collide. You can get a good overview of the state of the fonts in your PDF using: pdffonts file.pdf There's a column which tells you if there's s Unicode map available for the font. That's important. Because PDF is just rendering glyphs at positions, it doesn't even know what the character names are. To allow you to copy and paste, most fonts in most pdfs will have a Unicode map from the glyph id to the Unicode symbol. If that's not available, in some cases you can rebuild it yourself by looking at the character encodings and substitutions. On the book, do you have any examples? I'll probably never get around to writing anything down, but if it looks easy enough it's probably worth having a stab at. Also, large caveat, I'm not a PDF or font expert. I've probably decimated the terminology here but hopefully it gives you a rough idea.
- eru 9y ago> Most PDF files do not look readable in a text editor. Compression, encryption, and embedded images are largely to blame. After removing these three components, one can more easily see that PDF is a human-readable document description language. Of course, PDF is intentionally so weird: it was a move by Adobe because other companies were getting too good at handling postscript. Embedding custom compression inside your format is seldom worth it: .ps.gz is usually smaller than pdf.