Hi,
Hi Lalitya,
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>
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>
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”);
Hi Nayyer,
Hi Lalitya,
// load source PDF file<o:p></o:p>
Document pdfDocument = new Document("c:/pdftest/4831+EBDRTransactionAmountDiffersForm.pdf");
//adds a blank page to pdf document
Page page = pdfDocument.Pages.Count > 0 ? pdfDocument.Pages[1] : pdfDocument.Pages.Add();
// get page height and width information
Console.WriteLine(page.GetPageRect(true).Width.ToString() + ":" + page.GetPageRect(true).Height);
// rotate page at 90 degree angle
page.Rotate = Rotation.on90;
// get page height and width information
Console.WriteLine(page.GetPageRect(true).Width.ToString() + “:”
- page.GetPageRect(true).Height);