Articles in this section
Category / Section

How to create multicolumn PDF in C# and VB.NET

8 mins read

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.

Using this library, you can create a multicolumn PDF in C# and VB.NET.

Steps to create a multicolumn PDF programmatically in C#:

  1. Create a new C# console application project.

Create a console application in visula studio.

  1. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.

Refer NuGet package to the project

  1. Include the following namespace in Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System;
using System.Drawing;

 

VB.NET

Imports System.Drawing
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics

 

  1. You can draw the text on a PDF document, in either single column or multicolumn using Draw method of PdfTextElement.
  1. Draw text on a PDF document in single column.

C#

// Draw the text in single column
textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));

 

VB.NET

'Draw the text in single column
textElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height))

 

  1. Simple logic to draw text on a PDF document in two columns is to divide the width.

C#

// Draw the text in first column
textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width / 2, page.GetClientSize().Height));
 
// Draw the text in second column
textElement.Draw(page, new RectangleF(page.GetClientSize().Width / 2, 0, page.GetClientSize().Width / 2, page.GetClientSize().Height));

 

VB.NET

'Draw the text in first column
textElement.Draw(page, New RectangleF(0, 0, (page.GetClientSize().Width / 2), page.GetClientSize().Height))
 
'Draw the text in second column
textElement.Draw(page, New RectangleF((page.GetClientSize().Width / 2), 0, (page.GetClientSize().Width / 2), page.GetClientSize().Height))

 

  1. Logic to draw the text on a PDF document in multicolumn is,

C#

// Get number of columns
Console.WriteLine("Enter number of columns : ");
int n = Convert.ToInt16(Console.ReadLine());
 
for (int i = 0; i < n; i++)
{
    // Draw the text
    textElement.Draw(page, new RectangleF(i * page.GetClientSize().Width / n, 0, page.GetClientSize().Width / n,  page.GetClientSize().Height));
}

 

VB.NET

'Get number of columns
Console.WriteLine("Enter number of columns : ")
Dim n As Integer = Convert.ToInt16(Console.ReadLine)
 
Dim i As Integer
For i = 0 To n - 1 Step 1
    'Draw the text
    textElement.Draw(page, New RectangleF((i * (page.GetClientSize().Width / n)), 0, (page.GetClientSize().Width / n), page.GetClientSize().Height))
Next

 

  1. Include the following code snippet in main method of Program.CS file, to create a multicolumn PDF document.

C#

// Create a new PDF document
PdfDocument document = new PdfDocument();
 
// Add a page to the document
PdfPage page = document.Pages.Add();
 
// Create PDF Graphics for the page
PdfGraphics graphics = page.Graphics;
 
// Set the standard font
PdfFont standardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
 
// Load the text into PdfTextElement
PdfTextElement textElement = new PdfTextElement("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.", standardFont);
 
// Get number of columns
Console.WriteLine("Enter number of columns : ");
int n = Convert.ToInt16(Console.ReadLine());
 
for (int i = 0; i < n; i++)
{
    // Draw the text
    textElement.Draw(page, new RectangleF(i * page.GetClientSize().Width / n, 0, page.GetClientSize().Width / n, page.GetClientSize().Height));
}
 
// Save the PDF document
document.Save("MultiColumnPDF.pdf");
 
// Close the instance of PdfDocument
document.Close(true);

VB.NET

'Create a new PDF document
Dim document As PdfDocument = New PdfDocument
 
'Add a page to the document
Dim page As PdfPage = document.Pages.Add
 
'Create PDF Graphics for the page
Dim graphics As PdfGraphics = page.Graphics
 
'Set the standard font
Dim standardFont As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
 
'Load the text into PdfTextElement
Dim textElement As PdfTextElement = New PdfTextElement(("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base."))), standardFont)
 
'Get number of columns
Console.WriteLine("Enter number of columns : ")
Dim n As Integer = Convert.ToInt16(Console.ReadLine)
 
Dim i As Integer
For i = 0 To n - 1 Step 1
    'Draw the text
    textElement.Draw(page, New RectangleF((i * (page.GetClientSize().Width / n)), 0, (page.GetClientSize().Width / n), page.GetClientSize().Height))
Next
 
'Save the PDF document
document.Save("MultiColumnPDF.pdf")
 
'Close the instance of PdfDocument
document.Close(True)

 

A complete work sample to create a multicolumn PDF document can be downloaded from MultiColumnPDF.zip.

By executing the program, you will get a console window asking for number of columns. Console window

On entering the number of columns as 5, you will get the PDF document with text in 5 columns as follows.

Multi Column PDF

Take a moment to peruse the documentation, where you will find other options like drawing right-to-left text and multicolumn text, consuming TrueType fonts, Standards fonts, CJK fonts. Also, the features like PDF form filling, extract text or images from PDFprotect PDF documents with code examples.

Refer here to explore the rich set of Syncfusion Essential&reg; PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion&reg; assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion&reg; license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how to create multicolumn PDF in C# and VB.NET.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF 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!

 

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