简体   繁体   中英

Search for phrases in pdf command line

I need a way to search for phrases (multi-word strings such as "red ball") in a pdf from C#.
I've found a way to open a pdf file from C# and perform a search. However, it searches for each word individually instead of as a phrase. The interesting part is, If I open a pdf file and use the advanced search it will search for it as a complete term instead of two individual words, but it doesn't do that same from the command line.

I've done extensive search on the web and tried everything I can think of (adding quotes, adding \\ ", adding single quotes, using +, &, _, and others between the words). There must be a way to do this because it works within a pdf, I just need a way to call it from the command line. Can anyone help?

Here's what I have. This works, but it searches for each word individually. So it finds "red ball", as well as "red", "ball," "reddening", and "balled" . I just want to find only "red ball" .

string strParams = " /A \"search=" + "red ball" + "\"" + fileDirectory + strFilePath + "\"";
System.Diagnostics.Process.Start("AcroRd32.exe", strParams);

The search parameter is indeed for a list of words only, there is no way to search for a phrase (or more than 32 characters):

Adobe Docs :

You can search only for single words. You cannot search for a string of words

You could try alternate readers or a library .

Sorry, but you have to decompile the file, extract each page content section, decompress it and happy search inside each part. Therefore, you need any of PDF library or write it by yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM