Hi,
- To change page size customer may use Page.Rect property:
Document doc = new Document(“input.pdf”); //original page is A4doc.Pages[1].Rect = new Rectangle(0, 0, 421, 595); // A5 sizedoc.Save(“output.pdf”);
But, page cropping will occurs if new page size is smaller then original page size.
- To change page orientation, customer may use Page.Rotation:
Document doc = new Document(“input.pdf”); //original page is A4
doc.Pages[1].Rotation = Rotation.on270;doc.Save(“output.pdf”);(page contents will be rotated, and page orientation became landscape if it was portrait)
- Example of PdfPageEditor usage (but page may be cropped in this case)
PdfPageEditor ppe = new PdfPageEditor();
ppe.BindPdf(“input.pdf”);PageSize ps = new PageSize(421, 595);ps.IsLandscape = true;ppe.PageSize = ps;ppe.Save(“output.pdf”);
- As mentioned in forum link, customer has some pages A3 which need to be converted as A4.
To make the code more easy, method PdfFileEditor.ContentsResizeParameters.PageResize() was added. This method requires two parameters (new page width and height)To solve this task, PdfFileEditor.ResizeContents may be used.ResizeContents(String source, String destination, int[] pages, ContentsResizeParameters parameters)source = source file name;destination = destination file name;pages = array of page number which should be converted;parameters = instance of ContentsResizeParameters. This object describes parameters of page/contents re-size.It contains size elements: new page width and height and left/right/top/bootom margins.Each of these element is ContentsResizeValue instance. ContentsResizeValue describes required resize algorithm:ContentsResizeValue.Units(value) - creates resize value specified as absolute value in PDF document default units (pixels);ContentsResizeValue.Percents(value) - creates resize value specified in percents of initial page size;ContentsResizeValue.Auto() - creates resize value which will be automatically calculated (as initial page size - explicitly defined elements).Thus, customer task may be solved in the following way:[C#]
PdfFileEditor pfe = new PdfFileEditor();
));
pfe.ResizeContents(“input.pdf”, “output.pdf”,
new int[] { 1 },
new PdfFileEditor.ContentsResizeParameters(
PdfFileEditor.ContentsResizeValue.Units(0), //left margin
PdfFileEditor.ContentsResizeValue.Units(421), //new page width - for A5
PdfFileEditor.ContentsResizeValue.Units(0), //right margin
PdfFileEditor.ContentsResizeValue.Units(0), //top margin
PdfFileEditor.ContentsResizeValue.Units(595), //new page height - for A5
PdfFileEditor.ContentsResizeValue.Units(0) //bottom margin
How about to create a new pdf Document in LandScape to begin with?
Hi Helen,
Document doc = new
Document();<o:p></o:p>
Aspose.Pdf.Page page = doc.Pages.Add();
page.PageInfo = new Aspose.Pdf.PageInfo
{
Width = Aspose.Pdf.PageSize.A4.Height,
Height = Aspose.Pdf.PageSize.A4.Width,
};
....
....
Please feel free to contact us for any further assistance.
Best Regards,