Free Support Forum - aspose.com

FloatingBox overflows onto new page

I am trying to add a bounded text area with a background color onto an existing pdf document. The requirement is that if the text is out of the bounded area it will simply be truncated off.

I am using aspose.total.net (pdf version 18.5.0). Here is the source file I am using as a test.

source.pdf (97.0 KB)

Below is an example of the code

const string text = $“This is a test{Environment.NewLine}This{Environment.NewLine}is a{Environment.NewLine}test{Environment.NewLine}This is a{Environment.NewLine}This is a test{Environment.NewLine}This{Environment.NewLine}is a{Environment.NewLine}test{Environment.NewLine}This is a”;
var doc = new Document(“source.pdf”);

const double x = 50.25;
const double y = 162.34;
const double width = 201;
const double height = 152;
var page = doc.Pages[1];

var box = new FloatingBox
{
Top = page.Rect.Height - (y + page.PageInfo.Margin.Bottom + height),
Left = x - page.PageInfo.Margin.Left,
Height = height,
Width = width,
BackgroundColor = Color.FromRgb(System.Drawing.ColorTranslator.FromHtml("#426bf4")),
HorizontalAlignment = global::Aspose.Pdf.HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Border = new BorderInfo(BorderSide.None),
IsKeptWithNext = true
};
var fragment = new TextFragment(text);
fragment.TextState.FontSize = 30;
fragment.IsInLineParagraph = true;
box.Paragraphs.Add(fragment);
page.Paragraphs.Add(box);

doc.Save(“result.pdf”);

What you can see from the attached output is the text does not truncate, a new page seems to be created and a new box placed in the same location on the next page with the remainder of the text. I have tried setting the property IsKeptWithNext = true on the text fragment but this just locks up and never completes.

result.pdf (96.2 KB)

@cyrus10101,

We managed to replicate the said behavior of the API in our environment. In order to achieve the requirement, an investigation has been logged under the ticket ID PDFNET-44707 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.