[geeklog-devel] PDF from article
dirk at haun-online.de
Sat Jan 3 09:04:03 EST 2015
So I need to create PDFs from some of my articles. Only new ones, actually, so I don't mind a little extra manual work. I thought I'd simply use the "print to PDF" option from my operating system (Mac OS X, but Windows or Linux have similar options, AFAIK). The results weren't what I was hoping for, though.
Just printing the "normal" article view will include the site's header and footer, as well as all the stuff displayed in the side blocks (e.g. Who's online) that you don't really need here.
The dedicated "print" view that we have, however, doesn't load the stylesheet. So the article's formatting is lost, images don't show up as expected and so on.
I wonder if our print view really makes sense like that. Shouldn't we at least load the stylesheet to preserve the formatting?
After hacking that in, I encountered another problem: Links in the article are shown underlined but the actual URL they link to is lost. While you can make URLs in PDFs work like in HTML that would require creating the entire PDF from within Geeklog with the help of a PDF library (PDFlib or the like) and I didn't really want to invest that much time.
So I extracted the URLs from the article text and added them as footnotes at the end of the article. I also removed the underlines and instead inserted the footnote number in the text.
The result isn't perfect - it doesn't handle page breaks, for example. But I'm quite please with the way it looks. It's a clean look (without the site's header/footer or side blocks) but properly formatted. And you still get the URLs of the linked sites (the Mac OS X Preview app actually lets you click on those, at least the ones that don't wrap).
The code I came up with for this is not very elegant, though, to put it mildly. It also includes some code to handle special cases on my site. Still, I was wondering if I should try and integrate some of this back into Geeklog and in which way. Right now, I gave it a separate link, /pdf instead of /print. But, as stated above, maybe it would make more sense to modify the existing print view and make it more usable.
P.S. Some of you may remember that Geeklog did have an option to generate PDFs at one point. But it didn't really work all that well and was eventually removed again. https://www.geeklog.net/article.php/20040607171321591
More information about the geeklog-devel