PHP 中的高质量 PDF 到 Word 转换?

发布于 2024-07-10 21:47:39 字数 164 浏览 7 评论 0原文

在 PHP 中将 PDF 文档转换为 Microsoft Word 格式的最佳方法是什么? 这可以作为 PHP 脚本或调用 (Linux) 可执行文件(使用 proc_open())。 它只需要相对较快并生成高质量的 Word 文档(97/2000/2003 格式)。

商业软件就可以。

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).

Commercial software is OK.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

简单 2024-07-17 21:47:39

要阅读PDF文件,您需要安装XPDF< /a> 包,其中包括“pdftotext”。 安装 XPDF/pdftotext 后,运行以下 PHP 语句来获取 PDF 文本:

content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');

获取内容后,下载 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');
?>

To read PDF files, you will need to install the XPDF package, which includes "pdftotext." Once you have XPDF/pdftotext installed, you run the following PHP statement to get the PDF text:

content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');

After getting the content, Download PHPDOCX Community version, try like this.

<?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');
?>
孤蝉 2024-07-17 21:47:39

Openoffice 有一个 PDF 导入扩展。 大多数 OpenOffice 都是可编写脚本的,因此您应该能够编写命令行界面来执行转换。 UNO 官方 wiki 上有许多示例

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 examples on the official UNO wiki.

满地尘埃落定 2024-07-17 21:47:39

另一个转换选项是Aspose.Words Cloud SDK for PHP。 它是一套高效的 Word 文档处理解决方案,不依赖于任何 Microsoft Word。 它是付费产品,但免费定价计划每月提供 150 次免费 API 调用。

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');


try {

    //TODO: Get your ClientID and ClientSecret at https://dashboard.aspose.cloud (free registration is required).       
    $ClientSecret="xxxxxxxxxxxxxxxxxxxxxx";
    $ClientID="xxxx-xxxx-xxxx-xxxx-xxxxxxxxxx";


    $wordsApi = new Aspose\Words\WordsApi($ClientID,$ClientSecret);
    
    
    $format = "docx";
    $file = ("C:/Temp/02_pages.pdf");
    
    $request = new Aspose\Words\Model\Requests\ConvertDocumentRequest($file, $format,null);
    $result = $wordsApi->ConvertDocument($request); 
    copy($result->getPathName(),"C:/Temp/02_pages.docx");
        
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>

PS:我是 Aspose 的开发人员布道者。

Another option for the conversion is Aspose.Words Cloud SDK for PHP. It is an efficient set of Word document processing solutions without any Microsoft Word dependencies. It is paid product but free pricing plan offers 150 free API calls monthly.

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');


try {

    //TODO: Get your ClientID and ClientSecret at https://dashboard.aspose.cloud (free registration is required).       
    $ClientSecret="xxxxxxxxxxxxxxxxxxxxxx";
    $ClientID="xxxx-xxxx-xxxx-xxxx-xxxxxxxxxx";


    $wordsApi = new Aspose\Words\WordsApi($ClientID,$ClientSecret);
    
    
    $format = "docx";
    $file = ("C:/Temp/02_pages.pdf");
    
    $request = new Aspose\Words\Model\Requests\ConvertDocumentRequest($file, $format,null);
    $result = $wordsApi->ConvertDocument($request); 
    copy($result->getPathName(),"C:/Temp/02_pages.docx");
        
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>

P.S: I'm developer evangelist at Aspose.

走过海棠暮 2024-07-17 21:47:39

到目前为止,最简单的方法是使用 phpLiveDocx。 它可以加载DOC、DOCX和RTF并保存为PDF。 可以从 http://www.phplivedocx.org/articles/ 下载Brief-introduction-to-phplivedocx/ 下载文件包含大量示例应用程序,它们说明了 PHP5 库的各个方面。 狮子座

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文