PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.
- How to use a system font for rendering text
- Customize the GUI interaction of a radio button
- Customize the UI interaction of a check box
- How to reduce PDF file size
- Draw interactively on a PDF page
- How do I use PDFControls.NET in a WPF application
- Flatten PDF form
- Digitally sign a PDF form in C# or VB.NET
- C# render pdf in browser using MVC
- Add hyperlink to PDF
- Rotate a PDF page
- Change the formatting of a numeric field
- Override MouseWheel event
- How to create a thumbnail viewer
- EMF to PDF as vector image
- Create a text annotation in PDF with rich text
- Read and write meta data from PDF
- Use multiple licenses
Rotate a PDF page
This code sample creates a copy of a PDF document with each page rotated 90 degrees. Note that you can rotate each page to a custom angle.
using (FileStream inFile = new FileStream(@"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
// open the source document
Document documentIn = new Document(inFile);
// create the target document
Document documentOut = new Document();
// enumerate the pages in the source document
foreach (Page inputPage in documentIn.Pages)
{
// append a rotated version of the original page to the target document
// create a new page that has the width and height swapped
Page page = new Page(inputPage.Height, inputPage.Width);
// because the pageShape rotates clockwise with the rotation point at the lower left
// corner, we must apply a translation in order to get the page in view again
PageShape pageShape = new PageShape(inputPage, 0, inputPage.Width, inputPage.Width, inputPage.Height, true, 90, PageBoundary.Default);
page.VisualOverlay.Add(pageShape);
documentOut.Pages.Add(page);
}
// write the target document to disk
using (FileStream outFile = new FileStream(@"..\..\rotatepage.pdf", FileMode.Create, FileAccess.Write))
{
documentOut.Write(outFile);
}
Using inFile As New FileStream("..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
' open the source document
Dim documentIn As New Document(New BinaryReader(inFile))
' create the target document
Dim documentOut As New Document()
For i As Integer = 0 To documentIn.Pages.Count - 1
' enumerate the pages in the source document
' append a rotated version of thew original page to the target document
' create a new page that has the width and height swapped
Dim page As New Page(documentIn.Pages(i).Height, documentIn.Pages(i).Width)
' because the pageShape rotates clockwise with the rotation point at the lower left
' corner, we must apply a translation in order to get the page in view again
Dim pageShape As New PageShape(documentIn.Pages(i), 0, page.Height, page.Height, page.Width, True, _
90, PageBoundary.[Default])
page.VisualOverlay.Add(pageShape)
documentOut.Pages.Add(page)
Next
' write the target document to disk
Using outFile As New FileStream("..\..\rotatepage.pdf", FileMode.Create, FileAccess.Write)
documentOut.Write(New BinaryWriter(outFile))
End Using
End Using

Download PDFControls.NET 3.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download
We have sent an email with a download link.