How to create a PDF with different page sizes in C# and VB.NET?
Steps to create a PDF document with different page sizes programmatically:
- Create a new C# console application project.
- Install the NuGet package as reference to your .NET Framework application from .
- Including the following namespace in the Program.cs file.
- Use the following code snippet to create a PDF document with different page size.
//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");
'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")
Take a moment to peruse the documentation for , 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.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
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 .NET PDF Library’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET PDF Library documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!