Multi column newspaper style pdf

Hi Aspose,

We are evaluating your Aspose.Pdf library (.Net version), but we wanted to make certain that it can produce a multi-column layout with content that flows. Essentially what we want to do is to create a newspaper style pdf document. Is this something that is possible to do? If yes, is this something that is supported naturally or do we need to do like advanced setup/trick programming in the pdf creation.

Thanks.

Hi,

Thanks for considering Aspose.

Let me share some details regarding the structure of PDF documents generated by Aspose.Pdf. A PDF generated by Aspose.Pdf is comprised of one or more Sections, where a section contains one or more paragraphs. A paragraph can be an Image, Graph, Text, Floating Box, Table, Attachment, Heading or a Form Field.

By default all the paragraphs are inserted one after another in a sequence, but Aspose.Pdf provides an advanced feature to place paragraphs in multiple columns. Please visit the following link for detailed information Manipulating Multiple Columns

In order to have a better understanding of Document Structure generated by Aspose.Pdf, please visit Aspose.Pdf Document Object Model (DOM)

In case of any further query, please feel free to contact.

Hi Nayyer,

Thank you for your quick answer. After playing around with the library, I still can't do what we wanted, eventhough it looks so simple. Attached is a screen shot on what we trying to produce. So we wanted to put more than 1 articles per page and each title should span across all columns.

It might just need to spend more time using Aspose.Pdf. But if you could give us some suggestion it will be highly appreciated.

Thanks.

Wy

Hi,

I am working on this issue, I will inform you at here if I find the way to achieve your aim.

Thanks.

Hi Wayan,

Please use the attached dll and code as below, then you will get the result pdf file that you want.

If you still have some questions, please let me know.

Thanks

[C#]

Pdf pdf = new Pdf();
// specify the left margin info for the PDF file
pdf.PageSetup.Margin.Left = new MarginInfo().Left = 40;
// specify the Right margin info for the PDF file
pdf.PageSetup.Margin.Right = new MarginInfo().Right = 40;
Aspose.Pdf.Section sec0 = pdf.Sections.Add();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
Aspose.Pdf.Section sec2 = pdf.Sections.Add();
sec0.IsNewPage = false;
sec1.IsNewPage = false;
sec2.IsNewPage = false;


Graph graph1 = new Graph(sec0, 500, 2);
// Add the line to paraphraphs collection of section object
sec0.Paragraphs.Add(graph1);

//specify the coordinates for the line
float[] posArr = new float[] { 1, 2, 500, 2 };
Line l1 = new Line(graph1, posArr);
graph1.Shapes.Add(l1);
//Create string variables with text containing html tags

string s = "" +

" How to Steer Clear of money scams</ "
+ "";
//Create text paragraphs containing HTML text

Text heading_text = new Text(s);
heading_text.IsHtmlTagSupported = true;
heading_text.TextInfo.Alignment = AlignmentType.Left;
//sec1.IsNewColumn = false;
sec0.Paragraphs.Add(heading_text);


//Add four columns in the section
sec1.ColumnInfo.ColumnCount = 4;
//Set the spacing between the columns
sec1.ColumnInfo.ColumnSpacing = "5";

sec1.ColumnInfo.ColumnWidths = "105 105 105 105";
Text text1 = new Text("By A Googler (The Official Google Blog)");
text1.TextInfo.FontSize = 8;
text1.TextInfo.LineSpacing = 2;
text1.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Left;
sec1.Paragraphs.Add(text1);


text1.TextInfo.FontSize = 10;
//text1.TextInfo.Color = new Aspose.Pdf.Color("Red");
text1.TextInfo.IsTrueTypeFontItalic = true;
// Create a graphs object to draw a line
Graph graph2 = new Graph(50, 10);
// specify the coordinates for the line
float[] posArr2 = new float[] { 1, 10, 100, 10 };
Line l2 = new Line(graph2, posArr2);
graph2.Shapes.Add(l2);

// Add the line to paraphraphs collection of section object
sec1.IsNewColumn = true;
sec1.Paragraphs.Add(graph2);


Text text2 = new Text(@"Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.");
text2.TextInfo.IsTrueTypeFontItalic = false;

sec1.Paragraphs.Add(text2);


Aspose.Pdf.Section sec00 = pdf.Sections.Add();
Aspose.Pdf.Section sec11 = pdf.Sections.Add();
// Aspose.Pdf.Section sec5 = pdf.Sections.Add();
sec00.IsNewPage = false;
sec11.IsNewPage = false;
// sec5.IsNewPage = false;



//Create string variables with text containing html tags

string ss = "" +
" UK demands more troops from Kabul</ " + "";
//Create text paragraphs containing HTML text

Text heading_text1 = new Text(ss);
heading_text1.IsHtmlTagSupported = true;
heading_text1.TextInfo.Alignment = AlignmentType.Left;
//sec1.IsNewColumn = false;
sec00.Paragraphs.Add(heading_text1);


//Add four columns in the section
sec11.ColumnInfo.ColumnCount = 4;
//Set the spacing between the columns
sec11.ColumnInfo.ColumnSpacing = "5";

sec11.ColumnInfo.ColumnWidths = "105 105 105 105";
Text text11 = new Text("(World news and comment from the Guardian | Guardian.co.uk)");
text11.TextInfo.LineSpacing = 2;
text11.TextInfo.FontSize = 8;
text11.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Left;
sec11.Paragraphs.Add(text11);


text11.TextInfo.FontSize = 10;
//text1.TextInfo.Color = new Aspose.Pdf.Color("Red");
text11.TextInfo.IsTrueTypeFontItalic = true;
// Create a graphs object to draw a line
Graph graph22 = new Graph(50, 10);
// specify the coordinates for the line
float[] posArr22 = new float[] { 1, 10, 100, 10 };
Line l22 = new Line(graph22, posArr22);
graph22.Shapes.Add(l22);

// Add the line to paraphraphs collection of section object
sec11.IsNewColumn = true;
sec11.Paragraphs.Add(graph22);


Text text22 = new Text(@"nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.");
text22.TextInfo.IsTrueTypeFontItalic = false;

sec11.Paragraphs.Add(text22);

Text text44 = new Text(@" ");
text44.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Justify;
sec2.Paragraphs.Add(text44);

//Save the Pdf
pdf.Save(@"d:/Multiple_Columns.pdf");

Alex Li,

Thanks for your solution. I noticed the dll you sent is version 4.0.0.9. Is this a new release version or still in beta?

Thanks,

Wy

Hi,

The version 4.0.0.9 is the latest hotfix for Aspose.Pdf and is still in Beta. Whereas, we've planned to release the new version by the end of this month.

In case of any further query, please let us know.

Hi Alex Li,

Above code works. However the only issue we found is that the header does not show up on the subsequential pages. It only shows on the first page. Code snippet is below:

Section sec1 = pdf.Sections.Add();

HeaderFooter hf1 = new HeaderFooter(sec1);

sec1.OddHeader = hf1;

sec1.EvenHeader = hf1;

Text text = new Text(hf1, "header for testing");

hf1.Paragraphs.Add(text);

----

Let me know if you have a workaround for this. Thanks!

Hi,

Can you please try using the property IsFirstPageOnly of HeaderFooter class, and set its value to false.

In case it does not resolve your problem, please share the complete code snippet, so that we can test the scenario at our end.