合并PDF而不将文件保存在磁盘上


Merge PDF without saving a file on the disk

在php中,调用webservice后,我在变量中有一些PDF内容。

我需要合并pdf内容在一个单一的变量,使一个单一的pdf,然后发布到另一个web服务。

我找到了一些基于GS exec或FPDI的解决方案,但这些解决方案迫使我在合并之前将文件保存在磁盘上。

是否有一种方法来合并它在一个变量没有写入磁盘?

Php代码(我必须合并foreach的结果):
foreach($LogContent->DocumentsAnnexes->DocAnnexe as $parametre=>$value){
$content_brut=$value->fichier;
}
$content_maj=base64_decode($content_brut);
$OKMDocument->checkin(array('token' => $token, 'docPath' => $uuid, 'content' => $content_maj, 'comment' => 'Facture validée depuis le parapheur'));

(由于帖子的大小限制,我不能添加PDF示例)

你可以为变量使用流包装器(例如this)来解决这个问题。

由于这个问题:

未捕获的异常' exception '与消息'This document(VarStream://0)可能使用的压缩技术不是由FPDI附带的免费解析器支持。

在与GhostscriptConverter合并之前,我试图将PDF转换为1.4:

class ConcatPdf extends FPDI
{
    public $files = array();
    public function setFiles($file)
    {
        $this->files = $file;
    }
    public function concat()
    {
        foreach($this->files AS $file) {
$command = new GhostscriptConverterCommand();
$filesystem = new Filesystem();
$converter = new GhostscriptConverter($command, $filesystem);
$converter->convert(VarStream::createReference($file), '1.4');


//            $pageCount = $this->setSourceFile($file);
            $pageCount = $this->setSourceFile(VarStream::createReference($file));
            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
                $tplIdx = $this->ImportPage($pageNo);
                $s = $this->getTemplatesize($tplIdx);
                $this->AddPage($s['w'] > $s['h'] ? 'L' : 'P', array($s['w'], $s['h']));
                $this->useTemplate($tplIdx);
            }
        }
    }
}

但新问题:

[Mon Nov 21 17:31:32.103668 2016] [:error] [pid 400] [client . cn192.168.21.2:53396] PHP致命错误:未捕获的异常'RuntimeException'与消息'GPL Ghostscript 9.06: Unrecoverable错误,退出代码1'n' in/var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/转换器/GhostscriptConverterCommand.php: 39 ' nStack跟踪:' n # 0/var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/转换器/GhostscriptConverter.php (69):Xthiago ' PDFVersionConverter '转换器' GhostscriptConverterCommand ->运行(VarStream://0,"/tmp/pdf_versio…"、"1.4")' n # 1/var/www/html/tests/soap_autre/test.php (234):Xthiago ' PDFVersionConverter '转换器' GhostscriptConverter ->转换(VarStream://0,"1.4")' n # 2/var/www/html/tests/soap_autre/test.php (263):ConcatPdf->concat()'n#3 {main}'n抛出/var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/转换器/GhostscriptConverterCommand.php第39行

我不知道该怎么办