2017-01-23 62 views
0

我使用wkhtmltopdf生成pdf文件,我需要設置不同的選項到 不同的頁面。Mikehaertl wkhtmltopdf爲不同的頁面設置不同的選項

例如:

$pdf->addPage('http://frontbeta/')->setOptions(['orientation' => 'landscape']); 
$pdf->addPage('http://backbeta/'); 

所以,第1頁和肖像orientaion到第2頁橫向。 但上面的代碼爲所有頁面設置了第一個選項。

這裏是生成的PDF文件的功能:

protected function createPdf() 
{ 
    if ($this->_isCreated) { 
     return false; 
    } 
    $command = $this->getCommand(); 
    $fileName = $this->getPdfFilename(); 

    $command->addArgs($this->_options); 

    foreach ($this->_objects as $object) { 
     $command->addArgs($object); 
    } 
    $command->addArg($fileName, null, true); // Always escape filename 
    if (!$command->execute()) { 
     $this->_error = $command->getError(); 
     if (!(file_exists($fileName) && filesize($fileName)!==0 && $this->ignoreWarnings)) { 
      return false; 
     } 
    } 
    $this->_isCreated = true; 
    return true; 
} 

這裏,設置選項的foreach對象。那麼我該如何改變功能呢?

回答

1

documentation,我發現-O landscape。您可以通過添加此選項來更改您的命令。

enter image description here

+0

這是事實,但只是作爲一個全局選項,整個文件。 AFAIK,目前(可惜)沒有選擇wkhtmltopdf設置頁面級別的方向。使用CSS旋轉頁面有一些可能性(我現在正在嘗試),但只有在最簡單的情況下才可能滿足。有官方功能請求,在這裏:https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1564。看看你是否可以幫助。 – userfuser

相關問題