In today's world, working with PDF files has become an integral part of daily activities in both business and personal life. It is often necessary not only to create, but also to edit PDF documents, including their rotation. In this article, we will look at how to rotate pages in a PDF document using the Sautinsoft PDF .Net library in C# and .NET.
This can be useful for:Complete code
using System;
using SautinSoft.Pdf;
using System.IO;
using SautinSoft.Pdf.Content;
using System.Drawing;
using System.Runtime.CompilerServices;
namespace Sample
{
class Program
{
/// <remarks>
/// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/rotate-pdf.php
/// </remarks>
static void Main()
{
// Before starting this example, please get a free trial key:
// https://sautinsoft.com/start-for-free/
// Apply the key here:
// PdfDocument.SetLicense("...");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
// Rotate page content
page.Rotate = 0;
// Rotate page view: Landscape or Portrait.
page.SetMediaBox(page.Size.Height, page.Size.Width);
var formattedText1 = new PdfFormattedText();
var text1 = "Hello World";
formattedText1.FontSize = 15;
formattedText1.FontFamily = new PdfFontFamily("Calibri");
formattedText1.Append(text1);
page.Content.DrawText(formattedText1, new PdfPoint(200, 400));
document.Save("Output.pdf");
}
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("Output.pdf") { UseShellExecute = true });
}
}
}
Option Infer On
Imports System
Imports SautinSoft.Pdf
Imports System.IO
Imports SautinSoft.Pdf.Content
Imports System.Drawing
Imports System.Runtime.CompilerServices
Namespace Sample
Friend Class Program
''' <remarks>
''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/rotate-pdf.php
''' </remarks>
Shared Sub Main()
' Before starting this example, please get a free trial key:
' https://sautinsoft.com/start-for-free/
' Apply the key here:
' PdfDocument.SetLicense("...");
Using document = New PdfDocument()
Dim page = document.Pages.Add()
' Rotate page content
page.Rotate = 0
' Rotate page view: Landscape or Portrait.
page.SetMediaBox(page.Size.Height, page.Size.Width)
Dim formattedText1 = New PdfFormattedText()
Dim text1 = "Hello World"
formattedText1.FontSize = 15
formattedText1.FontFamily = New PdfFontFamily("Calibri")
formattedText1.Append(text1)
page.Content.DrawText(formattedText1, New PdfPoint(200, 400))
document.Save("Output.pdf")
End Using
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("Output.pdf") With {.UseShellExecute = True})
End Sub
End Class
End Namespace
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: