2015-09-23 145 views
1

我有一個包含多個頁面的pdf文檔。 每個頁面都可以有其他頁面的其他頁面。 我們在版本1.12中使用Zend Framework如何將橫向PDF頁面轉爲縱向

假設頁面1,2和4是縱向,頁面3是橫向。

目標:所有頁面都處於縱向模式。

 $pdf = Zend_Pdf::load($this->getFile()); 
     foreach ($pdf->pages as $index => $page) { 
      /** 
      * @var Zend_Pdf_Page $page 
      * @var integer  $index 
      */ 
      if (595 === $page->getHeight()) { 
       $page->rotate(0, 0, deg2rad(90)); 
       $pdf->pages[$index] = $page; 
      } 
     } 
     $pdf->save($this->getFile().'.new.pdf'); 

結果:和以前一樣:/

有什麼不對?它甚至有可能嗎? 在此先感謝。

+0

你確定高度爲* *確切點595? – usr2564301

+0

好點。但是這沒關係。 甚至 if($ page-> getHeight()< $page-> getWidth()){ 頁面未轉向肖像 – wolxXx

+0

測試代碼是否執行任何操作:刪除if,以便旋轉所有頁面。如果這也行不通,問題就出在其他地方。 – usr2564301

回答

1

沒關係。我與Java做的:)

try { 
     PDDocument doc = PDDocument.load(filePath); 
     List allPages = doc.getDocumentCatalog().getAllPages(); 
     for (int i = 0; i < allPages.size(); i++) { 
      PDPage page = (PDPage) allPages.get(i); 
      PDRectangle mediaBox = page.getMediaBox(); 
      if (mediaBox.getWidth() > mediaBox.getHeight()) { 
       page.setRotation(90); 
      } 
     } 
     String output = filePath + ".new.pdf"; 
     doc.save(output); 
     doc.close(); 
     System.out.println("wrote output to " + output); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (COSVisitorException e) { 
     e.printStackTrace(); 
    } 

http://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox

相關問題