Reputation: 348
I have a pdf document that contains several pages. Each page can has another orienatation as the other pages. We are using the Zend Framework in Version 1.12
Assuming page 1,2 and 4 are portrait and page 3 is landscape.
Target: all pages are in portrait mode.
$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');
Result: same as before :/
What is wrong? Is it even possible? Thanks in advance.
Upvotes: 1
Views: 1491
Reputation: 348
Nevermind. I did it with 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
Upvotes: 1