diff --git a/README.md b/README.md index 40c0779..1672d15 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,196 @@ -# rotating-a-PDF-document-using-csharp -This repository contains examples for rotating a PDF page, text, table and image in PDF document using C# +# Rotating a PDF using .Net Console + +The [Syncfusion PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library) provides support to rotating a PDF document. The library also provides APIs for changing the orientation of a PDF document by a specified degree. + +This article will cover the process to rotate a page, text, image and table from a PDF document using the Syncfusion .NET PDF library. The topics related to this will be discussed in the following sections of this post: + +Name | Description +--- | --- +[Rotating a page in PDF](https://github.com/SyncfusionExamples/rotating-a-PDF-document-using-csharp/master/RotatePDFPage) | It means changing the orientation of the page by a specified degree. +[Rotating a text in PDF](https://github.com/SyncfusionExamples/rotating-a-PDF-document-using-csharp/master/RotatePDFText) | It means changing the orientation of the text by a specified degree. +[Rotating an image in PDF](https://github.com/SyncfusionExamples/rotating-a-PDF-document-using-csharp/master/RotatePDFImage) | It means changing the orientation of the image by a specified degree. +[Rotating a Table in PDF](https://github.com/SyncfusionExamples/rotating-a-PDF-document-using-csharp/master/RotatePDFTable) | It means changing the orientation of the table by a specified degree. + + + +## Rotating a page in PDF using C# + +Rotating a PDF page means changing the orientation of the page by a specified degree. + +The following code example shows how to rotate a page to a PDF file using C#. + +```csharp +//Load PDF document as stream. +FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Load the existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +for (int i = 0; i < loadedDocument.PageCount; i++) +{ + //Gets the page. + PdfPageBase loadedPage = loadedDocument.Pages[i] as PdfPageBase; + //Set the rotation for loaded page. + loadedPage.Rotation = PdfPageRotateAngle.RotateAngle90; +} +//Create the filestream to save the PDF document. +using(FileStream fileStream = new FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite)) +{ +loadedDocument.Save(fileStream); +} +//Close the document. +loadedDocument.Close(true); +``` +By executing this code example, you will get a PDF document like the following screenshot. + +Add attachment output + + +## Rotating a text in PDF using C# + +Rotating a PDF text means changing the orientation of the text by a specified degree. + +The following code example shows how to rotate a text to a PDF file using C#. + +```csharp +//Create a new PDF document. +PdfDocument pdfDocument = new PdfDocument(); +//Add a page to the PDF document. +PdfPage pdfPage = pdfDocument.Pages.Add(); +//Create PDF graphics for the page. +PdfGraphics graphics = pdfPage.Graphics; +//Set the font. +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); +//Add watermark text. +PdfGraphicsState state = graphics.Save(); +graphics.RotateTransform(-40); +graphics.DrawString("Rotating a text in PDF document", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); + +//Create the filestream to save the PDF document. +FileStream fileStream = new FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +pdfDocument.Save(fileStream); +//Close the document. +pdfDocument.Close(true); +``` +By executing this code example, you will get a PDF document like the following screenshot. + +Add attachment output + +## Rotating an image in PDF using C# + +Rotating a PDF image means changing the orientation of the image by a specified degree. + +The following code example shows how to rotate an image to a PDF file using C#. + +```csharp +//Created the PDF document. +PdfDocument document = new PdfDocument(); +//Add a new page +PdfPage page = document.Pages.Add(); +FileStream imageStream = new FileStream("Input.png", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Load a bitmap +PdfBitmap image = new PdfBitmap(imageStream); +//save the current graphics state +PdfGraphicsState state = page.Graphics.Save(); +//Rotate the coordinate system +page.Graphics.RotateTransform(-40); +//Draw image +image.Draw(page, -150, 450); +//Restore the graphics state +page.Graphics.Restore(state); + +//Create the filestream to save the PDF document. +FileStream fileStream = new FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +document.Save(fileStream); +//Close the document. +document.Close(true); +``` +By executing this code example, you will get a PDF document like the following screenshot. + +Add attachment output + +## Rotating a table in PDF using C# + +Rotating a PDF table means changing the orientation of the table by a specified degree. + +The following code example shows how to rotate an table to a PDF file using C#. + +```csharp +//Create a new PDF document. +PdfDocument document = new PdfDocument(); +//Add a page. +PdfPage page = document.Pages.Add(); +//Create a PdfGrid. +PdfGrid pdfGrid = new PdfGrid(); +//Add a handler to rotate the table. +pdfGrid.BeginPageLayout += PdfGrid_BeginPageLayout; +//Create a DataTable. +DataTable dataTable = new DataTable(); + +//Add columns to the DataTable. +dataTable.Columns.Add("ID", typeof(int)); +dataTable.Columns.Add("Name", typeof(string)); +dataTable.Columns.Add("Type", typeof(string)); +dataTable.Columns.Add("Date", typeof(DateTime)); +//Add rows to the DataTable. +for (int i = 0; i < 10; i++) +{ + dataTable.Rows.Add(57, "AAA", "ABC", DateTime.Now); + dataTable.Rows.Add(130, "BBB", "BCD", DateTime.Now); + dataTable.Rows.Add(92, "CCC", "CDE", DateTime.Now); +} +//Assign data source. +pdfGrid.DataSource = dataTable; +//Set a repeat header for the table. +pdfGrid.RepeatHeader = true; +//Draw a grid to the page of a PDF document. +pdfGrid.Draw(page, new RectangleF(100, 20, 0, page.GetClientSize().Width)); + +//Create the filestream to save the PDF document. +FileStream fileStream = new FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +document.Save(fileStream); +//Close the document. +document.Close(true); + + +void PdfGrid_BeginPageLayout(object sender, Syncfusion.Pdf.Graphics.BeginPageLayoutEventArgs e) +{ + PdfPage page = e.Page; + PdfGraphics graphics = e.Page.Graphics; + //Translate the coordinate system to the required position. + graphics.TranslateTransform(page.GetClientSize().Width, 0); + //Rotate the coordinate system. + graphics.RotateTransform(90); +} +``` +By executing this code example, you will get a PDF document like the following screenshot. + +Add attachment output + + +# How to run the examples +* Download this project to a location in your disk. +* Open the solution file using Visual Studio. +* Rebuild the solution to install the required NuGet package. +* Run the application. + +# Resources +* **Product page:** [Syncfusion PDF Framework](https://www.syncfusion.com/document-processing/pdf-framework/net) +* **Documentation page:** [Syncfusion .NET PDF library](https://help.syncfusion.com/file-formats/pdf/overview) +* **Online demo:** [Syncfusion .NET PDF library - Online demos](https://ej2.syncfusion.com/aspnetcore/PDF/CompressExistingPDF#/bootstrap5) +* **Blog:** [Syncfusion .NET PDF library - Blog](https://www.syncfusion.com/blogs/category/pdf) +* **Knowledge Base:** [Syncfusion .NET PDF library - Knowledge Base](https://www.syncfusion.com/kb/windowsforms/pdf) +* **EBooks:** [Syncfusion .NET PDF library - EBooks](https://www.syncfusion.com/succinctly-free-ebooks) +* **FAQ:** [Syncfusion .NET PDF library - FAQ](https://www.syncfusion.com/faq/) + +# Support and feedback +* For any other queries, reach our [Syncfusion support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). +* Request new feature through [Syncfusion feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). + +# License +This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/eula/es/?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). + +# About Syncfusion +Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies. + +Today, we provide 1600+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-webforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Angular](https://www.syncfusion.com/angular-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [React](https://www.syncfusion.com/react-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Vue](https://www.syncfusion.com/vue-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WinUI(Preview)](https://www.syncfusion.com/winui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) and [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software. + + diff --git a/RotatePDFImage/RotatePDFImage.sln b/RotatePDFImage/RotatePDFImage.sln new file mode 100644 index 0000000..aa52dda --- /dev/null +++ b/RotatePDFImage/RotatePDFImage.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RotatePDFImage", "RotatePDFImage\RotatePDFImage.csproj", "{28D64592-DB58-4678-8ABF-B203AD60B917}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {28D64592-DB58-4678-8ABF-B203AD60B917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28D64592-DB58-4678-8ABF-B203AD60B917}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28D64592-DB58-4678-8ABF-B203AD60B917}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28D64592-DB58-4678-8ABF-B203AD60B917}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E4C8BCD0-EB4C-43EF-9E6E-6816DCCB0DC6} + EndGlobalSection +EndGlobal diff --git a/RotatePDFImage/RotatePDFImage/Data/Input.jpg b/RotatePDFImage/RotatePDFImage/Data/Input.jpg new file mode 100644 index 0000000..0098b3f Binary files /dev/null and b/RotatePDFImage/RotatePDFImage/Data/Input.jpg differ diff --git a/RotatePDFImage/RotatePDFImage/Program.cs b/RotatePDFImage/RotatePDFImage/Program.cs new file mode 100644 index 0000000..0b12cc4 --- /dev/null +++ b/RotatePDFImage/RotatePDFImage/Program.cs @@ -0,0 +1,28 @@ +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +//Created the PDF document. +PdfDocument document = new PdfDocument(); +//Add a new page +PdfPage page = document.Pages.Add(); + +FileStream fileStream = new FileStream("../../../Data/input.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Load a bitmap +PdfBitmap image = new PdfBitmap(fileStream); +//save the current graphics state +PdfGraphicsState state = page.Graphics.Save(); +//Rotate the coordinate system +page.Graphics.RotateTransform(40); +//Draw image +image.Draw(page, 280, 20); +//Restore the graphics state +page.Graphics.Restore(state); + +//Create file stream. +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + //Save the PDF document to file stream. + document.Save(outputFileStream); +} +//Close the document. +document.Close(true); \ No newline at end of file diff --git a/RotatePDFImage/RotatePDFImage/RotatePDFImage.csproj b/RotatePDFImage/RotatePDFImage/RotatePDFImage.csproj new file mode 100644 index 0000000..37d5bd2 --- /dev/null +++ b/RotatePDFImage/RotatePDFImage/RotatePDFImage.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/RotatePDFPage/RotatePDFPage.sln b/RotatePDFPage/RotatePDFPage.sln new file mode 100644 index 0000000..34f61ad --- /dev/null +++ b/RotatePDFPage/RotatePDFPage.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RotatePDFPage", "RotatePDFPage\RotatePDFPage.csproj", "{A65F8D4E-A714-47B1-BA7E-13133310B306}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A65F8D4E-A714-47B1-BA7E-13133310B306}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A65F8D4E-A714-47B1-BA7E-13133310B306}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A65F8D4E-A714-47B1-BA7E-13133310B306}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A65F8D4E-A714-47B1-BA7E-13133310B306}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {94774311-868C-4067-B6FB-5068B0A22C7D} + EndGlobalSection +EndGlobal diff --git a/RotatePDFPage/RotatePDFPage/Data/Input.pdf b/RotatePDFPage/RotatePDFPage/Data/Input.pdf new file mode 100644 index 0000000..dd3a38e Binary files /dev/null and b/RotatePDFPage/RotatePDFPage/Data/Input.pdf differ diff --git a/RotatePDFPage/RotatePDFPage/Program.cs b/RotatePDFPage/RotatePDFPage/Program.cs new file mode 100644 index 0000000..475596d --- /dev/null +++ b/RotatePDFPage/RotatePDFPage/Program.cs @@ -0,0 +1,20 @@ +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf; + +FileStream inputStream = new FileStream("../../../Data/Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +//Load the existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); +//Gets the page. +PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; + +//Set the rotation for loaded page. +loadedPage.Rotation = PdfPageRotateAngle.RotateAngle90; + +//Create file stream. +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + //Save the PDF document to file stream. + loadedDocument.Save(outputFileStream); +} +//Close the document. +loadedDocument.Close(true); diff --git a/RotatePDFPage/RotatePDFPage/RotatePDFPage.csproj b/RotatePDFPage/RotatePDFPage/RotatePDFPage.csproj new file mode 100644 index 0000000..37d5bd2 --- /dev/null +++ b/RotatePDFPage/RotatePDFPage/RotatePDFPage.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/RotatePDFTable/RotatePDFTable.sln b/RotatePDFTable/RotatePDFTable.sln new file mode 100644 index 0000000..ae33e59 --- /dev/null +++ b/RotatePDFTable/RotatePDFTable.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RotatePDFTable", "RotatePDFTable\RotatePDFTable.csproj", "{52170CC2-49DA-46BB-9C3C-C8542C133CE5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {52170CC2-49DA-46BB-9C3C-C8542C133CE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52170CC2-49DA-46BB-9C3C-C8542C133CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52170CC2-49DA-46BB-9C3C-C8542C133CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52170CC2-49DA-46BB-9C3C-C8542C133CE5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8DA4A816-B8BF-493B-A013-C58EA0C37B86} + EndGlobalSection +EndGlobal diff --git a/RotatePDFTable/RotatePDFTable/Program.cs b/RotatePDFTable/RotatePDFTable/Program.cs new file mode 100644 index 0000000..66da54a --- /dev/null +++ b/RotatePDFTable/RotatePDFTable/Program.cs @@ -0,0 +1,53 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Grid; +using Syncfusion.Pdf; +using System.Data; +using Syncfusion.Drawing; + + +//Create a new PDF document. +PdfDocument document = new PdfDocument(); +//Add a page. +PdfPage page = document.Pages.Add(); +//Create a PdfGrid. +PdfGrid pdfGrid = new PdfGrid(); +//Add a handler to rotate the table. +pdfGrid.BeginPageLayout += PdfGrid_BeginPageLayout; + +//Create a DataTable. +DataTable dataTable = new DataTable(); +//Add columns to the DataTable. +dataTable.Columns.Add("ID", typeof(int)); +dataTable.Columns.Add("Name", typeof(string)); +dataTable.Columns.Add("Type", typeof(string)); +dataTable.Columns.Add("Date", typeof(DateTime)); + +//Add rows to the DataTable. +for (int i = 0; i < 10; i++) +{ + dataTable.Rows.Add(57, "AAA", "ABC", DateTime.Now); + dataTable.Rows.Add(130, "BBB", "BCD", DateTime.Now); + dataTable.Rows.Add(92, "CCC", "CDE", DateTime.Now); +} +//Assign data source. +pdfGrid.DataSource = dataTable; +//Set a repeat header for the table. +pdfGrid.RepeatHeader = true; +//Draw a grid to the page of a PDF document. +pdfGrid.Draw(page, new RectangleF(100, 20, 0, page.GetClientSize().Width)); + +//Create the filestream to save the PDF document. +FileStream fileStream = new FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite); +document.Save(fileStream); +//Close the document. +document.Close(true); + +void PdfGrid_BeginPageLayout(object sender, Syncfusion.Pdf.Graphics.BeginPageLayoutEventArgs e) +{ + PdfPage page = e.Page; + PdfGraphics graphics = e.Page.Graphics; + //Translate the coordinate system to the required position. + graphics.TranslateTransform(page.GetClientSize().Width, 0); + //Rotate the coordinate system. + graphics.RotateTransform(90); +} \ No newline at end of file diff --git a/RotatePDFTable/RotatePDFTable/RotatePDFTable.csproj b/RotatePDFTable/RotatePDFTable/RotatePDFTable.csproj new file mode 100644 index 0000000..3847ef1 --- /dev/null +++ b/RotatePDFTable/RotatePDFTable/RotatePDFTable.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/RotatePDFText/RotatePDFText.sln b/RotatePDFText/RotatePDFText.sln new file mode 100644 index 0000000..5f6da62 --- /dev/null +++ b/RotatePDFText/RotatePDFText.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RotatePDFText", "RotatePDFText\RotatePDFText.csproj", "{45361F55-B889-4367-B8BB-7F50A7D3EC2C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {45361F55-B889-4367-B8BB-7F50A7D3EC2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45361F55-B889-4367-B8BB-7F50A7D3EC2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45361F55-B889-4367-B8BB-7F50A7D3EC2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45361F55-B889-4367-B8BB-7F50A7D3EC2C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D8248CD2-F8EB-4D95-AA0F-7B2D23281794} + EndGlobalSection +EndGlobal diff --git a/RotatePDFText/RotatePDFText/Program.cs b/RotatePDFText/RotatePDFText/Program.cs new file mode 100644 index 0000000..d931bd7 --- /dev/null +++ b/RotatePDFText/RotatePDFText/Program.cs @@ -0,0 +1,26 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + +//Create a new PDF document. +PdfDocument pdfDocument = new PdfDocument(); +//Add a page to the PDF document. +PdfPage pdfPage = pdfDocument.Pages.Add(); +//Create PDF graphics for the page. +PdfGraphics graphics = pdfPage.Graphics; + +//Set the font. +PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); +//Add watermark text. +PdfGraphicsState state = graphics.Save(); +graphics.RotateTransform(-40); +graphics.DrawString("Rotating a text in PDF document", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150,450)); + +//Save the document into stream. +using (MemoryStream stream = new MemoryStream()) +{ + pdfDocument.Save(stream); + System.IO.File.WriteAllBytes("Output.pdf", stream.ToArray()); +} +//Close the document. +pdfDocument.Close(true); \ No newline at end of file diff --git a/RotatePDFText/RotatePDFText/RotatePDFText.csproj b/RotatePDFText/RotatePDFText/RotatePDFText.csproj new file mode 100644 index 0000000..3847ef1 --- /dev/null +++ b/RotatePDFText/RotatePDFText/RotatePDFText.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Screenshot/ImageOutput.png b/Screenshot/ImageOutput.png new file mode 100644 index 0000000..a949c74 Binary files /dev/null and b/Screenshot/ImageOutput.png differ diff --git a/Screenshot/PageOutput.png b/Screenshot/PageOutput.png new file mode 100644 index 0000000..e0de050 Binary files /dev/null and b/Screenshot/PageOutput.png differ diff --git a/Screenshot/TableOutput.png b/Screenshot/TableOutput.png new file mode 100644 index 0000000..a64a914 Binary files /dev/null and b/Screenshot/TableOutput.png differ diff --git a/Screenshot/TextOutput.png b/Screenshot/TextOutput.png new file mode 100644 index 0000000..15f10b4 Binary files /dev/null and b/Screenshot/TextOutput.png differ