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

Free Support Forum - aspose.com

Aspose.Pdf.Generator.Paragraph.IsKeptWithNext Property not working

Hi,


I have the following problem:

I generate a Aspose.Pdf.Generator.Heading object an set the IsKeptWithNext property. The is add this object as a new paragraph to an exisiting section.

After that I add an Table as a new paragraph to the section and normaly the heading an the table should stay together because of the IsKeptWithNext property of the first paragraph.

But they don’t stick together. It also does not work if the first paragraph is a simple text or if the second paragraph is an image. It simply works never.

Did I understand anything wrong at this property?

I simply need a function to keep a headline and the following paragraph connected on the same page because it looks ugly if the headline is on the bottom of one page an the table on the next page.

Hope you have some hints for me.

Best regards,

Andrei

Hi Andrei,


Thanks for using our products.

Can you please share some sample project/code snippet which can help us in replicating this problem. We are really sorry for this inconvenience.
Hi,

a generated some sample code. This code generates the attached document. Headline 2 should be sticked on top of the table on the second page.

private Pdf testPDF()
{
// create new pdf document
Pdf createPdf = new Aspose.Pdf.Generator.Pdf();
createPdf.CompressionLevel = 0;

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Pdf.lic");

// set global font
createPdf.TextInfo.FontName = "Arial Narrow";
createPdf.TextInfo.FontSize = 10;
createPdf.DefaultFontName = "Arial Narrow";
createPdf.TextInfo.IsFontEmbedded = true;

// create new section and get settings from pdf document
Section newSection = new Section(createPdf);

// set page size
newSection.PageInfo.PageWidth = PageSize.A4Width;
newSection.PageInfo.PageHeight = PageSize.A4Height;

// set page margins
MarginInfo pageMargins = new MarginInfo();
pageMargins.Top = 50F;
pageMargins.Left = 50F;
pageMargins.Right = 50F;
pageMargins.Bottom = 50F;
newSection.PageInfo.Margin = pageMargins;

Heading heading1 = new Heading(createPdf, newSection, 1);
Segment segment1 = new Segment(heading1);
heading1.Segments.Add(segment1);
segment1.Content = "Headline 1 text";
heading1.Margin.Top = 15F;
heading1.Margin.Bottom = 15F;
heading1.LabelWidth = 0;
heading1.TextInfo.FontName = "Arial Narrow";
heading1.TextInfo.FontSize = 14;
heading1.TextInfo.IsTrueTypeFontBold = true;
heading1.TextInfo.Color = new Color(0, 73, 164);
heading1.IsKeptWithNext = true;
newSection.Paragraphs.Add(heading1);
for (int i = 0; i < 40; i++)
{
Text standardText = new Text("TEXT TEXT TEXT " + i.ToString());
standardText.TextInfo.FontName = "Arial Narrow";
standardText.TextInfo.FontSize = 10;
standardText.TextInfo.Color = new Color(0,0,0);
standardText.IsHtmlTagSupported = true;
standardText.UseTextInfoStyle = true;
newSection.Paragraphs.Add(standardText);
}

Heading heading2 = new Heading(createPdf, newSection, 1);
Segment segment2 = new Segment(heading2);
heading2.Segments.Add(segment2);
segment2.Content = "Headline 2 text";
heading2.Margin.Top = 15F;
heading2.Margin.Bottom = 15F;
heading2.LabelWidth = 0;
heading2.TextInfo.FontName = pdfSettings.TextFont;
heading2.TextInfo.FontSize = 14;
heading2.TextInfo.IsTrueTypeFontBold = true;
heading2.TextInfo.Color = new Color(0, 73, 164);
heading2.IsKeptWithNext = true;
newSection.Paragraphs.Add(heading2);
Table newTable = new Table(newSection);
newTable.IsRowBroken = false;
newTable.IsBroken = false;
newTable.ColumnWidths = "5cm 5cm 5cm";

for (int i = 0; i < 40; i++)
{
Row row1 = newTable.Rows.Add();
row1.Cells.Add(i.ToString() + " cell1");
row1.Cells.Add(i.ToString() + " cell2");
row1.Cells.Add(i.ToString() + " cell3");
}

newSection.Paragraphs.Add(newTable);

// add new created section
createPdf.Sections.Add(newSection);

return createPdf;
}

Hi Andrei,


Thanks for sharing the code snippet and resource file.

I have tested the scenario using Aspose.Pdf for .NET 7.0.0 and I am able to reproduce the same problem that Heading2 is not appearing on top of table 2, over second page. However during my testing with upcoming release version of Aspose.Pdf for .NET 7.1.0, the problem seems to be fixed. For your reference, I have also attached the resultant PDF that I have generated with v7.1.0. Please be patient and wait for the new release. Please note that we are planning to release the new version in next few days and once the new version becomes available, we would be more than happy to update you with the status of availability. We are sorry for your inconvenience.

Hi Andrei,


I am pleased to share that the new version of Aspose.Pdf for .NET 7.1.0 has been published. Please try using it and in case you still face the same problem or you have any further query, please feel free to contact.

Thank you! Seems to work now correctly (Version 7.1.0)!


Bye

Andrei

Hi,


I encountered the same problem if there are more than one paragraph with IsKeptWithNext = “true”. I’m using Aspose.Pdf 9.6.0.0.
I tried report generated from xml:

<?xml version="1.0" encoding="utf-8" ?>
Table 1 title
<Table ColumnWidths=“250” DefaultCellPaddingTop=“5”
DefaultCellPaddingLeft=“5” DefaultCellPaddingRight=“5”
DefaultCellPaddingBottom=“5” MarginBottom=“10”>
Data inside table


Table 2 title 1

Table 2 title 2
<Table ColumnWidths=“250” DefaultCellPaddingTop=“5”
DefaultCellPaddingLeft=“5” DefaultCellPaddingRight=“5”
DefaultCellPaddingBottom=“5” MarginBottom=“10”>
Data inside table

The problem is the the line “Table 2 title 1” is not kept on the same page as the “Table 2 title 2” and the table 2.

Best regards

Hi Mirek,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-37751 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

Hi Nayyer,


Thanks for your response.
I have found another problem with the IsKeptWithNext property. In some scenarios there are no elements margins, if this property is set to true. Please take a look at the report generated from xml:

<?xml version="1.0" encoding="utf-8" ?>
Table 1 data
Table 2 title
Table 2 data
Table 3 title
Table 3 data

The margin between Table 2 and “Table 3 title” is missing.

I have noticed that if there is no table before “Table 2 title” paragraph, margins are calculated correctly.

Best regards,
MirekF:
Hi Nayyer,

Thanks for your response.
I have found another problem with the IsKeptWithNext property. In some scenarios there are no elements margins, if this property is set to true. Please take a look at the report generated from xml:

<?xml version="1.0" encoding="utf-8" ?>
Table 1 data
Table 2 title
Table 2 data
Table 3 title
Table 3 data

The margin between Table 2 and "Table 3 title" is missing.

I have noticed that if there is no table before "Table 2 title" paragraph, margins are calculated correctly.

Hi Mirek,

Thanks for contacting support.

I have tested the above stated scenario and have managed to reproduce the same problem. For the sake of correction, I have
logged this problem as PDFNEWNET-37771 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time.


We are sorry for this inconvenience.
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0in; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

<![endif]–>