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

Free Support Forum - aspose.com

How to check and set the orientation of the pdf pages

HI,

I am creating a bulk PDF which contains some set of PDF documents, in that some of the documents will be scanned documents. So if we scan reverse, they will appear in rotation of 90 or 270. I have make everything in it to look correct.

Can you please send me some sample code with example to check if the PDF is in rotation of 90 or 270 and rotate it to view corretly.

Thanks for your help.

Hi Smita,

Thanks for using our products.

You may check the following documentation link for details and code snippets as per your requirement.

Working with Page Rotation

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Hi,

Please find the below code which i tried, but it is giving the PDF error while reading it from mail.

bytes = onBaseDocumentData.DocumentData;

mergedDocumentStream = new MemoryStream(bytes);

mergedDocumentStream = FlattenFieldsOfXfaForm(mergedDocumentStream);

pageEditor.BindPdf(mergedDocumentStream);

pageEditor.Rotation = 90;

pageEditor.Save(mergedDocumentStream);

//Store all input streams in an Array

Stream[] inStreams = new Stream[] { mergedCorrespondence, mergedDocumentStream };

// concatenate the two documents into one memory stream

pdfEditor.Concatenate(inStreams, correspondenceWithDocument);

Please help me on this...

Thanks

Hi Smita,

Thank you for sharing the sample code.

I tried to replicate your issue but unable to reproduce the problem at my end. However, to exactly replicate your issue at our end, we would appreciate it, if you create a sample application and post here to show us the issue. This will help us to regenerate the issue and reply back to you soon.

We apologize for your inconvenience.

Thanks & Regards,

Hi,

I am able to rotate it to 270 degrees. But before that i need to check the angle and rotate it. Now I am using the below code

mergedDocumentStream = FlattenFieldsOfXfaForm(mergedDocumentStream);

pageEditor.BindPdf(mergedDocumentStream);

int pdfPages = pageEditor.GetPages();

double pdfWidth = pageEditor.GetPageSize(1).Width;

double pdfHeight = pageEditor.GetPageSize(1).Height;

if (pdfWidth > pdfHeight)

{

pageEditor.Rotation = 270;

pageEditor.Save(mergedDocumentStream);

mergedDocumentStream.Position = 0;

}

But it will change it to potrait if it is in lanscape. But if the document is scanned reverse direction. I need to make it correcly.

I tried with

pageEditor.GetPageRotation(1);

But everytime it is showing the value as '0'

Please advice me.

Thanks!

Hi Smita,

Thank you for sharing the updated sample code.

I tried to replicate your issue again with updated code but unable to reproduce the problem at my end because source is not available to create the same mergedDocumentStream. However, to exactly replicate your issue at our end, we would appreciate, if you create a sample application and post here to show us the issue. This will help us to regenerate the issue and reply back to you soon.

We are very sorry for the inconvenience.

Thanks & Regards,

Hi,

I am able to rotate the PDF when it is scanned horizontally. I am able to rotate it to 270 degrees and make it to show correctly like below.

if (pdfWidth > pdfHeight)

{

pageEditor.Rotation = 270;

pageEditor.Save(mergedDocumentStream);

mergedDocumentStream.Position = 0;

}

So I am checking here, if the width is more than height.. it works

But when some one scanned totally reverse like up and down , in that case height will be more than width.. My code will not rotate in that case.

Please suggest me how to check in that case.. send me some sample code.

Thanks!

Hi Smita,

Thanks for your feedback.

I think you can use else condition for the case pdfHeight greater than the pdfWidth like below:

if (pdfWidth > pdfHeight)
{
pageEditor.Rotation = 270;

pageEditor.Save(mergedDocumentStream);

mergedDocumentStream.Position = 0;
}

else if (pdfHeight > pdfWidth)
{
// Write Code Here.
}

Moreover, you can split the pages using streams and check the pageWidth and pageHeight of each page individualy and rotate according to your requirement. Please see the following documentation link for your reference and check if it fits your need.

Split PDF to Individual Pages Using Streams (Facades)

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Hi,

Sorry, I think you did'nt understand my question properly.

pdfheight > pdf width will happen in two cases.

When PDF is properly shown in correct orientation (ex: up and down.) and when it is shown completely reverse. (like down and up)

In pdfheight > pdfWidth case.

1) If it is showing properly in correct orienation, I need not rotate it.

3) If it completely reverse, I should able to rotate it to up and down.

I hope you understood my above scenario.

Please let me know how can i handle this cases

Thanks!

Hi Smita,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

As I understand your issue, if the page is scanned reverse, then you are facing the problem in rotating it because the height will be greater than width and page will not get rotated as per your code. Well, I don’t think we can identify such a scenario because logically we cannot know whether a page was scanned in reverse. If my understanding is not right, please share some template PDF to show the issue, we will check that and reply to you.

Thank You & Best Regards,