Articles in this section
Category / Section

How to create a PDF with different page sizes in C# and VB.NET?

2 mins read

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:

  1. Create a new C# console application project. Title: Create a console application project
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. Title: NuGet reference
  3. Including the following namespace in the Program.cs file.

C#

using Syncfusion.Pdf;

 

VB.NET

Imports Syncfusion.Pdf

 

  1. 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 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.

 

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 .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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied