Free Support Forum - aspose.com

Second section error

I am binding to an XML file. It’s a pretty simple file, as I am just trying to see how this all works. I have three sections. For some reason, the second section does not display when I generate the PDF. Also, if I try to get that section programatically using:

Section section2 = pdf.Sections[“section2”];

I get an error that the section can not be found.

Another problem I’m having, which may or may not be related to this issue is that my third section, which has a table in it, displays on a second page, even though there is plenty of room for it on the first page.

I’d appreciate any help.
Pete

This is a user response.

Each always begins a new page. The section supplies the page layout information (page size and margins and orientation) and since each section could be on a different kind of page, each section begins on a new page. (This differs from sections in Word which do not require the section to start on a new page.)

Meant to include this in my last post. I have also noticed that if for some reason a Section is empty, Aspose skips generating a page to contain it. Check your XML to make sure that each section actually contains paragraphs (other than a header or footer).

Thanks. I spent some more time playing with it and discovered both of these things. An empty Text will also not render. I figured it out by looking at the Paragraphs.Count value. Thanks for responding.

Pete

Dear Pete,

Thanks for your consideration.


I am binding to an XML file. It’s a pretty simple file, as I am just trying to see how this all works. I have three sections. For some reason, the second section does not display when I generate the PDF. Also, if I try to get that section programatically using:

Section section2 = pdf.Sections[“section2”];

I get an error that the section can not be found.


I have tested the code you posted and can’t find any error. The function of pdf.Sections[“section2”] is to find a section object which ID is “section2” in the collection. Please make sure there is a section object which ID is “section2” in the collection. If not, you will get an error that the section can not be found.

The problem was that I did not have any text in my section with ID of section2, so it did not show up in the sections collection.

Pete