如何将横向pdf页面变成纵向
How to turn a landscape pdf page to portrait
我有一个包含几页的 pdf 文档。
每个页面都可以像其他页面一样有不同的方向。
我们正在使用版本 1.12
中的 Zend 框架
假设第 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');
结果:与之前相同:/
怎么了?有可能吗?
提前致谢。
没关系。我用 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();
}
我有一个包含几页的 pdf 文档。 每个页面都可以像其他页面一样有不同的方向。 我们正在使用版本 1.12
中的 Zend 框架假设第 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');
结果:与之前相同:/
怎么了?有可能吗? 提前致谢。
没关系。我用 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();
}