TextStamp height and width not respected

Hello,

I am trying to add some text to the an existing PDF document using a text stamp and am not seeing the behavior as I would expect.

I add a text stamp with a particular height and width but if I put a large amount of text into the stamp it doesn’t respect the height of text stamp. The height of the stamp is increase and the text overflows into the rest of the document.

I would expect that the size of the text stamp would not change the the content would be clipped. Below is an example of the code I am using to create a text stamp with a width and height of 100x50.

Is this just not something that is possible?
Thanks

Here is the code:

    static void Test()
    {
        var pdf = new Document();
        var page = pdf.Pages.Add();


        var stamp = new TextStamp("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
        stamp.Width = 100; 
        stamp.Height = 50; // doesn't resect the height
        stamp.LeftMargin = 10;
        stamp.RightMargin = 5;
        stamp.TopMargin = 5;
        stamp.WordWrap = true;
        stamp.TextState.FontSize = 11;
        stamp.Background = true;
        stamp.Scale = false;
        stamp.TextAlignment = HorizontalAlignment.Left;
        stamp.TextState.HorizontalAlignment = HorizontalAlignment.Left;
        stamp.VerticalAlignment = VerticalAlignment.Top;
        stamp.HorizontalAlignment = HorizontalAlignment.Left;
        stamp.TextState.BackgroundColor = Color.LightBlue;
        page.AddStamp(stamp);

        pdf.Save(@"d:\output\textstamp.pdf");

    }

@ejt66

Thank you for contacting support.

Would you please try to set stamp.WordWrap property to false and then share if this satisfies your requirements.

I tried that and it’s the same results, it turns my 1 page document into 5 pages.

@ejt66

With Aspose.PDF for .NET 19.11, there is only 1 page in generated file. Please refer to attached document which is created using your code but with stamp.WordWrap property set to false. textstamp_19.11.pdf (2.6 KB)

My mistake, I commented out the WordWrap line of code instead of setting it to false.

Regardless, it’s still not working the way that i am expecting. I’m trying to endorse a document with text in a specific area on it and in my code example a height and width of 50x100 and I do not want that text to overflow into the rest of the document.

When I set the height and width without word wrap enabled (in your example) the text goes beyond the width that I set of 100. It extends out past the end of the page.

When I try it with word wrap enable I get what I expect on page one, however it add 4 additional pages to the document which is what I do not want.

My expectation is that when I set the height and width of a text stamp that it uses those values and does not extent it beyond that area or add it additional pages to my document

@ejt66

Thank you for elaborating your requirements.

We have devised below code snippet so would you please try it and then share your kind feedback with us.

Document doc = new Document();
Aspose.Pdf.Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);

const double width = 100;
const double height = 50;

var box = new FloatingBox((float)width, (float)height)
{
    Left = 0f,
    Top = 0f,
    Margin = new MarginInfo(0, 0, 0, 0),
    Padding = new MarginInfo(0, 0, 0, 0),
    Border = new BorderInfo(BorderSide.All),
    HorizontalAlignment = HorizontalAlignment.Left,
    BackgroundColor = Aspose.Pdf.Color.Tomato,
    VerticalAlignment = VerticalAlignment.Top
};

TextFragment textFragment = new TextFragment("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");

//Add the Text into paragraphs collection of FloatingBox
box.Paragraphs.Add(textFragment);
page.Paragraphs.Add(box);

doc.Save(dataDir + "FloatingBox_19.11.pdf");

Hello Raza, Sorry it took me so long to look at this. I tried it and it produces the same results and my original code. It produces a 5 page document instead of truncating the content on the first page.

@ejt66

Would you please share generated document with us because we are getting only one page with truncated text while using above code snippet. We have also attached generated PDF document for your kind reference. FloatingBox_19.11.pdf

Your attached file has 5 pages as well.

@ejt66

Thank you for clarifying.

We have noticed that although the text is truncated but number of pages are still wrong. Therefore, a ticket with ID PDFNET-47458 has been logged in our issue management system for further investigations. We will let you know once any update will be available in this regard.

Note that this happens on both text stamp and fragment.

Thanks

Ed

@ejt66

We have logged your concerns along with the issue and will share our feedback as soon as some progress is made towards ticket resolution.