Multi-column PDFs are used for various types of publications such as magazines, newspapers, research articles, etc. While working with PDF automation, you may come across a scenario where you need to generate a multi-column PDF programmatically. Following that, this article covers how to create a multi-column PDF in C#.
C# Library to Create Multi-Column PDF
Aspose.PDF for .NET is a powerful and feature-rich API to create and manipulate PDF documents. We will use this API to create multiple-column PDF files using C#. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.PDF
How to Create a Multi-Column PDF in C#
Aspose.PDF for .NET makes it quite easier for you to create a multi-column PDF file. The following steps create a multi-column PDF from scratch in C#.
- Create a new Document object.
- Set the page margins using Document.PageInfo.Margin.Left and Document.PageInfo.Margin.Right properties.
- Add a new page in the PDF using Documents.Pages.Add() method and get its reference into a Page object.
- Create a new Graph object and add it to the paragraph using Page.Paragraphs.Add() method.
- Create a new Line and add it to the Graph.Shapes collection.
- Add heading text to the page using Page.Paragraphs.Add() method.
- Create a new FloatingBox and specify the number of columns, column spacing, and column width.
- Create another Graph object.
- Add a new Line to the Graph.Shapes collection.
- Add Graph to the FloatingBox.Paragraphs collection.
- Create a new TextFragment and add it to FloatingBox.Paragraphs collection.
- Add FloatingBox to the Page using Page.Paragraphs.Add() method.
- Save the PDF file using Document.Save(string) method.
The following code sample shows how to create a two-column PDF in C#.
The following is the screenshot of the multi-column PDF generated by Aspose.PDF for .NET.
Free C# PDF Library
You can get a free temporary license and create multi-column PDF files without any limitations.
Explore C# PDF Library
You can learn more about the C# PDF library using the documentation. In case you would have any questions, feel free to ask via our forum.
Conclusion
In this post, you have learned how to create multi-column PDF files in C#. The easy-to-follow steps and code sample have demonstrated how to create a two-column PDF in C#. You can simply install the library and integrate the provided code into your .NET applications.