Aspose.Pdf

Manipulating Multiple Columns

In magazines and newspapers, we mostly see that news are displayed in multiple columns on the single pages instead of the books where text paragraphs are mostly printed on the whole pages from left to right position. Many document processing applications like Microsoft Word and Adobe Acrobat Writer allow users to create multiple columns on a single page and then add data to them.

 

Using Aspose.Pdf , developers can also add multiple columns to the pages of their PDF documents. As we know that we always add Paragraphs to Sections of our PDF documents using Aspose.Pdf . So, it is necessary to divide a Section into multiple columns and this is achieved by Section.ColumnInfo property, which is used to specify the column related information for each Section . This column information would include the width and spacing of columns etc.

 

The following figure shows multiple columns and the spacing between them:

 

 

Figure: Demonstration of multiple columns

 

Column spacing means the space between the columns and ColumnInfo.ColumnSpacing property of the Section class is used to set this space between columns. Default spacing between the columns is 1.25cm.

Moreover, ColumnInfo.ColumnWidths property of Section class is used to set the width of each column. If the column width is not specified by the user then Aspose.Pdf calculates width for each column automatically according to the page size and column spacing.

 

An example is given below to demonstrate the creation of three columns in a Section with default spacing.

 

Example:

 

[C#]

 

 

//Instantiate a Pdf object

Pdf pdf1 = new Pdf();

 

 

//Add a section to the Pdf

Section sec1 = pdf1.Sections.Add();

 

 

//Set the number of columns in the section to 3

sec1.ColumnInfo.ColumnCount = 3;

...

 

 

//Save the Pdf

pdf1.Save(...);

 

 

[VB.NET]

 

 

'Instantiate a Pdf object

Dim pdf1 As Pdf = New Pdf

 

 

'Add a section to the Pdf

Dim sec1 As Section = pdf1.Sections.Add()

 

 

'Set the number of columns in the section to 3

sec1.ColumnInfo.ColumnCount = 3

...

 

 

'Save the Pdf

pdf1.Save(...)

 

[XML]

 

 

<?xml version="1.0" encoding="utf-8" ?>

<Pdf xmlns="Aspose.Pdf">

     <Section ColumnCount="3">

         ...

     </Section>

</Pdf>

 

In the above exmaple, we learnt that how to create multiple columns with default spacing between them. But, we can change the width of each column and also the spacing between them. Let's practice it also with the help of an example.

 

Example:

 

[C#]

 

 

//Instantiate a Pdf object

Pdf pdf1 = new Pdf();

 

 

//Add a section to the Pdf

Section sec1 = pdf1.Sections.Add();

 

 

//Add two columns in the section

sec1.ColumnInfo.ColumnCount = 2;

 

 

//Set the spacing between the columns

sec1.ColumnInfo.ColumnSpacing = "15";

 

 

//Set the widths of the columns

sec1.ColumnInfo.ColumnWidths = "250 150";

...

 

 

//Save the Pdf

pdf1.Save(...);

 

 

[VB.NET]

 

 

'Instantiate a Pdf object

Dim pdf1 As Pdf = New Pdf

 

 

'Add a section to the Pdf

Dim sec1 As Section = pdf1.Sections.Add()

 

 

'Add two columns in the section

sec1.ColumnInfo.ColumnCount = 2

 

 

'Set the spacing between the columns

sec1.ColumnInfo.ColumnSpacing = "15"

 

 

'Set the widths of the columns

sec1.ColumnInfo.ColumnWidths = "250 150"

...

 

 

'Save the Pdf

pdf1.Save(...)

 

[XML]

 

 

<?xml version="1.0" encoding="utf-8" ?>

<Pdf xmlns="Aspose.Pdf">

     <Section ColumnCount="2" ColumnSpacing="15" ColumnWidths="250 150">

         ...

     </Section>

</Pdf>