October 16th, 2005

beartato phd

(no subject)

I hate computers some days.

So I tried following the latest PDF spec to the letter, putting in every required field and shit, and created the following PDF:

http://www.cs.cmu.edu/~jcreed/transfer/Test.pdf

The only description of embedding TrueType fonts I could find led me to believe that possibly I could just take the binary data of a .ttf file and stuff it into a "stream object" and link things up properly. I did this, and indeed it works fine if I run gv on the pdf, although Acrobat reader chokes on the embedded font.

Also, gv only works as long as I refer to the file by a relative path not involving "..". An absolute path or use of .. leads to a blank page of, I concede, the right size. What the fuck, people. Apparently this has nothing to do with embedded fonts or any other particular pdf feature.

Still don't know what I'm doing wrong to not satisfy acrobat, though, grr.

---

Apparently PDF files can refer to external files; If I keep the truetype font external, then I get the same results: works fine in gv, gets an error in Acrobat. So it's probably not the font data itself that's bad, but something in the extra font-related data that I'm putting in the PDF itself. It's really annoying programming against a standard when I don't have the source code of a guaranteed standards-compliant viewer. At least I assume that gv is in the wrong here vis-a-vis the standard, being too liberal in what it accepts. Maybe I could try tracing through why Evince breaks or something.
beartato phd

(no subject)

Man, I might as well be using test tubes and caustic acids, this is so much an experimental science.

New data: xpdf chokes on the pdf file I generate if it refers to an external TTF file, but likes it just fine if the font is embedded. Hitting the pdf with embedded font with the function (pdf2ps o ps2pdf) produces a pdf file that all three viewers display correctly... but it turns the embedded font into pure graphics commands. Not likely to be very compact if there is a lot of text. However! The function (pdf2ps o pstopdf) — note the subtle difference that I am using xpdf's pstopdf (with a "to") instead of ghostscript's ps2pdf (with a "2") — leaves embedded fonts intact through the round trip, and what I get is a pdf that even acrobat displays right. Now I probably just have to understand the diff between that pdf and the one I output to figure out what I'm doing wrong.

---

Got it! I was omitting the "Length1" field. Because of course, when you look at the documentation for a "Stream Object Dictionary" and it lists all the possible keys that might appear in said dictionary, that list is a lie. In fact, buried in the documentation on embedding fonts, it says "oh, by the way, here are some more required keys for the special case of when your stream object happens to be an embedded font."
beartato phd

(no subject)

Watched episode 2 of Alias. Crazy crazy crazy! I like how shamelessly they use genre cliches. Kind of like watching a James Bond movie, only instead of a super secret spy who likes to chase attractive women, you get a super secret spy who happens to be an attractive woman, who likes to chase down, uh, hm, government documents and bombs and zero-point energy devices and things. Bold conclusion: the quickest way to a girl's heart is inanimate objects that are for some reason of great value to black-ops secret agencies.