How to Create Two Column PDF in C#, VB.NET

It's impossible to format an existing PDF document with columns due to its fixed layout. It is possible to create columns in a PDF document so that text appears as it does in a newspaper when creating PDFs from scratch.

This article presents how we can add columns of text to PDF documents by using Spire.PDF.

Step 1: Initialize an instance of PdfDocument class, add a page to it.

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Step 2: Declare and initialize two string variables.

string s1 = "Spire.PDF for .NET is a professional PDF component applied to creating, writing, "
            + "editing, handling and reading PDF files without any external dependencies within "
            + ".NET application. Using this .NET PDF library, you can implement rich capabilities "
            + "to create PDF files from scratch or process existing PDF documents entirely through "
            + "C#/VB.NET without installing Adobe Acrobat.";

string s2 = "Many rich features can be supported by the .NET PDF API, such as security setting "
            +"(including digital signature), PDF text/ attachment/ image extract, PDF merge/ split "
            +", metadata update, section, graph/ image drawing and inserting, table creation and "
            +"processing, and importing data etc.Besides, Spire.PDF for .NET can be applied to easily "
            +"converting Text, Image and HTML to PDF with C#/VB.NET in high quality.";

Step 3: Create a PdfFont instance.

PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 12f);

Step 4: Draw text of s1 in the first column.

page.Canvas.DrawString(s1, font, PdfBrushes.Black, new RectangleF(0, 20, page.GetClientSize().Width / 2 - 2f, page.GetClientSize().Height));

Step 5: Draw text of s2 in the second column.

page.Canvas.DrawString(s2, font, PdfBrushes.Black, new RectangleF(page.GetClientSize().Width / 2 + 2f, 20, page.GetClientSize().Width / 2, page.GetClientSize().Height));

Step 6: Save the file.

doc.SaveToFile("Output.pdf");

Result:

How to Create Two Column PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

string s1 = "Spire.PDF for .NET is a professional PDF component applied to creating, writing, "
            + "editing, handling and reading PDF files without any external dependencies within "
            + ".NET application. Using this .NET PDF library, you can implement rich capabilities "
            + "to create PDF files from scratch or process existing PDF documents entirely through "
            + "C#/VB.NET without installing Adobe Acrobat.";
string s2 = "Many rich features can be supported by the .NET PDF API, such as security setting "
            +"(including digital signature), PDF text/ attachment/ image extract, PDF merge/ split "
            +", metadata update, section, graph/ image drawing and inserting, table creation and "
            +"processing, and importing data etc.Besides, Spire.PDF for .NET can be applied to easily "
            +"converting Text, Image and HTML to PDF with C#/VB.NET in high quality.";

PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 12f);
page.Canvas.DrawString(s1, font, PdfBrushes.Black, new RectangleF(0, 20, page.GetClientSize().Width / 2 - 2f, page.GetClientSize().Height));
page.Canvas.DrawString(s2, font, PdfBrushes.Black, new RectangleF(page.GetClientSize().Width / 2 + 2f, 20, page.GetClientSize().Width / 2, page.GetClientSize().Height));

doc.SaveToFile("Output.pdf");
[VB.NET]
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPageBase = doc.Pages.Add()

String s1 = "Spire.PDF for .NET is a professional PDF component applied to creating, writing, "
            + "editing, handling and reading PDF files without any external dependencies within "
            + ".NET application. Using this .NET PDF library, you can implement rich capabilities "
            + "to create PDF files from scratch or process existing PDF documents entirely through "
            Dim "C#/VB.NET without installing Adobe Acrobat." As +
String s2 = "Many rich features can be supported by the .NET PDF API, such as security setting "
            + "(including digital signature), PDF text/ attachment/ image extract, PDF merge/ split "
            + ", metadata update, section, graph/ image drawing and inserting, table creation and "
            + "processing, and importing data etc.Besides, Spire.PDF for .NET can be applied to easily "
            + "converting Text, Image and HTML to PDF with C#/VB.NET in high quality."

Dim font As PdfFont = New PdfFont(PdfFontFamily.TimesRoman,12f)
page.Canvas.DrawString(s1, font, PdfBrushes.Black, New RectangleF(0, 20, page.GetClientSize().Width / 2 - 2f, page.GetClientSize().Height))
page.Canvas.DrawString(s2, font, PdfBrushes.Black, New RectangleF(page.GetClientSize().Width / 2 + 2f, 20, page.GetClientSize().Width / 2, page.GetClientSize().Height))

doc.SaveToFile("Output.pdf")