Good Afternoon. I'm using your api to highlight text. I'm having some problems when the pdf format is image over text. The text is in a hidden layer, (or i think so). I can find text. But when y change backgorund i cant see the text.I send you two code snippets that i have tried, and a pdf files that allows you to view the result:
----------------------------------------------------------------------------------------------------------
Protected Sub HighLightPDF(ByVal strBusqueda As String, _
ByVal pathFicheroOriginal As String, _
Byref pathFicheroSalida As String)
'open document
Dim pdfDocument As New Document(pathFicheroOriginal)
'create TextAbsorber object to find all instances of the input search phrase
Dim textFragmentAbsorber As New Aspose.Pdf.Text.TextFragmentAbsorber(strBusqueda)
'accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber)
'get the extracted text fragments
Dim textFragmentCollection As Aspose.Pdf.Text.TextFragmentCollection = textFragmentAbsorber.TextFragments
'loop through the fragments
For Each textFragment As Aspose.Pdf.Text.TextFragment In textFragmentCollection
Dim textStamp As New TextStamp(strBusqueda)
'set whether stamp is background
textStamp.Background = False
textStamp.Opacity = 100
'set origin
textStamp.XIndent = textFragment.Position.XIndent
textStamp.YIndent = textFragment.Position.YIndent
pdfDocument.Pages(1).Background = Drawing.Color.Transparent
textStamp.TextState.Font = textFragment.TextState.Font
textStamp.TextState.FontSize = textFragment.TextState.FontSize
textStamp.TextState.FontStyle = FontStyles.Bold
textStamp.TextState.ForegroundColor = System.Drawing.Color.Black
textStamp.TextState.BackgroundColor = Drawing.Color.Yellow
pdfDocument.Pages(1).AddStamp(textStamp)
Next textFragment
pdfDocument.Save(pathFicheroSalida)
End Sub
Second try: i can add a stamp over the image, but size doesnt fit.
----------------------------------------------------------------------------------------------
Protected Sub HighLightPDF(ByVal strBusqueda As String, _
ByVal pathFicheroOriginal As String, _
ByVal pathFicheroSalida As String)
'open document
Dim pdfDocument As New Document(pathFicheroOriginal)
'create TextAbsorber object to find all instances of the input search phrase
Dim textFragmentAbsorber As New Aspose.Pdf.Text.TextFragmentAbsorber(strBusqueda)
'accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber)
'get the extracted text fragments
Dim textFragmentCollection As Aspose.Pdf.Text.TextFragmentCollection = textFragmentAbsorber.TextFragments
'loop through the fragments
For Each textFragment As Aspose.Pdf.Text.TextFragment In textFragmentCollection
Dim textStamp As New TextStamp(strBusqueda)
'set whether stamp is background
textStamp.Background = False
textStamp.Opacity = 100
'set origin
textStamp.XIndent = textFragment.Position.XIndent
textStamp.YIndent = textFragment.Position.YIndent
pdfDocument.Pages(1).Background = Drawing.Color.Transparent
textStamp.TextState.Font = textFragment.TextState.Font
textStamp.TextState.FontSize = textFragment.TextState.FontSize
textStamp.TextState.FontStyle = FontStyles.Bold
textStamp.TextState.ForegroundColor = System.Drawing.Color.Black
textStamp.TextState.BackgroundColor = Drawing.Color.Yellow
pdfDocument.Pages(1).AddStamp(textStamp)
Next textFragment
pdfDocument.Save(pathFicheroSalida)
End Sub