本文介绍了PHP将Excel(.xls)转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在将xls文件转换为pdf文档的php/java/开源软件转换器或php库?

Is there any php/java/open source software converters or php libraries that will convert an xls file to a pdf document?

精简版:具有生成xls电子表格的预先存在的代码(大约在2002-2006年,我相信是预打开的xml版本),出于各种原因,需要将它们转换为pdf.

Rundown: Have pre-existing code generating xls spreadsheets (circa 2002-2006, pre open xml version I believe), need to turn them into pdfs for various reasons.

开始搜索无处不在,包括此处.我想我只需要朝正确的方向撞,我敢肯定已经有东西可以做到这一点.

Been searching everywhere including here. I think I just need a bump in the right direction, I'm sure there is something out there already that does it.

推荐答案

您可以通过安装OpenOffice在Linux上将XLS文件转换为PDF使用PDF编写器作为默认打印机驱动程序.

You can convert XLS files to PDF on Linux by installing OpenOfficewith a PDF writer as the default printer driver.

然后,您可以使用"-p"命令行调用OpenOffice(来自PHP)参数,这将使其加载指定的文件并进行打印.

Then, you can call OpenOffice (from PHP) using the "-p" command-lineparameter, which will cause it to load a designated file and print it.

例如,如果您的文件是"accounts.xls",则将其称为以下命令:

For example, if your file was "accounts.xls" you would call thefollowing command:

soffice -p account.xls

soffice -p accounts.xls

OpenOffice将加载"accounts.xls"文件并将其打印"到PDF writer,将其配置为将PDF文档保存到所需的文件名.

OpenOffice would load the "accounts.xls" file and "print" it to thePDF writer, which would be configured to save the PDF document to thedesired filename.

GhostScript是合适的PDF编写器.

GhostScript is a suitable PDF writer.

OpenOffice安装指南介绍了如何安装和配置使用"spadmin"实用程序的打印机驱动程序,并讨论了作为PDF编写者的ghostscript:"Open Office安装指南-附录" http://www.openoffice.org/docs/setup_guide/appendix.html

The OpenOffice setup guide describes how to install and configureprinter drivers using the "spadmin" utility, and discusses the use ofghostscript as a PDF writer:"Open Office Setup Guide - Appendix"http://www.openoffice.org/docs/setup_guide/appendix.html

您可以使用反引号执行从PHP调用OpenOffice运算符或"exec"功能.您可能还需要使用PHP移动和/或重命名生成的PDF文件:

You can call OpenOffice from PHP by using the backtick executionoperator, or the "exec" function. You may also need to use PHP to moveand/or rename the resulting PDF files:

PHP:程序执行功能 http://www.php.net/manual/zh/ref.exec.php

PHP: Program Execution Functionshttp://www.php.net/manual/en/ref.exec.php

PHP:文件系统:重命名 http://www.php.net/manual/zh/function.rename.php

PHP: Filesystem: Renamehttp://www.php.net/manual/en/function.rename.php

OpenOffice非常擅长处理XLS文件,但可能不行完美呈现每个此类文件-因此,如果您需要最终版本兼容性,您将必须在Windows上使用Microsoft Excel平台或仿真器. "IT AsiaOne"探讨了以下几种替代方案Microsoft Office(包括OpenOffice)并写道替代套件承诺...与Microsoft完全兼容通常,Office创建的文档在以下方面做得不错翻译Microsoft".doc",.ppt"和".xls"文件格式":

OpenOffice is pretty good at processing XLS files, but it may notperfectly render every such file - so if you need the ultimate incompatibility you will have to use Microsoft Excel on a WindowsPlatform or emulator. "IT AsiaOne" looked at several alternatives toMicrosoft Office (including OpenOffice) and wrote that "while none ofthe alternative suites promise ... full compatibility with MicrosoftOffice-created documents, in general, they do a decent job oftranslating Microsoft ".doc", ".ppt" and ".xls" file formats":

IT AsiaOne-特价商品-您的选购 http://it.asia1.com.sg/specials/mmedia20020724_001.html

IT AsiaOne - Specials - Yours For The Pickinghttp://it.asia1.com.sg/specials/mmedia20020724_001.html

其他链接:

OpenOffice.org主页 http://www.openoffice.org/

OpenOffice.org Home Pagehttp://www.openoffice.org/

Ghostscript主页 http://www.cs.wisc.edu/~ghost/

Ghostscript Home Pagehttp://www.cs.wisc.edu/~ghost/

PHP主页 http://www.php.net/

Google搜索策略:

Google search strategy:

openoffice脚本pdf Linux://www.google.com/search?q = openoffice%20scripting%20pdf%20linux

openoffice scripting pdf linux://www.google.com/search?q=openoffice%20scripting%20pdf%20linux

openoffice打印命令行"://www.google.com/search?q = openoffice%20scripting%20pdf%20linux

openoffice print "command line"://www.google.com/search?q=openoffice%20scripting%20pdf%20linux

接下来是从命令行中搜索命令行参数"openoffice.org主页.

followed by a search for "command line parameters" from theopenoffice.org home page.

ref: http://answers.google.com/answers/threadview/id/177241.html

这篇关于PHP将Excel(.xls)转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 11:43