PHP 中的高质量 PDF 到 Word 转换?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/437716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
High-quality PDF to Word conversion in PHP?
提问by cletus
What's the best way of converting PDF docs to Microsoft Word format in PHP? This can be either as a PHP script or calling a (Linux) executable (with proc_open()). It just needs to be relatively fast and produce quality Word documents (in 97/2000/2003 format).
在 PHP 中将 PDF 文档转换为 Microsoft Word 格式的最佳方法是什么?这可以作为 PHP 脚本或调用 (Linux) 可执行文件(使用 proc_open())。它只需要相对较快并生成高质量的 Word 文档(97/2000/2003 格式)。
Commercial software is OK.
商业软件没问题。
回答by Shankar Damodaran
To read PDFfiles, you will need to install the XPDFpackage, which includes "pdftotext." Once you have XPDF/pdftotext installed, you run the following PHP statement to get the PDF text:
要阅读PDF文件,您需要安装XPDF包,其中包括“pdftotext”。安装 XPDF/pdftotext 后,运行以下 PHP 语句以获取 PDF 文本:
content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');
After getting the content, Download PHPDOCXCommunity version, try like this.
获取内容后,下载PHPDOCX社区版,这样试试。
<?php
require_once '../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$textInfo = $content;
$paramsTextInfo = array(
'val' => 1,
'i' => 'single',
'sz' => 8
);
$docx->addText($textInfo, $paramsTextInfo);
$docx->createDocx('report.docx');
?>
回答by codelogic
Openoffice has a PDF import extension. Most of OpenOffice is scriptable, so you should be able to write a command line interface to perform the conversion. There are many exampleson the official UNO wiki.
Openoffice 有一个PDF 导入扩展。大多数 OpenOffice 都是可编写脚本的,因此您应该能够编写命令行界面来执行转换。官方 UNO wiki 上有很多示例。
回答by codelogic
By far the easiest way is with phpLiveDocx. It can load DOC, DOCX and RTF and save to PDF. It can be downloaded from http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/The download file contains a large number of sample applications, which illustrate all aspects of the PHP5 library. Leo
到目前为止,最简单的方法是使用 phpLiveDocx。它可以加载 DOC、DOCX 和 RTF 并保存为 PDF。可以从http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/下载 下载文件包含大量示例应用程序,它们说明了 PHP5 库的方方面面。狮子座

