iText 7 Get font line height - pdf

I am trying to get the total line height (ascent + descent) of a font in iText 7 with page and font size given. I found methods like PdfFont.getAscent(String, float) but this one seems to return the ascent for that particular given string. I want to get the general ("maximum") size properties for a given font and font size, as is for example possible in Java AWT (FontMetrics.getHeight()). Is there a way to do this? Or is there some specific reason why there is no way, that I should know about?
Thanks in advance!

The answer to this problem is solved here - https://stackoverflow.com/a/71289581/17931838
In a simple way, you need to extract the text from the pdf, and use itext tools to find the font height

Related

How to handle PDF font fallback perfectly when generating it?

I'm currently working on a project that can convert HTML canvas to PDF, user can select the font and draw the text in the canvas and export as a PDF(vector), but there's a problem that user can enter other language text that the font doesn't really support it. It's shown fine in the canvas because the browser did the font fallback mechanism maybe to grab the system font as a fallback, but in the exported PDF it's all corrupted. I've embedded the font in the PDF but the font doesn't have corresponding glyph, and the PDF reader like adobe doesn't have font fallback mechanism so it all become .nodef
I have two ideas but that aren't really satisfying.
1. Collect all glyph from each sentence and create a new font
Walk through each char and check if current font has corresponding glyph, if so, adding it to the new font list, if not, using an alternative font from the font stack #1 as the fallback to get the glyph and adding it to the new font list, then finally converting it as a new font and embedding it in the new PDF.
It seems good but in reality the performance of generating new font is terrible.
(I was using Opentype.js to load and write a new font, when we exported the font by using toArrayBuffer method, it took 10 mins for 6,000 words)
#1, Font stack is a stack like ['Crimson Text', 'Pt Sans', 'Noto Sans'], if the first font can't find corresponding glyph then go next until the end we give up.
2. If encountered any missing char, change the font-family of that sentence to Arial Unicode MS or Noto
It's pretty simple but it converts every word in the sentence to Arial Unicode MS or Noto, besides, it's hard to find a good font that contains most of language's glyph and we can't use font stack mechanism because we only can use one font in one sentence.
My goal is to make the exported PDF similar with the canvas that user drew, hoping someone can give me some direction 😥, many thanks
The usual solution would be to embed all four fonts in your stack plus noto (all suitably subsetted, preferably), and switch between them mid-word as required.
Building a new frankenfont from the fonts as you suggest is not required, though I admire the ambition!

How to change the font size of line numbers in IntelliJ IDEA?

I want to increase the font size of the line numbers in IntelliJ IDEA Ultimate(2019.3.1) independently from changing the font of the code itself but I can't find the way of doing so.
I shook the whole Internet and didn't find anything up to date either. Actions search didn't help as well.
How do I do that?
The font size of line numbers automatically changes along with the font size of code in the editor. It uses the same font setting(font, font size, etc).
You can try to adjust font.
https://www.jetbrains.com/help/idea/settings-editor-font.html
And as Improbable mentioned, there is a feature request for it: https://youtrack.jetbrains.com/issue/IDEA-92443

How to get the underlined text from PDF file?

everyone!
I try to get some underlined text from PDF file by itext, it seems very difficult for me. I've searched the solution for a long time, and I've learned how to get the text's fontfamily, fontsize and text location. However, no underline.
Looking forward to your help!
Thank you!
It might not be possible with itext, but you can achieve this with pdfbox at some extent
look at this: https://stackoverflow.com/a/40039407/4353762
But beware it might not work in some cases, the library needs to know the font and descriptors of the font. if you throw a pdf with unknown type then the descriptor will return null and the code will simply break with NullPointerException.
If you want to handle NullPointerExceptions manually then you might need to look at underlines and strikeThrough methods of
PDFStyledTextStripper.java

Increase font for pdf using Inkscape

I use to produce pdf graphs with R then I like to modify them using inkscape.
Yet when I increase font, letter size increase but letter spacing don't as you can see in example.
I have the same problem when I do the same with pdf from latex.
Thank for your help
Perhaps you have broken the text into individual letters, and are applying the new font size to those, rather than to the entire word? You may need to recreate the Xlabel text/group the letters back together.
Although there is an answer for exactly the same question here, I will duplicate it:
You should select the text you want to resize and then remove manual kerning either before or after the resizing. This can be done by clicking Text -> Remove Manual Kerns.

Change console text kerning in vb.net

I'm trying to make each letter a "square" essentially, so each letter is no more tall than it is wide, in vb.net. Is this possible? If so, how? I can't seem to find anything, and I've been searching hard.
Thanks for the help!
Why dont you just use a fixed size font ? Or create your own font ?
The Windows API has a function called SetCurrentConsoleFontEx which you could pinvoke. It accepts a width and height, font etc. Depending on how it handles these you may also need to make and add a 'square font' to the registry list of allowed fonts (example of adding a new font to the console here.)