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.

Thu Sep 23, 2021 12:28 pm

Hi, I'm having a problem of the following form.
I am searching for text which is made up of two parts separated by several different empty space symbols such as newlines (\n), carriage returns (\r) spaces and nbsp. So the text is basically as follows
string searched_text = "part1" + " \n\r " + "part2"

When I run PdfPageBase.FindText(searchedText) I find all the appearances in which my "part1" and "part2" appears, regardless of having those newlines spaces and carriage returns between them. But this is not what I am trying to find and I would instead like to have a more literal search of this text. If I use the RegEx property however, I don't find anything.

Given that PdfPageBase.ExtractText().Contains(searched_text) returns true the literal text is contained in the pdf.

So my question is as follows, how can I make the Find Text method pay attention to include the "\n", "\r" and whitespace in its search and not just look for the "part1" + "part2"?

BoneCustomer
 
Posts: 2
Joined: Thu Sep 23, 2021 7:14 am

Fri Sep 24, 2021 2:36 am

Hello Gorazd,

Thanks for your inquiry.
Please try the code snippet below.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("test.pdf");
            pdf.ConvertOptions.FindTextByAbsolutePosition=false;
            PdfTextFind[] finds = pdf.Pages[0].FindText(searchedText,TextFindParameter.CrossLine).Finds;

If it doesn't work for your pdf file, please share us with your pdf file for further investigation. Thanks.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Sun Sep 26, 2021 5:56 am

Hello Gorazd,

Greetings from E-iceblue!
Did the code I provide work for you? Any feedback would be greatly appreciated!

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 27, 2021 7:09 am

Hi, sorry for the late reply, I had a some other tasks in the meantime.
The provided solution cannot work for me, because the field does not exist in my version of PDF.ConvertOptions.
This is what I have in there:
Code: Select all

namespace Spire.Pdf
{
   public class PdfConvertOptions
    {
        public PdfConvertOptions();

        public void SetPdfToDocOptions();
        public void SetPdfToDocOptions(bool usePsMode);
        public void SetPdfToDocOptions(bool usePsMode, bool useFlowRecognitionMode);
        public void SetPdfToHtmlOptions(bool useEmbeddedSvg, bool useEmbeddedImg, int maxPageOneFile);
        public void SetPdfToHtmlOptions(bool useEmbeddedSvg, bool useEmbeddedImg);
        public void SetPdfToHtmlOptions();
        public void SetPdfToHtmlOptions(bool useEmbeddedSvg);
        public void SetPdfToSvgOptions(float wPixel);
        public void SetPdfToSvgOptions();
        public void SetPdfToSvgOptions(float wPixel, float hPixel);
        public void SetPdfToXpsOptions();
        public void SetPdfToXpsOptions(bool usePsMode, bool useInvariantCulture, bool useHighQualityImg);
        public void SetPdfToXpsOptions(bool usePsMode, bool useInvariantCulture);
        public void SetPdfToXpsOptions(bool usePsMode);
        public void SetXpsToPdfOptions();
        public void SetXpsToPdfOptions(bool useHighQualityImg);
    }
}

My Spire version is 7.2.6.0, is that outdated or should I use an older one?

BoneCustomer
 
Posts: 2
Joined: Thu Sep 23, 2021 7:14 am

Mon Sep 27, 2021 9:14 am

Hi Gorazd,

Thanks for your response.
The setting pdf.ConvertOptions.FindTextByAbsolutePosition=false; is included in the latest version(Spire.PDF Pack(Hot Fix) Version:7.9.6). Please download it and have a try.
If it doesn't work for your pdf file, please share us with your pdf file for further investigation.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Wed Sep 29, 2021 6:46 am

Hello Gorazd,

Hope you are doing well.
Has your issue been resolved?
Looking forward to your feedback.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron