This demo uses the DevExpress PDF Document API (PdfDocumentProcessor) to rotate and resize PDF pages. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Specify the rotation angle, new page size, and Page Range Settings. Click the Modify Pages button to update the document and download the result.
Select a Document
Sample_Main.pdf
Page Range Settings
using DevExpress.Pdf;
Stream RotateResizePages(Stream documentStream, IEnumerable<int> pageRange, int rotate, PdfRectangle pageSize) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
if (!pageRange.Any())
pageRange = Enumerable.Range(0, processor.Document.Pages.Count);
foreach (var index in pageRange) {
if (index < 0 || index >= processor.Document.Pages.Count)
continue;
var page = processor.Document.Pages[index];
page.Resize(pageSize, PdfContentHorizontalAlignment.Center, PdfContentVerticalAlignment.Center);
page.Rotate = rotate;
}
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
return outputStream;
}