Hi Michael,
var document = new Document(@“C:\pdftest\36886.pdf”);<o:p></o:p>
//create TextAbsorber object to find all the phrases matching the regular expression
TextFragmentAbsorber textAbsorber = new TextFragmentAbsorber(@"[\S]+");
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textAbsorber.TextSearchOptions = textSearchOptions;
document.Pages.Accept(textAbsorber);
var editor = new PdfContentEditor(document);
foreach (TextFragment textFragment in textAbsorber.TextFragments)
{
foreach (TextSegment textSegment in textFragment.Segments)
{
DrawBox(editor, textFragment.Page.Number, textSegment, System.Drawing.Color.Red);
}
}
document.Save(@"C:\pdftest\36886-edited.pdf");
private static void DrawBox(PdfContentEditor editor, int page, TextSegment segment, System.Drawing.Color color)
{
var lineInfo = new LineInfo();
lineInfo.VerticeCoordinate = new[] {
(float)segment.Rectangle.LLX, (float)segment.Rectangle.LLY,
(float)segment.Rectangle.LLX, (float)segment.Rectangle.URY,
(float)segment.Rectangle.URX, (float)segment.Rectangle.URY,
(float)segment.Rectangle.URX, (float)segment.Rectangle.LLY
};
lineInfo.Visibility = true;
lineInfo.LineColor = color;
editor.CreatePolygon(lineInfo, page, new System.Drawing.Rectangle(0, 0, 0, 0), null);
}<o:p></o:p>
Thank you for the code sample. I’m trying to use this, but nothing is displaying on the page. Does this still work an output stream? That’s the only thing I can think of that is different.
I’m doing basically the following, and it is not working for me. No border is ever written.
Document pdf = new Document();
PdfContentEditor _pdfContentEditor = new PdfContentEditor();
_pdfContentEditor.BindPdf(_pdf);_pdf.Pages.Add();var lineInfo = new LineInfo();
Rectangle rectangle = GetRectangle();
lineInfo.VerticeCoordinate = new[] {
(float)rectangle.LLX, (float)rectangle.LLY,
(float)rectangle.LLX, (float)rectangle.URY,
(float)rectangle.URX, (float)rectangle.URY,
(float)rectangle.URX, (float)rectangle.LLY
};
lineInfo.Visibility = true;
lineInfo.LineColor = System.Drawing.Color.Black;
_contentEditor.CreatePolygon(lineInfo, _pageNumber, new System.Drawing.Rectangle(0, 0, 0, 0), null);_pdf.Save(stream);
acordmike:Also, how could I do a border around say two sides? Is there a separate way to draw a line that would be similar?
Hi Mike,