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

Free Support Forum - aspose.com

DefaultAppearance.getFont() returns null

Hallo,
when I do this:
DefaultAppearance defaultAppearance = new DefaultAppearance();
defaultAppearance.setFontName(anno.getFontname());
defaultAppearance.setFontSize(anno.getFontsize());
defaultAppearance.setTextColor(color);
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

@GRein

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.

@GRein

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.