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#]
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace CreateTwoColumnPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            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]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing


Namespace CreateTwoColumnPDF
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			Dim page As PdfPageBase = doc.Pages.Add()

			Dim s1 As String = "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."
			Dim s2 As String = "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 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")
		End Sub
	End Class
End Namespace