We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How do I stop creating a new section from creating a new page?

Hi, I am creating a section that is a header (using Aspose.Pdf.Generator), and then I am creating a body and then I need a footer. However in my code below, the Section secBody = pdf.Sections.Add() does a page break and puts the header on a seperate page. How can I make the body section be just below the header section? Thanks!

Code:

Pdf pdf = new Pdf();

pdf.IsTruetypeFontMapCached = false;

pdf.PageSetup.PageHeight = PageSize.A2Height;

pdf.PageSetup.PageWidth = PageSize.A2Width;

Section secHeader = pdf.Sections.Add();

HeaderFooter header = new HeaderFooter(secHeader);

secHeader.OddHeader = header;

Table tableLogo = new Table();

tableLogo.PositioningType = PositioningType.ColumnRelative;

header.Paragraphs.Add(tableLogo);

tableLogo.DefaultCellBorder = new BorderInfo((int)BorderSide.None, 0.1F);

tableLogo.ColumnWidths = "500 500";

Image img = new Image();

img.ImageInfo.File = @"F:\Fetch\logo999_110.bmp";

img.ImageInfo.ImageFileType = ImageFileType.Bmp;

img.ImageInfo.FixWidth = 1000;

Row row1 = tableLogo.Rows.Add();

Cell cellImage = row1.Cells.Add();

cellImage.Paragraphs.Add(img);

tableLogo.Rows[0].Cells[0].ColumnsSpan = 2;

Row row2 = tableLogo.Rows.Add();

row2.BackgroundColor = new Aspose.Pdf.Generator.Color("#0000A0");

row2.DefaultCellTextInfo.Color = new Aspose.Pdf.Generator.Color("#FFFFFF");

row2.DefaultCellTextInfo.FontName = "Verdana";

row2.DefaultCellTextInfo.FontSize = 12;

Cell cellTitle = row2.Cells.Add("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");

cellTitle.Alignment = AlignmentType.Left;

Cell cellDate = row2.Cells.Add("20 November 2011");

cellDate.Alignment = AlignmentType.Right;

Row row3 = tableLogo.Rows.Add();

row3.DefaultCellTextInfo.FontSize = 12;

row3.DefaultCellTextInfo.FontName = "Arial";

Cell cellName = row3.Cells.Add("Firstname Lastname");

cellName.Alignment = AlignmentType.Left;

Cell cellEmail = row3.Cells.Add("email@companyname.com");

cellEmail.DefaultCellTextInfo.Color = new Aspose.Pdf.Generator.Color("#00FFFF");

cellEmail.Alignment = AlignmentType.Right;

Section secBody = pdf.Sections.Add();

Text txt = new Text("Test Body");

secBody.Paragraphs.Add(txt);

Hi Herman,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

As per Aspose.Pdf for .NET DOM, Document (PDF document in general) is the root object which contains multiple sections (Pages in Pdf file). So, if you add a new section, that means you are adding a new page to your document. To keep the text together on one page you need to put it in the same section. Also, in your case, as you are using table, it is better to use table rows to add different text segments or paragraphs to your page. Please see the following documentation link for Aspose.PDF DOM details:

http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/introduction-to-dom.html

Thank You & Best Regards,