提问人:NigSys Technologies 提问时间:10/26/2023 更新时间:10/26/2023 访问量:49
如何在 PHP 中使用 LibreOffice 解决此问题并从 PDF 转换 DOCX 文件?
How can I resolve this issue and convert the DOCX file from the PDF Using LibreOffice in PHP?
问:
运行以下代码时遇到以下错误:
数组 ( [0] => 错误:未找到 /home/nigsys.net/public_html/123 的导出过滤器.docx正在中止。 [1] => 错误:没有导出过滤器 )
转换完成。Word 文件位于 output.docx
我目前在我的服务器上使用 LibreOffice 5.3 版,我的 PHP 版本是 7.3。我正在使用以下代码,该代码使用 LibreOffice 命令,将 PDF 文件转换为 DOCX 文件:
<?php
// Define the input PDF file and output DOCX file
$inputPDF = '123.pdf';
$outputDoc = 'output.docx';
// Check if 'soffice' is recognized
$libreofficeCheck = shell_exec('where soffice');
if (empty($libreofficeCheck)) {
echo 'LibreOffice is not recognized. Please ensure that LibreOffice is installed, and its directory is included in the system PATH.';
} else {
// Command to convert the PDF to DOCX
$libreofficeCommand = 'soffice --headless --convert-to docx --outdir ' . __DIR__ . ' ' . $inputPDF;
// Execute the LibreOffice command
exec($libreofficeCommand, $output, $return);
echo "<pre>";
print_r($output);
if ($return !== 0) {
echo 'Error: LibreOffice conversion failed. Output: ' . implode("\n", $output);
} else {
echo 'Conversion complete. The Word file is located at ' . $outputDoc;
}
} ?>
PHP 和 PDF 文件位于同一目录中。
我想使用 LibreOffice 将 PDF 文件转换为 Docx 文件。请提供有关解决此问题的指导。
答: 暂无答案
评论