如何将横向pdf页面转换为纵向

时间:2015-09-23 11:15:10

标签: php pdf zend-framework

我有一个包含多个页面的pdf文档。 每个页面可以具有与其他页面相同的另一个方向。 我们在版本1.12中使用Zend Framework

假设第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');

结果:与之前相同:/

有什么问题?它甚至可能吗? 提前谢谢。

1 个答案:

答案 0 :(得分: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