

PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rect, null, PdfAnnotation.MARKUP_HIGHLIGHT, quad) NOTE: The order below doesn't appear to match the actual spec but is what Acrobat producesįloat quad = Create an array of quad points based on that rectangle. NOTE: Technically this isn't used but it helps with the quadpoint calculation Using (PdfStamper stamper = new PdfStamper(reader, fs)) Using (FileStream fs = new FileStream(highLightFile, FileMode.Create, FileAccess.Write, FileShare.None)) PdfReader reader = new PdfReader(outputFile) Bind a reader and stamper to our test PDF String highLightFile = Path.Combine(Environment.GetFolderPath(), "Highlighted.pdf") Create a new file from our test file with highlighting Using (PdfWriter w = PdfWriter.GetInstance(doc, fs))ĭoc.Add(new Paragraph("This is a test"))

Using (Document doc = new Document(PageSize.LETTER)) Using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) String outputFile = Path.Combine(Environment.GetFolderPath(), "Test.pdf") Private void Form1_Load(object sender, EventArgs e) Once you have the highlight you can set the color using: highlight.Color = BaseColor.YELLOW Īnd then add it to your stamper stamper.AddAnnotation(highlight,1) If you want to highlight text in pdf document using an existing PdfStamper called
