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

In php, after calling a webservice, I have some PDF content in variables.

I need to merge the pdf content in a single variable to make one single PDF and then post it to another webservice.

I found some solutions based on GS exec or FPDI but those solutions oblige me to save the files on the disk before merging it.

Is there a way to merge it in a variable without writing on the disk?

Code in Php (I have to merge the result of the 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'));

(I can't add PDF example because of the size limit of the post)

You can use a stream wrapper for variables (e.g. this) to overcome this issue.

Because of this issue :

Uncaught exception 'Exception' with message 'This document (VarStream://0) probably uses a compression technique which is not supported by the free parser shipped with FPDI.

I tried to convert the PDF into 1.4 before merging with GhostscriptConverter :

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);
            }
        }
    }
}

But new issue :

[Mon Nov 21 17:31:32.103668 2016] [:error] [pid 400] [client 192.168.21.2:53396] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'GPL Ghostscript 9.06: Unrecoverable error, exit code 1 ' in /var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/Converter/GhostscriptConverterCommand.php:39 Stack trace: #0 /var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/Converter/GhostscriptConverter.php(69): Xthiago\PDFVersionConverter\Converter\GhostscriptConverterCommand->run('VarStream://0', '/tmp/pdf_versio...', '1.4') #1 /var/www/html/tests/soap_autre/test.php(234): Xthiago\PDFVersionConverter\Converter\GhostscriptConverter->convert('VarStream://0', '1.4') #2 /var/www/html/tests/soap_autre/test.php(263): ConcatPdf->concat() #3 {main} thrown in /var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/Converter/GhostscriptConverterCommand.php on line 39

I do not know what to do !