2016-11-16 87 views
0

在php中,在调用Web服务之后,我在变量中有一些PDF内容。在不保存文件的情况下合并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的例子)

+2

你能给我们一个内容如何存储/结构的例子吗? – atoms

+0

Michael,编辑您的问题以包含这些变量的pdf字符串内容,我们需要让他们知道我们在这里处理的是什么。如果内容不是字符串,它是否是对象?它是什么类型? –

+0

PDF是在base64, 我把它从一个对象,我试着用(字符串)在值的前面,相同的结果... – MichaelED17

回答

1

您可以使用一个stream wrapper为变量(例如this)来解决这个问题。

+0

感谢它的工作! – MichaelED17

+0

不,实际上它不起作用,我鼓励这个问题:PHP致命错误:未捕获异常'异常',消息'无法找到'startxref“关键字”。在/var/www/html/tests/soap_autre/vendor/setasign/fpdi/pdf_parser.php:287\nStack trace: – MichaelED17

+0

那么,你在你传递给流封装的变量中找到关键字“startxref”吗? –

0

由于此问题:

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.

我试图将PDF转换成1.4 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); 
      } 
     } 
    } 
} 

但是,新的问题:

[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\n' in /var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/Converter/GhostscriptConverterCommand.php:39\nStack trace:\n#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')\n#1 /var/www/html/tests/soap_autre/test.php(234): Xthiago\PDFVersionConverter\Converter\GhostscriptConverter->convert('VarStream://0', '1.4')\n#2 /var/www/html/tests/soap_autre/test.php(263): ConcatPdf->concat()\n#3 {main}\n thrown in /var/www/html/tests/soap_autre/vendor/xthiago/pdf-version-converter/src/Converter/GhostscriptConverterCommand.php on line 39

我不知道做什么 !

+0

我猜Ghostscript将不适用于流包装,因为它被称为通过CLI。使用单独的[FPDI PDF-Parser](https://www.setasign.com/products/fpdi-pdf-parser/details/),该问题也应该消失。 –

+0

Thanx的提示,但它是商业的,你知道一些免费的人谁可以做到这一点? – MichaelED17

相关问题