|
|
Subject:
XLS to PDF Conversion using PHP/Ghostscript
Category: Computers > Programming Asked by: g8z-ga List Price: $10.00 |
Posted:
17 Mar 2003 01:45 PST
Expires: 16 Apr 2003 02:45 PDT Question ID: 177241 |
Hello, I need to be able to convert an Excel .XLS file to PDF, but it must be done via scripting (e.g. PHP, JSP, etc) on a remotely-hosted website. For example, a user uploads a .XLS file to the server via a standard HTML form, then when "Submit" is clicked, a PHP (or other language) script is called, which converts the file to a PDF. The PDF will then be saved to a database, but this I can handle - I just need to know how to do the conversion. Here's what is available to me: PHP, Perl, JSP, Python, Java Servlets, Ghostscript version 6. The server is Linux, running Apache. Constraints: I do not have root privileges on the server, so I cannot install commercial software that I buy, and since it's running Linux I would assume that MS Office is NOT installed on the server, although I may be able to get some freeware like OpenOffice installed. If this conversion is impossible without having Excel installed on the server, I may be able to persuade my web host to install it. I know that there are a lot of programs out there that allow this type of conversion, but they're expensive, or they are things that must be downloaded and installed, which I probably wouldn't be able to do given my limited server permissions. The ideal solution would involve only PHP or JSP commands + Ghostscript or utilities built into Linux. Thanks, Darren |
|
Subject:
Re: XLS to PDF Conversion using PHP/Ghostscript
Answered By: eiffel-ga on 17 Mar 2003 03:26 PST Rated: |
Hi g8z, You can convert XLS files to PDF on Linux by installing OpenOffice with a PDF writer as the default printer driver. Then, you can call OpenOffice (from PHP) using the "-p" command-line parameter, which will cause it to load a designated file and print it. For example, if your file was "accounts.xls" you would call the following command: soffice -p accounts.xls OpenOffice would load the "accounts.xls" file and "print" it to the PDF writer, which would be configured to save the PDF document to the desired filename. GhostScript is a suitable PDF writer. The OpenOffice setup guide describes how to install and configure printer drivers using the "spadmin" utility, and discusses the use of ghostscript as a PDF writer: "Open Office Setup Guide - Appendix" http://www.openoffice.org/docs/setup_guide/appendix.html You can call OpenOffice from PHP by using the backtick execution operator, or the "exec" function. You may also need to use PHP to move and/or rename the resulting PDF files: PHP: Program Execution Functions http://www.php.net/manual/en/ref.exec.php PHP: Filesystem: Rename http://www.php.net/manual/en/function.rename.php OpenOffice is pretty good at processing XLS files, but it may not perfectly render every such file - so if you need the ultimate in compatibility you will have to use Microsoft Excel on a Windows Platform or emulator. "IT AsiaOne" looked at several alternatives to Microsoft Office (including OpenOffice) and wrote that "while none of the alternative suites promise ... full compatibility with Microsoft Office-created documents, in general, they do a decent job of translating Microsoft ".doc", ".ppt" and ".xls" file formats": IT AsiaOne - Specials - Yours For The Picking http://it.asia1.com.sg/specials/mmedia20020724_001.html Additional links: OpenOffice.org Home Page http://www.openoffice.org/ Ghostscript Home Page http://www.cs.wisc.edu/~ghost/ PHP Home Page http://www.php.net/ Google search strategy: openoffice scripting pdf linux ://www.google.com/search?q=openoffice%20scripting%20pdf%20linux openoffice print "command line" ://www.google.com/search?q=openoffice%20scripting%20pdf%20linux followed by a search for "command line parameters" from the openoffice.org home page. Regards, eiffel-ga | |
| |
|
g8z-ga rated this answer: |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |