2017-02-16 75 views
2

我一直在使用TCPDF 現在我想做出一個頁第4頁在一張紙上TCPDF自動設置persheet

enter image description here

沒有與腳本沒有任何問題成功生成PDF格式...我只是要使它自動設置persheet 4,因此用戶不必須設定他們想要讓我不要有我的編碼改爲多


到print..is有沒有辦法做到這一點,每次配置如建議,我使用fpdi

   $pdf->Output($st.'/TEST.PDF', 'F'); 
      require_once(APPPATH.'libraries/FPDI/fpdf_tpl.php'); 
      require_once(APPPATH.'libraries/FPDI/fpdi.php'); 


      $filename = $st.'/TEST.PDF'; 

      $pdfx = new FPDI(); 


      //exit(); 

      $pageCount = $pdfx->setSourceFile($filename); 


      //echo $pageCount; 
      //exit(); 

      $w = $pdfx->GetPageWidth()/2 - 15; 
      $h = 0; 

      $_x = $x = 10; 
      $_y = $y = 10; 

      $pdfx->AddPage(); 
      for ($n = 1; $n <= $pageCount; $n++) { 
       $tplIdx = $pdfx->importPage($n); 

       $size = $pdfx->useTemplate($tplIdx, $x, $y, $w); 
       $pdfx->Rect($x, $y, $size['w'], $size['h']); 
       $h = max($h, $size['h']); 
       if ($n % 2 == 0) { 
        $y += $h + 10; 
        $x = $_x; 
        $h = 0; 
       } else { 
        $x += $w + 10; 
       } 

       if ($n % 4 == 0 && $n != $pageCount) { 
        $pdfx->AddPage(); 
        $x = $_x; 
        $y = $_y; 
       } 
      } 

      $pdfx->Output('thumbnails.pdf', 'F'); 

但即時得到一個錯誤消息

甲PHP錯誤遇到

嚴重性:警告

消息:fopen()函數:遠程主機文件訪問不支持,文件:// thumbnails.pdf

文件名:包括/ tcpdf_static.php

行號:遇到2466 一個PHP錯誤

嚴重性:警告

消息:的fopen(文件://thumbnails.pdf):未能打開流:沒有合適的包裝可以發現

文件名:包括/ tcpdf_static.php

行號:2466 TCPDF錯誤:無法創建輸出文件:thumbnails.pdf

這是在codeignighter衝突庫?我加載TCPDF然後我再次要求FPDI庫


哦,我想我知道這個問題是關於保存位置...請不要介意我重新修改我的輸出到 $ pdfx->輸出('thumbnails.pdf ', '一世');

回答

1

這裏有一個印前條款 - imposition - 您所談論的內容。我猜測TCPDF本身沒有拼版工具。

你可以寫上通過TCPDF生成的文件使用FPDI簡單的拼版工具(檢查this example出),或看看另一個庫調用PDFlib和,具體而言, pdfimpose腳本該庫。

+0

確定我使用fpdi,因爲你建議,但我得到一個錯誤信息,但我認爲代碼工作..只有部分,當我嘗試輸出thumbnails.pdf我不知道爲什麼它從tcpdf獲得庫 – Runshax

+1

哦我知道問題,我只是reedit $ pdfx->輸出('thumbnails.pdf','我'); – Runshax