Text Width Dynamically in Aspose.PDF for Java

Hi,

I am looking for a way to find width of content within TextField and assign that width to field, so does not take extra white space on pdf. If you have snippet of code, please share here as well.

I have found some sort of in below link for .Net but I need in Java.

Thanks,
Darshit Patel

@darshpatel

Do you want to determine the width of Textbox value? Could you please share your sample PDF document for our reference along with the information of text; of which width you need to determine using the API. We will check the related information at our end and share our feedback with you.

Hi @asad.ali,

I am not able to get that is why I am asking here, let me explain in plain words what is I am trying to achieve.

Let say I have text “Hello World” with font size of 10. I want to know the width that given text with given font size can take a width.

Once I have that width, want to allocate that size to field, so I don’t have to provide predefine width to any field.

I hope that is more clear and you don’t need an example from me now.

Thanks,
Darshit Patel

@darshpatel

You can please use the following Java Code snippet to get the width of a text of specific font:

com.aspose.pdf.Font font = FontRepository.findFont("Arial");
double width = font.measureString("Hello World", 10);

Please let us know in case you need more information.

1 Like