Hi,
How to get the text from the specific XRect position?
So far I have below code to add a text at specific XRect position. It works great. However, I would like to read the existing text from that position and based upon the existing text, I need to update the new text.
Code:
using (PdfDocument InputDocument = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify))
{
for (int i = 0; i < InputDocument.Pages.Count; i++)
{
PdfPage page = InputDocument.Pages[i];
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Courier", 10, XFontStyle.Regular);
XTextFormatter tf = new XTextFormatter(gfx);
var rect = new XRect(new PointF(505, 38.5f), new SizeF(76, 10));
gfx.DrawRectangle(XBrushes.White, rect);
tf.Alignment = XParagraphAlignment.Left;
tf.DrawString("some text based upon existing text", font, XBrushes.Black, rect, XStringFormats.TopLeft);
}
InputDocument.Save("out.pdf");
}
Please help.
Thanks