hi we try your library for highlight some words in pdf everythings works well but on some pdf we have an error message on pdf open i attach the two pdf one is before “test.pdf” and one is after “output.pdf” also i attach the error message when i open “output.pdf” the words highlighted is “adidas”
best regards
Hi Francisco,
Document document = new Document(myDir
- “test (8).pdf”);<o:p></o:p>
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i)adidas");
//set text search option to specify regular expression usage
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;
document.Pages.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection1)
{
Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation freeText = new Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation(textFragment.Page, new Aspose.Pdf.Rectangle((float)textFragment.Position.XIndent,
(float)textFragment.Position.YIndent, (float)textFragment.Position.XIndent + (float)textFragment.Rectangle.Width,
(float)textFragment.Position.YIndent + (float)textFragment.Rectangle.Height));
freeText.Opacity = 0.5;
freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow);
textFragment.Page.Annotations.Add(freeText);
}
document.Save(myDir + "texthighlight_output.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
i try your code with
win7 machine and vs2008 with 3.5 framework
and everythings seems to working well
did you have the same code in vb ?
my project is written in vb and i have afraid to write wrong code in traduction from another language
best regards
Frnacesco
Hi Frnacesco,
Dim document As New Document(myDir + “test (8).pdf”)<o:p></o:p>
Dim textFragmentAbsorber As New TextFragmentAbsorber("(?i)adidas")
'set text search option to specify regular expression usage
Dim textSearchOptions As New TextSearchOptions(True)
textFragmentAbsorber.TextSearchOptions = textSearchOptions
document.Pages.Accept(textFragmentAbsorber)
Dim textFragmentCollection1 As TextFragmentCollection = textFragmentAbsorber.TextFragments
For Each textFragment As TextFragment In textFragmentCollection1
Dim freeText As New Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation(textFragment.Page, New Aspose.Pdf.Rectangle(textFragment.Position.XIndent, textFragment.Position.YIndent, textFragment.Position.XIndent + textFragment.Rectangle.Width, textFragment.Position.YIndent + textFragment.Rectangle.Height))
freeText.Opacity = 0.5
freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow)
textFragment.Page.Annotations.Add(freeText)
Next
document.Save(myDir + "texthighlight_output.pdf")
Please feel free to contact us for any further assistance.
Best Regards,
perfect !
everythings works.
A last question if i want to add more than one keywords to highlight?
how can change the code ?
best regards
Francesco
Hi Francisco,
Dim keyWords As String() = New String() {“word1”,
“word2”}<o:p></o:p>
Dim document As New Document("input.pdf")
For Each value As String In keyWords
Dim key As String = "(?i)" & value
Dim textFragmentAbsorber As New TextFragmentAbsorber(key)
'set text search option to specify regular expression usage
Dim textSearchOptions As New TextSearchOptions(True)
textFragmentAbsorber.TextSearchOptions = textSearchOptions
document.Pages.Accept(textFragmentAbsorber)
Dim textFragmentCollection1 As TextFragmentCollection = textFragmentAbsorber.TextFragments
For Each textFragment As TextFragment In textFragmentCollection1
Dim freeText As New Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation(textFragment.Page, New Aspose.Pdf.Rectangle(textFragment.Position.XIndent, textFragment.Position.YIndent, textFragment.Position.XIndent + textFragment.Rectangle.Width, textFragment.Position.YIndent + textFragment.Rectangle.Height))
freeText.Opacity = 0.5
freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow)
textFragment.Page.Annotations.Add(freeText)
Next
Next
document.Save("output.pdf")
Please feel free to contact us for any further assistance.
Best Regards,
i found a solution by myself i use regular expression and passing this phrase to library i give you an example
"(?i)adidas | (?)reebook" .
the procedure seems to working well, is it the same ? the code is more readable in this mode but if is not the same i change my code .
best regards
Francesco
Hi Francesco,