Insert an Image in PDF using ITextSharp

后端 未结 2 1205
[愿得一人]
[愿得一人] 2021-01-20 11:36

I have to insert a an image in a pdf. That is, wherever I see a text \'Signature\', I have to insert an signature image there . I can do by saying absolute positions . But

相关标签:
2条回答
  • 2021-01-20 12:02

    That was perfect Chris. I am able to find the text position and insert the signature. What I understood is , there is a list List<TextChunk> LocationalResult in the LocationTextExtractionStrategy class. The RenderText() method in LocationTextExtractionStrategy will add each text to the LocationalResult list.

    Actually the list LocationalResult is a private list, I made it public to access it from outside.
    I loop through each page of PDF document and call PdfTextExtractor.GetTextFromPage(reader, i, locationStrat); where i is the pagenumber. At this time all text in the page will be added to the LocationalResult with all the position information. This is what I done . And it works perfect.

    0 讨论(0)
  • 2021-01-20 12:04

    Check out PdfTextExtractor and specifically the LocationTextExtractionStrategy. Create a class in your project with the exact code for the LocationTextExtractionStrategy and put a breakpoint on the line return sb.ToString(); (line 131 in SVN) and take a look at the contents of the variable locationalResult. You'll see pretty much exactly what you're looking for, a collection of text with start and end locations. If your search word isn't on a line by itself you might have to dig a little deeper but this should point you in the right direction.

    0 讨论(0)
提交回复
热议问题