2016-11-16 125 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

相關問題