Form Field Text Resize Issue

I’m using Aspose.PDF to fill and flatten form fields on a PDF. Latest version: 23.1.1

IF Aspose decides the text is too large for the rectangle field it will reduce its size even if the font size is explicitly set.
But I don’t want this, I want it to follow the settings even if the text is truncated like it would if I typed into the form.

I found an old post about this here.
But your library has changed since then. Now instead of setting FitIntoRectangle on the specific Field (sensible), you’ve made it a static field at Aspose.Pdf.Forms.Field.FitIntoRectangle (what?).

I’m using this in a web app, ASP.NET.
Say I’m on the same page and I have 2 buttons for generating docs. Button A sets FitIntoRectangle to false, Button B doesn’t set it at all.
If I click B then A then B… The 1st B will have FitIntoRectangle true (default) and the 2nd B will have FitIntoRectangle false.
And now it’s suddenly changed for other users too… Sometimes. In actuality, testing with 2 Users gives odd results where sometimes the setting seems to switch back to the default of true for some reason.
It’s concerning why this setting is static?

What if I want it set differently on different docs?
Is there a way I can globally set the default to false?(if I set it on startup it just ends up back to true later).


This scenario needs further investigation. Can you please share a sample PDF document for our reference along with some code snippet that you have been using to replicate this exact behavior your mentioned? We will log an investigation ticket in our issue tracking system and share the ID with you.

Any pdf document with a Form Field on it is an example.

For example, run this C# code on the attached PDF:

    public static void AsposeSingleForm() 
        var doc = new Aspose.Pdf.Document(pathToFile);
        //Aspose.Pdf.Forms.Field.FitIntoRectangle = false;
        var field = doc.Form["Text1"];
        ((Aspose.Pdf.Forms.TextBoxField)field).Value = "Some long text that I want to shrink down to fit";
        var field2 = doc.Form["Text2"];
        ((Aspose.Pdf.Forms.TextBoxField)field2).Value = "Some more long text that I want to overflow and not change size";

Now toggle the FitIntoRectangle setting and you’ll see the different outputs.
What if I want the 1st to shrink and the 2nd to overflow?
I could set FitIntoRectangle to true after the 1st one right? But that’s not the root of the problem.

The issue is that FitIntoRectangle is a property that should exist per Field. Like above I should be able to say “field.FitIntoRectangle = false”. And instead, it’s a static property.
Aka you have what should be an instance property as a static property.

Toggling static FitIntoRectangle is fine if you’re only working on a single doc and thread at any given time but useless for web applications.
In a web app, at any given time the property could switch. Maybe in the middle of a page being built that was set off by another user.

Decompiling your code I see that the property is “[ThreadStatic]” so set per thread. But this is still bad for a web app because you don’t know what thread any request will be on. So it will randomly vary depending on whatever thread the request is assigned to. Have it false on one and true on another and it’s a coin flip.

To see what I’m talking about first hand you’d have to deploy a web app that builds a pdf on some request/action and then perform that action from multiple clients to see how 1 client altering the static property affects the other client. I’m not providing a sample of all that (tho I have verified it in our app).
But I don’t need to. It’s just a basic OOP design concept.

The fact it can be toggled shows that it IS being set internally at the time that Value is being set. So why not have the option to set it as an instance property?

And my mistake on the old forum post. Looking back I see it’s set the same way there.

JustAFormField.pdf (6.1 KB)


We have opened the following new ticket(s) in our internal issue tracking system to further investigate the scenario. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

Issue ID(s): PDFNET-53704

We are sorry for the inconvenience.

For anyone who sees this in the future, you can mostly resolve this odd design issue yourself by manually truncating text to the field size using Font.MeasureString:

var txtWidth = font.MeasureString(txt, fontSize);
while (txtWidth > maxWidth)
    txt = txt.Substring(0, txt.Length - 1);
    txtWidth = font.MeasureString(txt, fontSize);


It is nice to hear that you were able to resolve your issue. Shared information would definitely help others having similar issue. Please feel free to let us know in case you face any issues.