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 the scenario where you need to generate a multi-column PDF programmatically. In accordance with that, this article covers how to create multi-column PDF files using C#.
C# API to Create Multi-Column PDFs
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
Create a Multi-Column PDF using 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.
- 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 using C#.
The following is the screenshot of the multi-column PDF generated by Aspose.PDF for .NET.
Get a Free License
You can use Aspose.PDF for .NET without evaluation limitations using a temporary license.
Conclusion
In this post, you have learned how to create multi-column PDF files from scratch using C#. You can simply install the API and integrate the provided code into your .NET applications. In addition, you can learn more about the .NET PDF API using the documentation. In case you would have any questions, feel free to ask via our forum.