Software, technology, sysadmin war stories, and more. Feed
Saturday, January 12, 2013

PDF creation with Samba, Ghostscript, and a bit of glue

When I worked for that school district, I sometimes did a bunch of things which were intended to save money. Turning our existing "screwdriver shop" machines into CD towers was one of them. Breaking out a /24 from our bigger block to get distinct routing through another ISP in the absence of BGP was another.

I got a reputation as someone who could make something work even if it involved some crazy plumbing behind the scenes. One day, I was called to put these skills to work in the field of document creation. Specifically, my users wanted to create PDFs and couldn't afford Adobe Acrobat. I heard about this somehow and the wheels started turning in my head.

Thanks in part to my earlier work in making printing happen from our Unix boxes, I was familiar with tools like 'ps2pdf'. It seemed like the obvious solution: we get the users to give us PostScript versions of their documents, and I'll run it through that tool to get a PDF. Easy, right? Well, it actually required more steps than that.

The best way to get PostScript output from my Windows-using users was to have them set up a new printer of that type. That step also happened to be the right way for them to get the jobs to my server for processing. Instead of having some screwy web upload form, I created a fake SMB printer using Samba. It would just take whatever input it had been handed and would run it through ps2pdf, dropping the output in a "holding tank" for later pickup.

All my users had to do is do the one-time task of adding this new bogus printer to their system. It would pick up the PostScript details automatically. Then, they'd just "print" to that instead of their usual device and it would end up on my machine. Later, they could hit the web server, plug in their username, and then they would be presented with a list of files they had waiting.

With the help of my friend the webmaster, we made it look pretty nice. We even went to some lengths to make it as friendly as possible. For instance, the URL to the file that you wind up clicking could have been something like "/cgi-bin/pdfconv/pickup?user=rachel&doc=abcd". This would have given terrible results when users clicked on it, since it might create a file on their disk called "pickup" or worse. It certainly wouldn't have had the magic ".pdf" file extension that Windows needs to see to know what it "really" is.

Instead, I renamed a few things so the actual pickup program was called document.pdf. This way, when they did the "save as..." thing in their browser, taking the default would yield something meaningful. It probably saved a whole bunch of support phone calls from confused users.

It wasn't particularly elegant, but it did get the job done.

Sometimes I wonder if some version of this thing is still in use out there.