I am trying to create a landscape PDF document 11 X 8.5 using the following code. The resulting file is attached and size is 8.26 x 11.69
Hi Thaddeus,
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();<o:p></o:p>
pdfDocument.Pages.Add();<o:p></o:p>
// pdfDocument.PageInfo.IsLandscape = true;<o:p></o:p>
Aspose.Pdf.Rectangle r = pdfDocument.Pages[1].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 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 lower edge upper based on difference between old and new height.<o:p></o:p>
double newLLY = r.LLY + (r.Height - newHeight);<o:p></o:p>
pdfDocument.Pages[1].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>
pdfDocument.Pages[1].CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);<o:p></o:p>
pdfDocument.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;<o:p></o:p>
pdfDocument.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;<o:p></o:p>
string sLine =@“123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz”;<o:p></o:p>
sLine = @“REPORT: KL0142BC ------ GE CAPITAL ------ PAGE: 11”;<o:p></o:p>
TextStamp textStamp = new TextStamp(sLine);<o:p></o:p>
textStamp.YIndent = 50;// pdfDocument.PageInfo.Height - 200;<o:p></o:p>
textStamp.XIndent = 10;<o:p></o:p>
textStamp.TextState.FontSize = 10;<o:p></o:p>
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Regular;<o:p></o:p>
textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont(@“Arial”);<o:p></o:p>
pdfDocument.Pages[1].AddStamp(textStamp);<o:p></o:p>
pdfDocument.Save(@“C:\pdftest\landscape.pdf”);
Given the sample code above I still don’t understand how to determine the textStamp.YIndent so I can print the first line on the top of the page.
Thaddeus:Given the sample code above I still don’t understand how to determine the textStamp.YIndent so I can print the first line on the top of the page.
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();<o:p></o:p>
pdfDocument.Pages.Add();
// pdfDocument.PageInfo.IsLandscape = true;
Aspose.Pdf.Rectangle r = pdfDocument.Pages[1].MediaBox;
//new height the same
double newHeight = r.Height;
//new width is expanded proportionally to make orientation landscape
//(we assume that previous orientation is portrait)
double newWidth = r.Height * r.Height / r.Width;
// double newHeight = r.Width;
// double newWidth = r.Height;
double newLLX = r.LLX;
//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.LLY + (r.Height - newHeight);
pdfDocument.Pages[1].MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
//sometimes we also need to set CropBox (if it was set in original file)
pdfDocument.Pages[1].CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
pdfDocument.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;
pdfDocument.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;
string sLine = @"123456789012345678901234567890123456789012345678901234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz";
// sLine = @"REPORT: KL0142BC ------ GE CAPITAL ------ PAGE: 11";
TextStamp textStamp = new TextStamp(sLine);
textStamp.YIndent = pdfDocument.PageInfo.Height - 10;
textStamp.XIndent = 10;
textStamp.TextState.FontSize = 10;
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Regular;
textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont(@"Arial");
pdfDocument.Pages[1].AddStamp(textStamp);
pdfDocument.Save(@"C:\pdftest\landscape.pdf");
Hi Thaddeus,Thaddeus:oddityin the sample code the following line does not correctly assign the lly value to MediaBox?pdfDocument.Pages[1].MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);I even tried changing the line of code to the followingpdfDocument.Pages[1].MediaBox = new Aspose.Pdf.Rectangle(10, 10, 200, 200);after this assignment statement did not change the value of pdfDocument.Pages[1].MediaBox?I stepped in the debugger to examine this?
Document doc = new Document(“PdfWithText.pdf”);<o:p></o:p>
Rectangle r = doc.Pages[1].Rect;
PdfPageEditor ppe = new PdfPageEditor();
ppe.BindPdf("PdfWithText.pdf");
ppe.Zoom = (float) (r.Width / r.Height);
ppe.PageSize = new PageSize((float)r.Height, (float)r.Width);
ppe.Save("36115-1.pdf");
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
pdfDocument.Pages.Add();
// pdfDocument.PageInfo.IsLandscape = true;
Aspose.Pdf.Rectangle r = pdfDocument.Pages[1].MediaBox;
//new height the same
double newHeight = r.Height;
//new width is expanded proportionally to make orientation landscape
//(we assume that previous orientation is portrait)
double newWidth = r.Height * r.Height / r.Width;
Hi Thaddeus,
Document doc = new Document(@“C:\pdftest\landscape\landscape.pdf”);<o:p></o:p>
Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;
Aspose.Pdf.Facades.PdfPageEditor ppe = new Aspose.Pdf.Facades.PdfPageEditor();
ppe.BindPdf(@"C:\pdftest\landscape\landscape.pdf");
ppe.Zoom = (float)(r.Width / r.Height);
ppe.PageSize = new PageSize((float)r.Height, (float)r.Width);
ppe.Save(@“C:\pdftest\landscape\landscape_36115-1.pdf”);
I think we have a misunderstanding of my problem. I do not have an existing portrait pdf that I want to change to landscape. I am creating a NEW pdf document. I would like this pdf document to be landscape 11x8.5.
Hi Thaddeus,
Document doc = new Document();<o:p></o:p>
doc.Pages.Add();
Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;<o:p></o:p>
Aspose.Pdf.Facades.PdfPageEditor ppe = new Aspose.Pdf.Facades.PdfPageEditor();<o:p></o:p>
ppe.BindPdf(@“C:\pdftest\landscape\landscape.pdf”);<o:p></o:p>
ppe.Zoom = (float)(r.Width / r.Height);<o:p></o:p>
ppe.PageSize = new PageSize((float)r.Height, (float)r.Width);<o:p></o:p>
ppe.Save(@“C:\pdftest\landscape\landscape_36115-1.pdf”);ppe.BindPdf(@“C:\pdftest\landscape\landscape.pdf”);
Hi Thaddeus,Thaddeus:ppe.BindPdf(@“C:\pdftest\landscape\landscape.pdf”);Where do I get this file? I get file not found when I execute this code sample?
Document doc = new
Document();<o:p></o:p>
doc.Pages.Add();
Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;
MemoryStream ms = new MemoryStream();
doc.Save(ms);
Aspose.Pdf.Facades.PdfPageEditor ppe = new Aspose.Pdf.Facades.PdfPageEditor();
ppe.BindPdf(ms);
ppe.Zoom = (float)(r.Width / r.Height);
ppe.PageSize = new Aspose.Pdf.PageSize((float)r.Height, (float)r.Width);
ppe.Save(@"C:\pdftest\landscape_36115-1.pdf");
ms.Close();
the document size is not letter. The results of your last sample returns a document
Thaddeus:the document size is not letter. The results of your last sample returns a document11.69 X 8.26.My last sample code returns the same page size for letter, legal and 11x17.Hi Thaddeus,Thanks for sharing the details.When using earlier shared code snippet, the dimensions of page are changed so that it appears as Landscape and as you are aware, for landscape page, the width of page is greater than height. Also please note that in order to set page size as Letter (8.50 × 11.00 inches) and in Aspose.Pdf, 1 inch = 72 points, so Letter dimensions in points will be (612, 792) points.You can post queries in Priority Support forum anytime. However usually customers raise the issues/bugs in Priority Support forum in order to expedite the investigation/resolution of their reported problems.Thaddeus:My company has an account with priority support, should I enter this problem in a priority ticket. I really need to get this resolved for one our customers.
" so Letter dimensions in points will be (612, 792) points."
Hi Thaddeus,
Document doc = new
Document();<o:p></o:p>
doc.Pages.Add();
Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;
MemoryStream ms = new MemoryStream();
doc.Save(ms);
Aspose.Pdf.Facades.PdfPageEditor ppe = new Aspose.Pdf.Facades.PdfPageEditor();
ppe.BindPdf(ms);
ppe.Zoom = (float)(r.Width / r.Height);
ppe.PageSize = new Aspose.Pdf.PageSize(612, 792);//, (float)r.Width);
ppe.Save(@"C:\pdftest\landscape_36115-1.pdf");
ms.Close();