Recently we found Paul Madary's blog post about digital signatures in a Univeral Application (UWP) with iText 7, and we wanted to share it. Paul gracefully agreed to let us do that, and as a bonus we upgraded the code to be usable out-of-the-box with iText 7.1.3. The only change needed is the method SignDocumentSignature.

A big thank you to our Q3 top contributors!

There are so many people that contribute information to us in order to help improve our code, products and projects. We want to make sure that our top contributors are being recognized for the help they give and that they know how much we appreciate them.

Now you can ask the base font for the width of this String in 'normalized 1000 units' (these are units used in 'Glyph space'; see ISO-32000-1 for more info):

float glyphWidth = bf.getWidth("WHAT IS THE WIDTH OF THIS STRING?");

Now we can convert these 'normalized 1000 units' to an actual size in points (actually user units, but let's assume that 1 user unit = 1 pt for the sake of simplicity).

For instance: the width of the text "WHAT IS THE WIDTH OF THIS STRING?" when using Courier with size 16pt is:

float width = glyphWidth * 0.001f * 16f;

Your question is different: you want to know the font size for a given width. That's done like this:

float fontSize = 1000 * width / glyphwidth;

Note that there are short cuts to get the widht of a String in points: you can use BaseFont.getWidthPoint(String text, float fontSize) to get the width of text given a certain fontSize. Or, you can put the string in a Chunk and do chunk.getWidthPoint() (if you didn't define a Font for the Chunk, the default font Helvetica with the default font size 12 will be used).

How to use two different colors in a single String?

Ready to use iText?

As always, if you have any technical questions, you can contact support with your valid support subscription or head over to one of our community support pages on Stack Overflow to see if your question has already been answered for our AGPL users.