如何突出显示现有pdf文件中的特定文本

时间:2014-02-18 13:18:22

标签: c# itextsharp

using (FileStream fs = new FileStream(@"F:\test\resulthighlight.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
    using (PdfStamper stamper = new PdfStamper(reader, fs))
    {
        iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(60.6755f, 749.172f, 94.0195f, 735.3f);
        float[] quad = { rect.Left, rect.Bottom, rect.Right, rect.Bottom, rect.Left, rect.Top, rect.Right, rect.Top };


        PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rect, null, PdfAnnotation.MARKUP_HIGHLIGHT, quad);
        //Set the color
        highlight.Color = BaseColor.YELLOW;

        //Add the annotation

        stamper.AddAnnotation(highlight, 1);
    }
}

我尝试了这个,但我找不到我的搜索文本的坐标,任何人帮助我?我使用了Itextsharp解析器的ITextExtractionStrategyLocationTextExtractionStrategy

0 个答案:

没有答案