| 1 |
= pdfgrep(1) |
| 2 |
:doctype: manpage |
| 3 |
:man source: Pdfgrep |
| 4 |
:man manual: Pdfgrep Manual |
| 5 |
:man version: {pdfgrepversion} |
| 6 |
|
| 7 |
== NAME |
| 8 |
pdfgrep - search PDF files for a regular expression |
| 9 |
|
| 10 |
== SYNOPSIS |
| 11 |
[verse] |
| 12 |
*pdfgrep* ['OPTION'...] 'PATTERN' 'FILE'... |
| 13 |
*pdfgrep* ['OPTION'...] {*-e* 'PATTERN'|*-f* 'FILE'}... 'FILE'... |
| 14 |
*pdfgrep* ['OPTION'...] *-r*|*-R* 'PATTERN' ['FILE'|'DIR'...] |
| 15 |
*pdfgrep* ['OPTION'...] *-r*|*-R* {*-e* 'PATTERN'|*-f* 'FILE'}... ['FILE'|'DIR'...] |
| 16 |
|
| 17 |
== DESCRIPTION |
| 18 |
|
| 19 |
Search for 'PATTERN' in each PDF 'FILE' and print matching lines. By |
| 20 |
default, 'PATTERN' is an extended regular expression. |
| 21 |
|
| 22 |
*pdfgrep* tries to be mostly compatible with *GNU grep* with some |
| 23 |
PDF-specific distinctions and additional options. Most notably, *-n* |
| 24 |
prints page instead of line numbers. |
| 25 |
|
| 26 |
== OPTIONS |
| 27 |
=== General Information |
| 28 |
|
| 29 |
*--help* :: Print a short summary of the options. |
| 30 |
|
| 31 |
*-V*, *--version* :: Show version information. |
| 32 |
|
| 33 |
=== Pattern Interpretation |
| 34 |
|
| 35 |
*-F*, *--fixed-strings* :: Interpret 'PATTERN' as a list of fixed |
| 36 |
strings separated by newlines, any of which is to be matched. |
| 37 |
|
| 38 |
*-P*, *--perl-regexp* :: Interpret 'PATTERN' as a Perl compatible |
| 39 |
regular expression (PCRE2). See 'pcre2syntax'(3) for a quick overview. |
| 40 |
|
| 41 |
=== Matching Control |
| 42 |
|
| 43 |
*-e* 'PATTERN', *--regexp=*'PATTERN' :: Use 'PATTERN' as the pattern |
| 44 |
to search for. If this option is specified multiple times or |
| 45 |
combined with *--file*, all patterns are tried in turn until one of |
| 46 |
them matches. |
| 47 |
|
| 48 |
*-f* 'FILE', *--file=*'FILE' :: Read patterns from 'FILE', one per |
| 49 |
line. If 'FILE' contains multiple patterns or if this option is |
| 50 |
applied multiple times or combined with *-e*, all patterns are tried |
| 51 |
in turn until one of them matches. An empty pattern list matches |
| 52 |
nothing. |
| 53 |
|
| 54 |
*-i*, *--ignore-case* :: Ignore case distinctions in both the |
| 55 |
'PATTERN' and the input files. |
| 56 |
|
| 57 |
=== General Output Control |
| 58 |
|
| 59 |
*-c*, *--count* :: Suppress normal output. Instead print the number of |
| 60 |
matches for each input file. Note that unlike grep, multiple matches |
| 61 |
on the same page will be counted individually. |
| 62 |
|
| 63 |
*-p*, *--page-count* :: Like *-c*, but prints the number of matches |
| 64 |
per page. Implies *-n*. |
| 65 |
|
| 66 |
*--color* 'WHEN' :: Surround file names, page numbers and matched text |
| 67 |
with escape sequences to display them in color on the terminal. |
| 68 |
'WHEN' can be: |
| 69 |
+ |
| 70 |
[horizontal] |
| 71 |
*always* ;; Always use colors, even when stdout is not a terminal. |
| 72 |
*never* ;; Do not use colors. |
| 73 |
*auto* ;; Use colors only when stdout is a terminal (this is the |
| 74 |
default). |
| 75 |
|
| 76 |
*-L*, *--files-without-match* :: Suppress normal output. Instead print |
| 77 |
the name of each input file that doesn't contain a match. This works |
| 78 |
well with *-Z*, but many other output options like *-n* or *-c* are |
| 79 |
ignored when *-L* is specified. |
| 80 |
|
| 81 |
*-l*, *--files-with-matches* :: Suppress normal output. Instead print |
| 82 |
the name of each input file that contains a match. This works well |
| 83 |
with *-Z*, but many other output options like *-n* or *-c* are |
| 84 |
ignored when *-l* is specified. |
| 85 |
|
| 86 |
*-m*, *--max-count* 'NUM' :: Stop reading a file after 'NUM' matches. |
| 87 |
When the -c or --count option is also used, pdfgrep does not output |
| 88 |
a count greater than 'NUM'. |
| 89 |
|
| 90 |
*-o*, *--only-matching* :: Print only the matched part of a line |
| 91 |
without any surrounding context. |
| 92 |
|
| 93 |
*-q*, *--quiet* :: Suppress all normal output to stdout. Exit |
| 94 |
immediately with exit status 0 if a match is found, even in case of |
| 95 |
errors. Use this if you only care about the presence of matches, not |
| 96 |
their number or content. |
| 97 |
|
| 98 |
=== Line Prefix Control |
| 99 |
|
| 100 |
*-H*, *--with-filename* :: Print the file name for each match. This is |
| 101 |
the default setting when there is more than one file to search. |
| 102 |
|
| 103 |
*-h*, *--no-filename* :: Suppress the prefixing of file name on |
| 104 |
output. This is the default setting when there is only one file to |
| 105 |
search. |
| 106 |
|
| 107 |
*-n*, *--page-number*[='TYPE'] :: Prefix each match with the number of the page |
| 108 |
where it was found. |
| 109 |
+ |
| 110 |
The optional argument 'TYPE' controls how page numbers are |
| 111 |
determined. If present, it can be one of the following: |
| 112 |
+ |
| 113 |
[horizontal] |
| 114 |
*index* ;; The index of the page in the PDF, starting at 1 for the |
| 115 |
first page. This is the default. |
| 116 |
*label* ;; The PDF page label. This can be an arbitrary string per |
| 117 |
page, set by the PDF creator (e.g. roman numerals for the first few |
| 118 |
pages). |
| 119 |
|
| 120 |
*-Z*, *--null* :: Output a null byte (called 'NUL' in ASCII and \'\0' |
| 121 |
in C) instead of the colon that usually separates a filename from |
| 122 |
the rest of the line. This option makes the output unambiguous in |
| 123 |
the presence of colons, spaces or newlines in the filename. It can |
| 124 |
be used in conjunction with commands such as 'xargs -0' or |
| 125 |
'perl -0'. |
| 126 |
|
| 127 |
*--match-prefix-separator* 'SEP' :: Changes the colon used to separate |
| 128 |
filename, line number and text in the output to 'SEP', which can be |
| 129 |
an arbitrary string. This is useful when filenames contain colons, |
| 130 |
but only for interactive usage. For scripting, *--null* should be |
| 131 |
used. |
| 132 |
|
| 133 |
=== Context Control |
| 134 |
|
| 135 |
*-A* 'NUM', *--after-context=NUM*:: Print 'NUM' lines of context after |
| 136 |
matching lines. Contiguous groups of matches are separated by a line |
| 137 |
containing *--*. With *-o*, this option has no effect. |
| 138 |
|
| 139 |
*-B* 'NUM', *--before-context=NUM*:: Print 'NUM' lines of context |
| 140 |
before matching lines. Contiguous groups of matches are separated by |
| 141 |
a line containing *--*. With *-o*, this option has no effect. |
| 142 |
|
| 143 |
*-C* 'NUM', *--context=NUM*:: Print 'NUM' lines of context before and |
| 144 |
after matching lines. Contiguous groups of matches are separated by |
| 145 |
a line containing *--*. With *-o*, this option has no effect. |
| 146 |
|
| 147 |
=== File Selection |
| 148 |
|
| 149 |
*-r*, *--recursive*:: Recursively search all files (restricted by |
| 150 |
*--include* and *--exclude*) under each directory, following symlinks |
| 151 |
only if they are on the command line. |
| 152 |
|
| 153 |
*-R*, *--dereference-recursive*:: Same as *-r*, but follows all |
| 154 |
symlinks. |
| 155 |
|
| 156 |
*--exclude=*'GLOB' :: Skip files whose base name matches 'GLOB'. See |
| 157 |
'glob'(7) for wildcards you can use. You can use this option |
| 158 |
multiple times to exclude more patterns. It takes precedence over |
| 159 |
*--include*. Note, that in- and excludes apply only to files found |
| 160 |
via *--recursive* and not to the argument list. |
| 161 |
|
| 162 |
*--include=*'GLOB' :: Only search files whose base name matches |
| 163 |
'GLOB'. See *--exclude* for details. The default is |
| 164 |
'*.[Pp][Dd][Ff]'. |
| 165 |
|
| 166 |
=== Other Options |
| 167 |
|
| 168 |
*--cache* :: Use a cache for the rendered text to speed up the |
| 169 |
operation on large files. |
| 170 |
|
| 171 |
*--password=*'PASSWORD' :: Use PASSWORD to decrypt the PDF-files. Can |
| 172 |
be specified multiple times; all passwords will be tried on all |
| 173 |
PDFs. |
| 174 |
*Note* that this password will show up in your command history and |
| 175 |
the output of 'ps'(1). So please do not use this if the security of |
| 176 |
'PASSWORD' is important. |
| 177 |
|
| 178 |
*--page-range=*'RANGE' :: Limit search to a specified set of pages. |
| 179 |
'RANGE' is a comma separated list of either a single page number or |
| 180 |
a range expression of the form `PAGE1-PAGE2`. Example: |
| 181 |
`2-3,5,7-10`. |
| 182 |
|
| 183 |
*--debug* :: Enable debug output. *Note*: Due to limitations of |
| 184 |
poppler before version 0.30.0, some debug output is also printed |
| 185 |
without *--debug* when using such a poppler version. |
| 186 |
|
| 187 |
*--warn-empty* :: Print a warning to 'stderr' if a PDF contains no |
| 188 |
searchable text. This is the case for PDFs that consist only of |
| 189 |
images, for example scanned documents. |
| 190 |
|
| 191 |
*--unac* :: Remove accents and ligatures from both the search pattern |
| 192 |
and the PDF documents. This is useful if you want to search for a |
| 193 |
word containing "ae", but the PDF uses the single character "æ" |
| 194 |
instead. See *unac(3)* and *unaccent(1)* for details. |
| 195 |
+ |
| 196 |
*This option is experimental and only available if pdfgrep is |
| 197 |
compiled with unac support.* |
| 198 |
|
| 199 |
== EXIT STATUS |
| 200 |
Normally, the exit status is 0 if at least one match is found, 1 if no |
| 201 |
match is found and 2 if an error occurred. But if the *--quiet* or |
| 202 |
*-q* option is used and a match was found, *pdfgrep* will return 0 |
| 203 |
regardless of errors. |
| 204 |
|
| 205 |
== ENVIRONMENT VARIABLES |
| 206 |
The behavior of *pdfgrep* is affected by the following environment |
| 207 |
variable. |
| 208 |
|
| 209 |
*GREP_COLORS* :: Specifies the colors and other attributes used to |
| 210 |
highlight various parts of the output. The syntax and values are |
| 211 |
like *GREP_COLORS* of *grep*. See 'grep'(1) for more details. |
| 212 |
Currently only the capabilities *mt*, *ms*, *mc*, *fn*, *ln* and |
| 213 |
*se* are used by *pdfgrep*, where *mt*, *ms* and *mc* have the same |
| 214 |
effect. |
| 215 |
|
| 216 |
== FILES |
| 217 |
|
| 218 |
*$\{XDG_CACHE_HOME\}/pdfgrep/** :: Cache files written and used when |
| 219 |
*--cache* is enabled. At most 200 cache entries older than a day are |
| 220 |
retained. |
| 221 |
|
| 222 |
== Examples |
| 223 |
*Print the first ten lines matching 'pattern' and print their page number:* :: |
| 224 |
+ |
| 225 |
-------------------------------------------------- |
| 226 |
pdfgrep -n --max-count 10 pattern foo.pdf |
| 227 |
-------------------------------------------------- |
| 228 |
|
| 229 |
*Search all .pdf files whose names begin with 'foo' recursively in the current directory:* :: |
| 230 |
+ |
| 231 |
-------------------------------------------------- |
| 232 |
pdfgrep -r --include "foo*.pdf" pattern |
| 233 |
-------------------------------------------------- |
| 234 |
|
| 235 |
*Search all PDFs in the current directory for 'foo' that also contain 'bar':*:: |
| 236 |
+ |
| 237 |
-------------------------------------------------- |
| 238 |
pdfgrep -Z --files-with-matches "bar" *.pdf | xargs -0 pdfgrep -H foo |
| 239 |
-------------------------------------------------- |
| 240 |
|
| 241 |
*Search all .pdf files that are smaller than 12M recursively in the current directory:* :: |
| 242 |
+ |
| 243 |
-------------------------------------------------- |
| 244 |
find . -name "*.pdf" -size -12M -print0 | xargs -0 pdfgrep pattern |
| 245 |
-------------------------------------------------- |
| 246 |
+ |
| 247 |
Note that in contrast to the previous examples, this task could not be |
| 248 |
solved with pdfgrep alone, but the Unix tools *find(1)* and *xargs(1)* |
| 249 |
had to be used. That's because pdfgrep itself doesn't include options |
| 250 |
to exclude files by their size. But as you see, it doesn't have to! |
| 251 |
|
| 252 |
*Search all .pdf files in the current directory in parallel on a multcore CPU* :: |
| 253 |
+ |
| 254 |
-------------------------------------------------- |
| 255 |
find . -name "*.pdf" -print0 | parallel -q0 pdfgrep -H foobar |
| 256 |
-------------------------------------------------- |
| 257 |
+ |
| 258 |
This uses GNU *parallel(1)* in addition fo *find(1)* to search multiple files in |
| 259 |
parallel on multicore processors. Doing this can lead to a good speedup if you |
| 260 |
have multiple files to search and an underused CPU. |
| 261 |
|
| 262 |
== BUGS |
| 263 |
=== Reporting Bugs |
| 264 |
Bugs can either be reportet to the mailing list |
| 265 |
([email protected]) or to the bugtracker on gitlab |
| 266 |
(https://gitlab.com/pdfgrep/pdfgrep/issues). |
| 267 |
|
| 268 |
== AUTHORS |
| 269 |
*pdfgrep* is maintained by Hans-Peter Deifel. |
| 270 |
|
| 271 |
See the 'AUTHORS' file in the source for a full list of contributors. |
| 272 |
|
| 273 |
|
| 274 |
== SEE ALSO |
| 275 |
grep(1), pcre2(3), regex(7) |
| 276 |
|
| 277 |
See pdfgrep's website https://pdfgrep.org for more information, |
| 278 |
downloads, git repository and more. |