How to create a PDF with different page sizes in C# and VB.NET?
Syncfusion Essential® PDF is a .NET PDF Library used to create, read, and edit PDF documents. Using this library, you can create a PDF document with different page sizes.
Steps to create a PDF document with different page sizes programmatically:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
- Including the following namespace in the Program.cs file.
C#
using Syncfusion.Pdf;
VB.NET
Imports Syncfusion.Pdf
- Use the following code snippet to create a PDF document with different page size.
C#
//Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page with A5 size PdfSection section1 = document.Sections.Add(); section1.PageSettings.Size = PdfPageSize.A5; PdfPage page1 = section1.Pages.Add(); //Add a page with A3 size PdfSection section2 = document.Sections.Add(); section2.PageSettings.Size = PdfPageSize.A3; PdfPage page2 = section2.Pages.Add(); //Save and close the document document.Save("Output.pdf"); document.Close(true); //This will open the PDF file so, the result will be seen in default PDF viewer Process.Start("Output.pdf");
VB.NET
'Create a new PDF document Dim document As PdfDocument = New PdfDocument() 'Add a page with A5 size Dim section1 As PdfSection = document.Sections.Add() section1.PageSettings.Size = PdfPageSize.A5 Dim page1 As PdfPage = section1.Pages.Add() 'Add a page with A3 size Dim section2 As PdfSection = document.Sections.Add() section2.PageSettings.Size = PdfPageSize.A3 Dim page2 As PdfPage = section2.Pages.Add() 'Save and close the document document.Save("Output.pdf") document.Close(True) 'This will open the PDF file so, the result will be seen in default PDF viewer Process.Start("Output.pdf")
A complete working sample can be download from PDFSample.zip.
Take a moment to peruse the documentation for working with pages, where you can find the options like inserting, rotating, importing, and rearranging the pages from an existing document, removing the pages and splitting a PDF file to individual pages.
Refer here to explore the rich set of Syncfusion Essential® PDF features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion:
I hope you enjoyed learning about how to create a PDF with different page sizes in C# and VB.NET.
You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!