ruhk has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow Monks! Im at a loss of what to do for a project that was assigned to me. Basically, we are creating a messageboard for a college campus that people can post news and whatnot instead of printing out 23489384387 different sheets of paper that just get thrown out in an effort to save money. We want people to be able to attach a text file or image or word document to the news and upload it, and we want the server to convert it to .pdf format. Ive played a lot with perl and pdfs, Ive used a couple modules before to turn plain text and html into pdfs however I am at a loss how to proceed. The best I have so far come up with is some code that uses Win32::OLE to manipulate word to do the conversion, however due to resources on the server this isnt an option. Does anyone have any idea for an automated way to convert word files to pdfs? I implore you to just point me in the right direction!

Replies are listed 'Best First'.
Re: More PDF troubles
by Corion (Patriarch) on Sep 15, 2003 at 20:44 UTC

    The easiest way to convert a Word document to PDF is to set up a special machine, with the default printer a PDF converter, and automate Word to print the document (via Win32::OLE).

    Parsing and recreating Word input/output is not easily done - maybe you can also install and automate the OpenOffice.Org suite, which possibly can read *.doc files, and they for sure have an .pdf output option.

    If you're in for a pure Perl solution, I fear that the closest thing available is SpreadSheet::ParseExcel, which should do most of the OLE-Stream parsing, but which will know nothing about Word...

    Personally, I would tell the people to either upload an image, text or a PDF and thus put the burden of producing a suitable PDF file on them - it isn't hard with either a Mac or a Windows PC and even the Unix users should know how to coax their tool of choice to produce a suitable PDF.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
      If it were up to me I would just require the user to convert it to PDF ( our campus has a site liscense to Acrobat Writer.) However, it has to be done this way, and it has to be a perl only or near perl only solution. One thing I am looking into is to go from word->html and then html->pdf.
Re: More PDF troubles
by aquarium (Curate) on Sep 15, 2003 at 22:42 UTC
    use redmon (a port redirector utility) in combination with ghostscript, on either platform, to print pdf from any program that uses standard OS printing facilities. redmon web page tells you how to set it up. You can then do the conversions manually OR via OLE.