ITsolutionWizard
asked on
itextsharp, c#, mvc, position
The c#/code below: how to find x,y position of 'text' for example 'signature'. and after it is found, I hope to drop the png image there.
I just need help how to find the x, y position and I already created the code dropping the png image.
Thanks
I just need help how to find the x, y position and I already created the code dropping the png image.
Thanks
public static string AddSignature(string originalPdf, string outputPdf, string signature, int pdfPositionX, int pdfPositionY)
{
string path = @"C:\Users\Documents\Workspaces\";
string pathSignature = @"C:\Users\Documents\signature\";
using (Stream inputPdfStream = new FileStream(path + originalPdf, FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream inputImageStream = new FileStream(pathSignature + signature, FileMode.Open, FileAccess.Read, FileShare.Read))
using (Stream outputPdfStream = new FileStream(path + outputPdf, FileMode.Create, FileAccess.Write, FileShare.None))
{
var reader = new PdfReader(inputPdfStream);
var stamper = new PdfStamper(reader, outputPdfStream);
var pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
//begin: need logics to find keyword
PdfReader pdfReader = new PdfReader(path + outputPdf);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentPageText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
if (currentPageText.Contains("Signature"))
{
//how to get x, y postion with text called 'signature'
}
}
//end: need logics to find keyword
image.SetAbsolutePosition(pdfPositionX, pdfPositionY);
pdfContentByte.AddImage(image);
stamper.Close();
}
return "Success";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
First, please test the above code in a separate (new) project.
Supply your actual pdf. Check to make sure it displays from the statement
Console.WriteLine(string.F ormat("Fou nd text {0} at {1}x{2}", p.Text, p.Rect.Left, p.Rect.Bottom));
Thanks,
Ashok
Supply your actual pdf. Check to make sure it displays from the statement
Console.WriteLine(string.F
Thanks,
Ashok
ASKER