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

Free Support Forum - aspose.com

DefaultAppearance.getFont() returns null

when I do this:
DefaultAppearance defaultAppearance = new DefaultAppearance();
com.aspose.pdf.Font font = defaultAppearance.getFont();

Aspose gives me a null. Why I need this? Because I want to calculate the appropriate width of a rectangle for generating a freetextAnnotation with some text in it. I thought I can do it with font.measureString().

What did I do wrong?

Regards, Gerd


Do you want to generate a rectangle around some text? Please share some more details by sharing a sample source and expected output PDF. We will test the scenario in our environment and address it accordingly.

Thank you, I solved this myself:
com.aspose.pdf.Font font = FontRepository.findFont(fontName);
dwidthNeeded = font.measureString(text+“MM”, new Double(fontsize).floatValue());

I added “MM” because otherwise the resulting width is too small.


It is nice to hear that you have managed to achieve your requirements. Please feel free to create a new topic in case you need further assistance.