Hi there, I am using Aspose PDF 23.1.1 .Net version. I am using textfragmentabsorber search options and hyperlinking the text to a file or a page. I have some text with strikethroughs, which are also found through textfragmentabsorber, which removes the strikethrough from the output product. Can you please advise how to fix this? I can send sample input file and outfile if required.
Below is my code in vb.net
Blockquote
Private Sub hyperlinkpdfindex(file As String, logfile As String, logfilen As String, errorlog As String)
Try
If IO.Directory.Exists(TextBox2.Text + "\Documents") = False Then
IO.Directory.CreateDirectory(TextBox2.Text + "\Documents")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "PDF Hyperlinker")
Exit Sub
End Try
Dim inputfile As String
inputfile = file
Dim inputFileName As String = Path.GetFileName(inputfile)
Dim filepath As String
filepath = Path.GetDirectoryName(inputfile)
Dim writer As StreamWriter
writer = New StreamWriter(logfile, True)
writer.Close()
Dim writern As StreamWriter
writern = New StreamWriter(logfilen, True)
writern.Close()
Dim writererr As StreamWriter
writererr = New StreamWriter(errorlog, True)
writererr.Close()
Dim filename1 As String
Try
Dim pdfDocument As Document = New Document(inputfile)
Dim textFragmentAbsorber As TextFragmentAbsorber = New TextFragmentAbsorber(TextBox3.Text)
Dim textSearchOptions As TextSearchOptions = New TextSearchOptions(True)
textFragmentAbsorber.TextSearchOptions = textSearchOptions
Dim editor As New PdfContentEditor
editor.BindPdf(pdfDocument)
For i = 1 To pdfDocument.Pages.Count
pdfDocument.Pages(i).Accept(textFragmentAbsorber)
Dim textFragmentCollection As TextFragmentCollection = textFragmentAbsorber.TextFragments
Dim dasharray As Integer() = {}
Dim LEArray As String() = {}
Dim rect As New System.Drawing.Rectangle
Dim blue As System.Drawing.Color = System.Drawing.Color.Blue
For Each textFragment As TextFragment In textFragmentCollection
Dim isStrikethrough As Boolean = textFragment.TextState.StrikeOut
If isStrikethrough = True Then
textFragment.TextState.StrikeOut = True
End If
Dim files() As String = System.IO.Directory.GetFiles(TextBox1.Text, textFragment.Text + ".*", IO.SearchOption.AllDirectories)
If files.Count = 0 Then
writern = New StreamWriter(logfilen, True)
writern.WriteLine("""" + inputfile + """" + "," + textFragment.Text + ",Not Hyperlinked - Matching file not found" + "," + CStr(i))
writern.Close()
Else
If files.Count > 1 Then
Dim sortlist As New List(Of String)
Dim exlist As String() = TextBox4.Text.Split(",")
For Each exl In exlist
sortlist.Add(exl.ToLower)
Next
For Each file In files
Dim fext As String
fext = IO.Path.GetExtension(file)
If Not sortlist.Contains(fext.ToLower) Then
sortlist.Add(fext.ToLower)
End If
Next
Dim sorted = files.OrderBy(Function(s) sortlist.IndexOf(Path.GetExtension(s).ToLower))
filename1 = sorted(0)
If filename1 Is Nothing Then
filename1 = files(0)
End If
Else
filename1 = files(0)
End If
If filename1 Is Nothing Then
writern = New StreamWriter(logfilen, True)
writern.WriteLine("""" + inputfile + """" + "," + textFragment.Text + ",Not Hyperlinked - Matching file not found" + "," + CStr(i))
writern.Close()
Else
If IO.File.Exists((TextBox2.Text) + "\Documents\" + IO.Path.GetFileName(filename1)) Then
'Dim pagetext = pdfDocument.Pages(textFragment.Page.Number)
rect = New System.Drawing.Rectangle(Convert.ToDouble(textFragment.Rectangle.LLX), Convert.ToDouble(Math.Round(textFragment.Rectangle.LLY)), Convert.ToDouble(Math.Round(textFragment.Rectangle.Width + 2)), Convert.ToDouble(Math.Round(textFragment.Rectangle.Height + 1)))
editor.CreateApplicationLink(rect, "Documents/" + IO.Path.GetFileName(filename1), textFragment.Page.Number)
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Blue
' editor.CreateLine(rect, "", CDbl(textFragment.Rectangle.LLX + 1), CDbl(textFragment.Rectangle.LLY - 1), CDbl(textFragment.Rectangle.URX), CDbl(textFragment.Rectangle.LLY - 1), i, 1, blue, "S", dasharray, LEArray)
' editor.CreateLine(rect, "", CDbl(textFragment.Rectangle.LLX + 1), CDbl(textFragment.Rectangle.LLY - 1), CDbl(textFragment.Rectangle.URX), CDbl(textFragment.Rectangle.LLY - 1), i, 1, blue, "S", dasharray, LEArray)
writer = New StreamWriter(logfile, True)
writer.WriteLine("""" + inputfile + """" + "," + textFragment.Text + ",Hyperlinked to " + ".\Documents\" + IO.Path.GetFileName(filename1) + "," + CStr(i))
writer.Close()
dthyper.Rows.Add(IO.Path.GetFileName(filename1))
Else
System.IO.File.Copy(filename1, (TextBox2.Text) + "\Documents\" + IO.Path.GetFileName(filename1))
rect = New System.Drawing.Rectangle(Convert.ToDouble(textFragment.Rectangle.LLX), Convert.ToDouble(Math.Round(textFragment.Rectangle.LLY)), Convert.ToDouble(Math.Round(textFragment.Rectangle.Width + 2)), Convert.ToDouble(Math.Round(textFragment.Rectangle.Height + 1)))
editor.CreateApplicationLink(rect, "Documents/" + IO.Path.GetFileName(filename1), textFragment.Page.Number)
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Blue
'editor.CreateLine(rect, "", CDbl(textFragment.Rectangle.LLX + 1), CDbl(textFragment.Rectangle.LLY - 1), CDbl(textFragment.Rectangle.URX), CDbl(textFragment.Rectangle.LLY - 1), i, 1, blue, "S", dasharray, LEArray)
writer = New StreamWriter(logfile, True)
writer.WriteLine("""" + inputfile + """" + "," + textFragment.Text + ",Hyperlinked to " + ".\Documents\" + IO.Path.GetFileName(filename1) + "," + CStr(i))
writer.Close()
dthyper.Rows.Add(IO.Path.GetFileName(filename1))
End If
End If
End If
Next
textFragmentCollection.Clear()
Next
editor.Save(filepath + "\" + IO.Path.GetFileNameWithoutExtension(inputFileName) + "_Hyperlinked" + IO.Path.GetExtension(inputFileName))
Catch ex As Exception
writererr = New StreamWriter(errorlog, True)
writererr.WriteLine(Now() + " - " + file + " - " + ex.Message)
writererr.Close()
End Try
End Sub