Hi,
Hi Nicolas,
com.aspose.pdf.Document doc = new
com.aspose.pdf.Document(myDir+“result.pdf”);
System.out.println(doc.getPages().get_Item(1).getPageInfo().isLandscape());
doc.getPages().get_Item(1).setRotate(Rotation.on270);
doc.save(myDir+“LandScapeOutput.pdf”);
Document doc = new Document(“PdfWithText.pdf”);<o:p></o:p>
for (int pageCount = 1; pageCount <= doc.getPages().size(); pageCount++)<o:p></o:p>
{<o:p></o:p>
Page page= doc.getPages().get_Item(pageCount);<o:p></o:p>
com.aspose.pdf.Rectangle r = page.getMediaBox();<o:p></o:p>
double newHeight = r.getWidth();<o:p></o:p>
double newWidth = r.getHeight() * r.getHeight() / r.getWidth();<o:p></o:p>
double newLLX = r.getLLX();<o:p></o:p>
//we must to move page upper in order to compensate changing page size (lower edge of the page is 0,0 and information is usually placed from the top of the page. That’s why we move lover edge upper on difference between old and new height.<o:p></o:p>
double newLLY = r.getLLY() + (r.getHeight() - newHeight);<o:p></o:p>
page.setMediaBox(new com.aspose.pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));<o:p></o:p>
//sometimes we also need to set CropBox (if it was set in original file)<o:p></o:p>
page.setCropBox(new com.aspose.pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));<o:p></o:p>
}<o:p></o:p>
doc.save(“36115.pdf”);
Furthermore, you may consider using PdfPageEditor as it may help you to change the page orientation without truncating page data.
[Java]
Document doc = new Document(myDir+“ipnut.pdf”);<o:p></o:p>
com.aspose.pdf.Rectangle r = doc.getPages().get_Item(1).getRect();<o:p></o:p>
PdfPageEditor ppe = new PdfPageEditor();<o:p></o:p>
ppe.bindPdf(doc);<o:p></o:p>
ppe.setZoom((float)(r.getWidth() / r.getHeight()));<o:p></o:p>
ppe.setPageSize(new com.aspose.pdf.PageSize((float)r.getHeight(), (float)r.getWidth()));<o:p></o:p>
ppe.save(myDir+“output_ppe.pdf”);
Hi and thank you for your answer.
Hi Nicolas,
Hi,
Hi Nicolas,
Thank you. Sorry for the inconvenience as i know this is as a very specific request.
Hi Nicolas,