Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Mar 15, 2024 7:36 am

Given the following method:

Code: Select all
private void AddHyperlinks(PdfDocument pdfDocument)
{
    var page = pdfDocument.GetSpecificPageByIndex(1);
    PdfTextFinder finder = new PdfTextFinder(page);
    finder.Options.Parameter = TextFindParameter.IgnoreCase;
    var pdfTextFragments = finder.FindAllText();
    foreach (var textFragment in pdfTextFragments)
    {
        foreach (var bounds in textFragment.Bounds)
        {
            PdfUriAnnotation url = new PdfUriAnnotation(bounds);
            url.Uri = "https://en.wikipedia.org/wiki/Climate_change";
            url.Border = new PdfAnnotationBorder(1f);
            url.Color = Color.Blue;
            clarificationPage.Annotations.Add(url);
        }
    }
}


Whenever I inspect the textFragment I get the following information

code.png


As you can see the Text parameter is filled with "\0\0\0" instead of text.
This also prevents me from using the finder.Find("text") because it won't match with the value in pdfTextFragment.text.
Hopefully you can help me.

PaulDictu2
 
Posts: 6
Joined: Mon Mar 11, 2024 7:27 am

Fri Mar 15, 2024 8:18 am

Hello,

Thanks for your inquiry.
To assist us in further investigation, please provide us with your pdf file. You can upload it as an attachment or send it to this email: [email protected] . Thank you in advance.

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Fri Mar 15, 2024 8:22 am

The PDF isn't saved at this point in the code.
All the pages are created but it isn't saved to a disk.

PaulDictu2
 
Posts: 6
Joined: Mon Mar 11, 2024 7:27 am

Fri Mar 15, 2024 8:50 am

Hello,

Thanks for your quick reply.
Sorry, based on the code you provided earlier, we are unable to further investigate your issue. You can provide us with your complete test code, or save your PDF to disk and send it to us. We need to know the content on the PDF page when you call the "FindAllText()" method.

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Fri Mar 15, 2024 8:56 am

I just emailed you the pdf.

PaulDictu2
 
Posts: 6
Joined: Mon Mar 11, 2024 7:27 am

Fri Mar 15, 2024 9:18 am

Hello,

Thanks for your file.
May I ask which part of the content do you want to add hyperlinks to? Did "FindText ()" not match the corresponding content? Please tell us the keyword you are searched for.

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Fri Mar 15, 2024 9:24 am

The word(s) I am searching for are"Meer Info". I also tried "Meer" or "Info" but that also didn't result in any results.

PaulDictu2
 
Posts: 6
Joined: Mon Mar 11, 2024 7:27 am

Fri Mar 15, 2024 9:47 am

Hello,
Thanks for more information.
Sorry, I tested your case with the latest Spire.PDF Pack(Hot Fix) Version:10.3.7, but did not encounter the issue you mentioned. It matched 9 results, as shown in the screenshot below.
FindText.png

I have also attached my test code for your reference. If you are not using the latest version, please upgrade and try again. If your problem still persists, please reply to us with more details about your issue, or provide us with a simplified project that can reproduce your problem. Thank you in advance.
Code: Select all
 PdfDocument pdfDocument = new PdfDocument();
 pdfDocument.LoadFromFile("391105530_3512TP_6_1-158.pdf");
 PdfTextFinder finder = new PdfTextFinder(pdfDocument.Pages[1]);
 finder.Options.Parameter = TextFindParameter.IgnoreCase;
 List<PdfTextFragment> pdfTextFragments = finder.Find("Meer Info");
 foreach (var textFragment in pdfTextFragments)
 {
     foreach (var bounds in textFragment.Bounds)
     {
         //...
     }
 }

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron