We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page Orientation Settings for com.aspose.pdf.Document

Hi,


Is there anyway to setup the page orientation for PDF document. In my requirement, i am not creating any new PDF document. I am loading the existing PDF document into com.aspose.pdf.Document object to apply pagesetup

Regards

Hi Diane,


Thanks for contacting support.

In order to set/change the page orientation, setLandscape(true); of PageInfo class can be used. But I am afraid in recent release of Aspose.Pdf for Java is having some issue while setting/updating the page orientation of PDF file. For the sake of correction, the problem is logged in our issue tracking system as PDFNEWJAVA-34362. We
will investigate this issue in details and will keep you updated on the status
of a correction. We
apologize for your inconvenience.

[Java]

com.aspose.pdf.Document
doc =
new
com.aspose.pdf.Document(
“c:/pdftest/result.pdf”);<o:p></o:p>

System.out.println(doc.getPages().get_Item(1).getPageInfo().isLandscape());

doc.getPages().get_Item(1).getPageInfo().setLandscape(true);

doc.save("c:/pdftest/LandScapeOutput.pdf");

Hi,

Is there any update on this ?
We are using latest aspose PDF version 9.3.1 and we still have this issue.

Hi,


Thanks for using our API.

As shared in earlier post, the API is having some issue while setting page orientation and problem has already been logged in our issue tracking system. The development team will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are apologize for this inconvenience.

I am having a similar issue in .NET, does this issue exist for .NET as well?


Hi,

Do we have any SLA for this issue. We are moving to production soon. We need to see whether it can be fixed prior to that.

hapyfishrmn:
I am having a similar issue in .NET, does this issue exist for .NET as well?
Hi,

Thanks for contacting support.

Aspose.Pdf for .NET is also having similar issue and for the sake of correction, we already have logged it as PDFNEWNET-36115 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Please note that Aspose.Pdf for Java is ported from Aspose.Pdf for .NET, so this problem will first be fixed in Aspose.Pdf for .NET and same fix will be ported to Aspose.Pdf for Java.
nielsenusa:
Do we have any SLA for this issue. We are moving to production soon. We need to see whether it can be fixed prior to that.
Hi,

Currently this issue has low priority and will be fixed as per its schedule. However I has shared your concerns with development team and as soon as we have some further updates, we will let you know.

Your patience and comprehension is greatly appreciated in this regard.

The issues you have found earlier (filed as PDFNEWNET-36115) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(4)

Hi Diane,


As stated above your reported issue is resolved in Aspose.Pdf for .NET 9.6.0. Please note Rotation property changes orientation of entire page including its contents. In order to change page size you can set MediaBox of the page in the following way.

Document doc = new Document(“PdfWithText.pdf”);<o:p></o:p>

foreach (Page page in doc.Pages)<o:p></o:p>

{<o:p></o:p>

Aspose.Pdf.Rectangle r = page.MediaBox;<o:p></o:p>

double newHeight = r.Width;<o:p></o:p>

double newWidth = r.Height;<o:p></o:p>

double newLLX = r.LLX;<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.LLY + (r.Height - newHeight);<o:p></o:p>

page.MediaBox = new 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.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);<o:p></o:p>

}<o:p></o:p>

doc.Save(“36115.pdf”);<o:p></o:p>


Please note that in that case you can cut some contents of the document (because we decrease height)
in order to avoid this you can increase width proportionally and leave height intact as following:

Aspose.Pdf.Rectangle r = page.MediaBox;<o:p></o:p>

//new height the same<o:p></o:p>

double newHeight = r.Height;<o:p></o:p>

//new width is expanded proportionally to make orientation landscape (we assume that previous orientation is portrait)<o:p></o:p>

double newWidth = r.Height * r.Height / r.Width;<o:p></o:p>


Other option is to use PdfPageEditor facade (it can apply zoom to page contents)


Document doc = new Document(“PdfWithText.pdf”);<o:p></o:p>

Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;<o:p></o:p>

PdfPageEditor ppe = new PdfPageEditor();<o:p></o:p>

ppe.BindPdf(“PdfWithText.pdf”);<o:p></o:p>

ppe.Zoom = (float)(r.Width / r.Height);<o:p></o:p>

ppe.PageSize = new Aspose.Pdf.PageSize((float)r.Height, (float)r.Width);<o:p></o:p>

ppe.Save(“36115-1.pdf”);<o:p></o:p>

We will share Java code for the purpose with you soon.


Best Regards,

Does the isLandscape (.NET) / setLandscape (Java) have any function for actually setting the orientation of the page?


hapyfishrmn:
Does the isLandscape (.NET) / setLandscape (Java) have any function for actually setting the orientation of the page?
Hi,

Thanks for contacting support.

Yes your understanding is correct. The property in .NET and method in Java perform same operation. Please try using our API's and the event of any further query, please feel free to contact.

Thank you for the update. I am using the latest build of 9.6 and tried your original response using the isLandscape() and found it not changing the document from portrait to landscape.


Aspose.Pdf.Document doc = new Aspose.Pdf.Document(“c:/test/Portrait.pdf”);
doc.Pages[1].PageInfo.IsLandscape = true;
doc.Save(“c:/test/Landscape.pdf”);

Is there something I am missing?

Hi,


We are sorry for the inconvenience caused. Please note IsLandscape property works if you are creating a PDF document from scratch. However for changing orientation of existing PDF page, please use above suggested options. Please feel free to contact us for any further assistance.

Best Regards,

Hi,

Suggested options above for landscape issue is given only for dot net. We are looking for a java solution. Can you please help.

Hi Diane,


Thanks for your inquiry. Please note Aspose.Pdf for Java is migrated from Aspose.Pdf for .NET and Java code is analogous. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

Document doc = new Document(“PdfWithText.pdf”);<o:p></o:p>

for (int pageCount = 1; pageCount <= doc.getPages().size(); pageCount++)

{

Page page= doc.getPages().get_Item(pageCount);

com.aspose.pdf.Rectangle r = page.getMediaBox();

double newHeight = r.getWidth();

double newWidth = r.getHeight() * r.getHeight() / r.getWidth();

double newLLX = r.getLLX();

//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.

double newLLY = r.getLLY() + (r.getHeight() - newHeight);

page.setMediaBox(new com.aspose.pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));

//sometimes we also need to set CropBox (if it was set in original file)

page.setCropBox(new com.aspose.pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));

}

doc.save("36115.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Hi,


we are actually editing the existing PDF which is portrait mode. The code snippet shared is not changing the layout alone instead its crops the page and renders it in the landscape mode

Hi Diane,


Thanks for your feedback. Please use PdfPageEditor, it will help you to change the page orientation without truncating page data. Hopefully it will help you to accomplish the task.

Document doc = new Document(myDir+“ipnut.pdf”);<o:p></o:p>

com.aspose.pdf.Rectangle r = doc.getPages().get_Item(1).getRect();

PdfPageEditor ppe = new PdfPageEditor();

ppe.bindPdf(doc);

ppe.setZoom((float)(r.getWidth() / r.getHeight()));

ppe.setPageSize(new com.aspose.pdf.PageSize((float)r.getHeight(), (float)r.getWidth()));

ppe.save(myDir+"output_ppe.pdf");


Please feel free to contact us for any further assistance.


Best Regards,