|
|
@@ -287,21 +287,17 @@ class PdfMerger
|
|
|
|
|
|
/**
|
|
|
* 使用qpdf合并PDF(带进度回调)
|
|
|
- * 【修复】qpdf命令格式不正确,缺少页面范围参数
|
|
|
- * 正确格式:qpdf --empty --pages file1.pdf 1-z,file2.pdf 1-z -- output.pdf
|
|
|
+ * 【修复】qpdf命令格式问题 - 使用正确的页面范围语法
|
|
|
+ * 正确格式:qpdf --empty --pages file1.pdf,file2.pdf -- output.pdf
|
|
|
+ * qpdf会自动合并所有页面,无需手动指定页面范围
|
|
|
*/
|
|
|
private function mergeWithQpdf(array $pdfPaths, string $outputPath, ?callable $progressCallback = null): bool
|
|
|
{
|
|
|
// 【修复】构建正确的qpdf命令
|
|
|
- // qpdf --empty --pages file1.pdf 1-z,file2.pdf 1-z -- output.pdf
|
|
|
- // 每个文件都需要指定页面范围(1-z表示从第一页到最后一页)
|
|
|
-
|
|
|
- $pagesArgs = [];
|
|
|
- foreach ($pdfPaths as $pdfPath) {
|
|
|
- $pagesArgs[] = escapeshellarg($pdfPath) . ' 1-z';
|
|
|
- }
|
|
|
- $pagesArg = implode(',', $pagesArgs);
|
|
|
+ // qpdf --empty --pages file1.pdf,file2.pdf -- output.pdf
|
|
|
+ // 注意:qpdf不需要手动指定页面范围,会自动合并所有页面
|
|
|
|
|
|
+ $pagesArg = implode(',', array_map('escapeshellarg', $pdfPaths));
|
|
|
$command = "qpdf --empty --pages {$pagesArg} -- -- " . escapeshellarg($outputPath);
|
|
|
|
|
|
Log::debug('执行qpdf命令', ['command' => $command]);
|
|
|
@@ -341,7 +337,8 @@ class PdfMerger
|
|
|
'error' => $output->errorOutput(),
|
|
|
'duration_ms' => $duration,
|
|
|
'timeout_seconds' => $timeout,
|
|
|
- 'corrected_command' => $command // 记录修正后的命令用于调试
|
|
|
+ 'command' => $command,
|
|
|
+ 'note' => 'qpdf会自动合并所有页面,不需要指定页面范围'
|
|
|
]);
|
|
|
|
|
|
return false;
|