mvc, pdf

itextsharp/c#

do you know how to get text's location just like (x, y coordinate)? for example, i have pdf with 2 pages and I want to look for text called 'esign'
if the esign is found, i want to drop the image just next to esign on the right.
LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITsolutionWizardAuthor Commented:
Help?
0
MishaProgrammerCommented:
Read this post for solve your problem:
https://stackoverflow.com/questions/23909893/getting-coordinates-of-string-using-itextextractionstrategy-and-locationtextextr
Use class Rectangle to get location:
var rect = new iTextSharp.text.Rectangle(
                                                bottomLeft[Vector.I1],
                                                bottomLeft[Vector.I2],
                                                topRight[Vector.I1],
                                                topRight[Vector.I2]
                                                );

Open in new window

0
ITsolutionWizardAuthor Commented:
Sorry I don't get it....I want to search based on the keyword
0
MishaProgrammerCommented:
If you want to find text in PDF file using iTextSharp, you can try to use this code:
                    PdfReader pdfReader = new PdfReader("YourFileName");
                    for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                    {
                        ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();

                        string currentPageText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
                        if (currentPageText.Contains("YoursearchText"))
                        {
                           //
                        }
                    }
                    pdfReader.Close();
                }

Open in new window

This code was in answer, which I posted later.
0
ITsolutionWizardAuthor Commented:
please read the comment below.

what i hope to do is if we find 'signature' text in pdfs, then drop the png signature 5 crm on the right from text called 'signature'
               

                //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 find x, y position ?
                        because i want to drop signature png like below

 image.SetAbsolutePosition(pdfPositionX, pdfPositionY);
                pdfContentByte.AddImage(image);
                stamper.Close();


                    }
                }
                //begin: need logics to find keyword
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.