I'm trying to figure out how to find text that I've previously added to a PDF with iText7.
I'm playing around with iText7, and have the following code:
static void Main(string[] args)
{
PdfDocument pdfDocument = new PdfDocument(new PdfWriter("./test.pdf"));
pdfDocument.AddNewPage(PageSize.LETTER.Rotate());
Document document = new Document(pdfDocument);
PdfFont helv = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
Paragraph paragraph = new Paragraph("test string");
paragraph.SetFont(helv);
paragraph.SetFontSize(8);
paragraph.SetFixedPosition(500, 194, 100);
document.Add(paragraph);
document.Close();
return;
}
I then run different code to get me the streams, which shows me the following:
q
BT
/F1 8 Tf
500 197.54 Td
(test string)Tj
ET
Q
Of note is that where I specified a Y position of 194, the resulting PDF shows 197.54. If I add (user-supplied) text to the PDF, and then want to go back later and replace that text with something else, I can know that, for at least that specific font/size, I have to add 3.54 to the Y I originally specified; I'm assuming that has something to do with the font's baseline v. iText specifying the bottom of the text block.
My question is, how can I calculate what that "3.54" is for any other Font or size I might use. Is there info I can get from iText to help, or is it just "multiply the font size by 0.44 for Helvetica, and 0.35 for Courier, etc"?
So far, and maybe it's just been lucky, I haven't seen any issues with a string of text being split up into different Td/Tj commands, so I'm going to ignore that potential future problem for the moment.
Thanks!