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

Free Support Forum - aspose.com

IsKeptWithNext issue

Hello,


We found the weird issue with IsKeptWithNext property. In our document there is a heading and some related text (or table) paragraphs. The requirement is do not split the heading and its first paragraph and keep them on the same page. In other words it should not be a lonely heading at the bottom of the page. To achieve this we tried to set IsKeptWithNext = true to the heading.

Here there are 2 samples:

1) Everything works as expected (the “Heading 3” is rendered on the next page together with the 1st text paragraph):

Pdf document = new Pdf();
Section docPage = document.Sections.Add();
docPage.PageInfo.Margin = new MarginInfo()
{
Bottom = 30,
Left = 0,
Right = 0,
Top = 0
};
Heading h = new Heading(document, docPage, 1);
h.Segments.Add(new Segment(“Heading 2”));
docPage.Paragraphs.Add(h);
for (int i = 0; i < 65; i++)
{
docPage.Paragraphs.Add(new Text(docPage, "test test test " + i.ToString()));
}

// HEADING 3
h = new Heading(document, docPage, 1)
{
IsKeptWithNext = true
};
h.Segments.Add(new Segment(“Heading 3”));
docPage.Paragraphs.Add(h);
for (int i = 0; i < 75; i++)
{
docPage.Paragraphs.Add(new Text(docPage, "test test test " + i.ToString()));
}
document.Save(“output_1.pdf”);

2) Now we add a page before “Heading 2” and set “Heading 2” as the first paragraph of the page. The result is unexpected: “Heading 3” and its 1st text paragraph are split and displayed on different pages. Moreover in both cases the page margin top is 0 so the rendering starts from the beginning of the page. It seems that if there is any page break before “Heading 2”, the property "IsKeptWithNext " for all heading below is ignored (or the start point is not calculated properly). For us it’s the critical bug.

Pdf document = new Pdf();
Section docPage = document.Sections.Add();
docPage.PageInfo.Margin = new MarginInfo()
{
Bottom = 30,
Left = 0,
Right = 0,
Top = 0
};

// HEADING 1
Heading h = new Heading(document, docPage, 1);
h.Segments.Add(new Segment(“Heading 1”));
docPage.Paragraphs.Add(h);
for (int i = 0; i < 10; i++)
{
docPage.Paragraphs.Add(new Text(docPage, "test test test " + i.ToString()));
}

// HEADING 2 (New Page)
docPage.PageInfo.Margin = new MarginInfo()
{
Bottom = 30,
Left = 0,
Right = 0,
Top = 0
};
h = new Heading(document, docPage, 1);
h.IsFirstParagraph = true;
h.Segments.Add(new Segment(“Heading 2”));
docPage.Paragraphs.Add(h);
for (int i = 0; i < 65; i++)
{
docPage.Paragraphs.Add(new Text(docPage, "test test test " + i.ToString()));
}

// HEADING 3
h = new Heading(document, docPage, 1)
{
IsKeptWithNext = true
};
h.Segments.Add(new Segment(“Heading 3”));
docPage.Paragraphs.Add(h);
for (int i = 0; i < 75; i++)
{
docPage.Paragraphs.Add(new Text(docPage, "test test test " + i.ToString()));
}
document.Save(“output_2.pdf”);

In the attachment there are 2 outputs for the scenarios above.
Please advise.

Hello Support,


Please comment the issue above.

The support team.


Any clarification ? This is the critical issue for us.

Hi,


Thanks for contacting support and sorry for the delayed response.

I am working on testing the scenario and will keep you posted with my findings.

Hi,


Thanks for your patience.

The code snippet which you have shared earlier is based on legacy Aspose.Pdf.Generator and for the sake of testing, I have tried using new Document Object Model (DOM) of Aspose.Pdf namespace and as per my observations, the Heading 3 and its paragraphs are appearing right after Heading 2. Can you please take a look over attached PDF file and in case I have not properly understood the requirement, please share some further details and image files which can help us in properly identifying the issue.

[C#]

Document document = new Document();<o:p></o:p>

Page docPage = document.Pages.Add();

docPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo()

{

Bottom = 30,

Left = 0,

Right = 0,

Top = 0

};

// HEADING 1

Aspose.Pdf.Heading h = new Aspose.Pdf.Heading(1);

h.Segments.Add(new TextSegment("Heading 1"));

docPage.Paragraphs.Add(h);

for (int i = 0; i < 10; i++)

{

docPage.Paragraphs.Add(new TextFragment("test test test " + i.ToString()));

}

// HEADING 2 (New Page)

docPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo()

{

Bottom = 30,

Left = 0,

Right = 0,

Top = 0

};

h = new Aspose.Pdf.Heading(1);

h.IsInNewPage= true;

h.Segments.Add(new TextSegment("Heading 2"));

docPage.Paragraphs.Add(h);

for (int i = 0; i < 65; i++)

{

docPage.Paragraphs.Add(new TextFragment("test test test " + i.ToString()));

}

// HEADING 3

h = new Aspose.Pdf.Heading(1)

{

IsKeptWithNext = true

};

h.Segments.Add(new TextSegment("Heading 3"));

docPage.Paragraphs.Add(h);

for (int i = 0; i < 75; i++)

{

docPage.Paragraphs.Add(new TextFragment("test test test " + i.ToString()));

}

document.Save("c:/pdftest/HeadingRenderingIssue_output_2.pdf");

Hello,


Thanks for the response. In new generator it works as expected and I’d use your new generator with a great pleasure but you do not give us a chance because of too many blockers:

1) Header in TOC page: Exception occurs on a document save

4) Also you do not support “StrikeOut” font

How can we use the new approach if the base functionality does not work (but works in your old generator) and we cannot even create ToC (which is the core requirement) with your new generator? Also we do not know when you’re going to fix the found issues. We cannot say our customers to wait for a couple of months.
I’d agree to wait for a fix of minor issues, but not the blockers. So I’m not satisfied with the proposed approach and asking to test our issue in your old generator and propose a solution.

Also please let me know when ToC issues are going to be released.

ShmelP:
1) Header in TOC page: Exception occurs on a document save
We are pleased to share that the issues reported earlier in this thread are resolved and their resolution will be included in next release of Aspose.Pdf for .NET 10.7.0, which is planned to release in August-2015. Please be patient and wait for the resolution.

ShmelP:
4) Also you do not support “StrikeOut” font
This issue is logged as PDFNEWNET-38556 and product team plans the resolution within current month.

ShmelP:
How can we use the new approach if the base functionality does not work (but works in your old generator) and we cannot even create ToC (which is the core requirement) with your new generator?
The new DOM supports the TOC feature. Please visit the following link for further details on Add TOC to Existing PDF