doc/pdfgrep.1
raw| 1 | '\" t |
| 2 | .\" Title: pdfgrep |
| 3 | .\" Author: [see the "AUTHORS" section] |
| 4 | .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/> |
| 5 | .\" Date: 03/15/2024 |
| 6 | .\" Manual: Pdfgrep Manual |
| 7 | .\" Source: Pdfgrep 2.1.2 |
| 8 | .\" Language: English |
| 9 | .\" |
| 10 | .TH "PDFGREP" "1" "03/15/2024" "Pdfgrep 2\&.1\&.2" "Pdfgrep Manual" |
| 11 | .\" ----------------------------------------------------------------- |
| 12 | .\" * Define some portability stuff |
| 13 | .\" ----------------------------------------------------------------- |
| 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 15 | .\" http://bugs.debian.org/507673 |
| 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 18 | .ie \n(.g .ds Aq \(aq |
| 19 | .el .ds Aq ' |
| 20 | .\" ----------------------------------------------------------------- |
| 21 | .\" * set default formatting |
| 22 | .\" ----------------------------------------------------------------- |
| 23 | .\" disable hyphenation |
| 24 | .nh |
| 25 | .\" disable justification (adjust text to left margin only) |
| 26 | .ad l |
| 27 | .\" ----------------------------------------------------------------- |
| 28 | .\" * MAIN CONTENT STARTS HERE * |
| 29 | .\" ----------------------------------------------------------------- |
| 30 | .SH "NAME" |
| 31 | pdfgrep \- search PDF files for a regular expression |
| 32 | .SH "SYNOPSIS" |
| 33 | .sp |
| 34 | .nf |
| 35 | \fBpdfgrep\fR [\fIOPTION\fR\&...] \fIPATTERN\fR \fIFILE\fR\&... |
| 36 | \fBpdfgrep\fR [\fIOPTION\fR\&...] {\fB\-e\fR \fIPATTERN\fR|\fB\-f\fR \fIFILE\fR}\&... \fIFILE\fR\&... |
| 37 | \fBpdfgrep\fR [\fIOPTION\fR\&...] \fB\-r\fR|\fB\-R\fR \fIPATTERN\fR [\fIFILE\fR|\fIDIR\fR\&...] |
| 38 | \fBpdfgrep\fR [\fIOPTION\fR\&...] \fB\-r\fR|\fB\-R\fR {\fB\-e\fR \fIPATTERN\fR|\fB\-f\fR \fIFILE\fR}\&... [\fIFILE\fR|\fIDIR\fR\&...] |
| 39 | .fi |
| 40 | .SH "DESCRIPTION" |
| 41 | .sp |
| 42 | Search for \fIPATTERN\fR in each PDF \fIFILE\fR and print matching lines\&. By default, \fIPATTERN\fR is an extended regular expression\&. |
| 43 | .sp |
| 44 | \fBpdfgrep\fR tries to be mostly compatible with \fBGNU grep\fR with some PDF\-specific distinctions and additional options\&. Most notably, \fB\-n\fR prints page instead of line numbers\&. |
| 45 | .SH "OPTIONS" |
| 46 | .SS "General Information" |
| 47 | .PP |
| 48 | \fB\-\-help\fR |
| 49 | .RS 4 |
| 50 | Print a short summary of the options\&. |
| 51 | .RE |
| 52 | .PP |
| 53 | \fB\-V\fR, \fB\-\-version\fR |
| 54 | .RS 4 |
| 55 | Show version information\&. |
| 56 | .RE |
| 57 | .SS "Pattern Interpretation" |
| 58 | .PP |
| 59 | \fB\-F\fR, \fB\-\-fixed\-strings\fR |
| 60 | .RS 4 |
| 61 | Interpret |
| 62 | \fIPATTERN\fR |
| 63 | as a list of fixed strings separated by newlines, any of which is to be matched\&. |
| 64 | .RE |
| 65 | .PP |
| 66 | \fB\-P\fR, \fB\-\-perl\-regexp\fR |
| 67 | .RS 4 |
| 68 | Interpret |
| 69 | \fIPATTERN\fR |
| 70 | as a Perl compatible regular expression (PCRE2)\&. See |
| 71 | \fIpcre2syntax\fR(3) for a quick overview\&. |
| 72 | .RE |
| 73 | .SS "Matching Control" |
| 74 | .PP |
| 75 | \fB\-e\fR \fIPATTERN\fR, \fB\-\-regexp=\fR\fIPATTERN\fR |
| 76 | .RS 4 |
| 77 | Use |
| 78 | \fIPATTERN\fR |
| 79 | as the pattern to search for\&. If this option is specified multiple times or combined with |
| 80 | \fB\-\-file\fR, all patterns are tried in turn until one of them matches\&. |
| 81 | .RE |
| 82 | .PP |
| 83 | \fB\-f\fR \fIFILE\fR, \fB\-\-file=\fR\fIFILE\fR |
| 84 | .RS 4 |
| 85 | Read patterns from |
| 86 | \fIFILE\fR, one per line\&. If |
| 87 | \fIFILE\fR |
| 88 | contains multiple patterns or if this option is applied multiple times or combined with |
| 89 | \fB\-e\fR, all patterns are tried in turn until one of them matches\&. An empty pattern list matches nothing\&. |
| 90 | .RE |
| 91 | .PP |
| 92 | \fB\-i\fR, \fB\-\-ignore\-case\fR |
| 93 | .RS 4 |
| 94 | Ignore case distinctions in both the |
| 95 | \fIPATTERN\fR |
| 96 | and the input files\&. |
| 97 | .RE |
| 98 | .SS "General Output Control" |
| 99 | .PP |
| 100 | \fB\-c\fR, \fB\-\-count\fR |
| 101 | .RS 4 |
| 102 | Suppress normal output\&. Instead print the number of matches for each input file\&. Note that unlike grep, multiple matches on the same page will be counted individually\&. |
| 103 | .RE |
| 104 | .PP |
| 105 | \fB\-p\fR, \fB\-\-page\-count\fR |
| 106 | .RS 4 |
| 107 | Like |
| 108 | \fB\-c\fR, but prints the number of matches per page\&. Implies |
| 109 | \fB\-n\fR\&. |
| 110 | .RE |
| 111 | .PP |
| 112 | \fB\-\-color\fR \fIWHEN\fR |
| 113 | .RS 4 |
| 114 | Surround file names, page numbers and matched text with escape sequences to display them in color on the terminal\&. |
| 115 | \fIWHEN\fR |
| 116 | can be: |
| 117 | .TS |
| 118 | tab(:); |
| 119 | lt lt |
| 120 | lt lt |
| 121 | lt lt. |
| 122 | T{ |
| 123 | \fBalways\fR |
| 124 | T}:T{ |
| 125 | Always use colors, even when stdout is not a terminal\&. |
| 126 | T} |
| 127 | T{ |
| 128 | \fBnever\fR |
| 129 | T}:T{ |
| 130 | Do not use colors\&. |
| 131 | T} |
| 132 | T{ |
| 133 | \fBauto\fR |
| 134 | T}:T{ |
| 135 | Use colors only when stdout is a terminal (this is the default)\&. |
| 136 | T} |
| 137 | .TE |
| 138 | .sp 1 |
| 139 | .RE |
| 140 | .PP |
| 141 | \fB\-L\fR, \fB\-\-files\-without\-match\fR |
| 142 | .RS 4 |
| 143 | Suppress normal output\&. Instead print the name of each input file that doesn\(cqt contain a match\&. This works well with |
| 144 | \fB\-Z\fR, but many other output options like |
| 145 | \fB\-n\fR |
| 146 | or |
| 147 | \fB\-c\fR |
| 148 | are ignored when |
| 149 | \fB\-L\fR |
| 150 | is specified\&. |
| 151 | .RE |
| 152 | .PP |
| 153 | \fB\-l\fR, \fB\-\-files\-with\-matches\fR |
| 154 | .RS 4 |
| 155 | Suppress normal output\&. Instead print the name of each input file that contains a match\&. This works well with |
| 156 | \fB\-Z\fR, but many other output options like |
| 157 | \fB\-n\fR |
| 158 | or |
| 159 | \fB\-c\fR |
| 160 | are ignored when |
| 161 | \fB\-l\fR |
| 162 | is specified\&. |
| 163 | .RE |
| 164 | .PP |
| 165 | \fB\-m\fR, \fB\-\-max\-count\fR \fINUM\fR |
| 166 | .RS 4 |
| 167 | Stop reading a file after |
| 168 | \fINUM\fR |
| 169 | matches\&. When the \-c or \-\-count option is also used, pdfgrep does not output a count greater than |
| 170 | \fINUM\fR\&. |
| 171 | .RE |
| 172 | .PP |
| 173 | \fB\-o\fR, \fB\-\-only\-matching\fR |
| 174 | .RS 4 |
| 175 | Print only the matched part of a line without any surrounding context\&. |
| 176 | .RE |
| 177 | .PP |
| 178 | \fB\-q\fR, \fB\-\-quiet\fR |
| 179 | .RS 4 |
| 180 | Suppress all normal output to stdout\&. Exit immediately with exit status 0 if a match is found, even in case of errors\&. Use this if you only care about the presence of matches, not their number or content\&. |
| 181 | .RE |
| 182 | .SS "Line Prefix Control" |
| 183 | .PP |
| 184 | \fB\-H\fR, \fB\-\-with\-filename\fR |
| 185 | .RS 4 |
| 186 | Print the file name for each match\&. This is the default setting when there is more than one file to search\&. |
| 187 | .RE |
| 188 | .PP |
| 189 | \fB\-h\fR, \fB\-\-no\-filename\fR |
| 190 | .RS 4 |
| 191 | Suppress the prefixing of file name on output\&. This is the default setting when there is only one file to search\&. |
| 192 | .RE |
| 193 | .PP |
| 194 | \fB\-n\fR, \fB\-\-page\-number\fR[=\fITYPE\fR] |
| 195 | .RS 4 |
| 196 | Prefix each match with the number of the page where it was found\&. |
| 197 | .sp |
| 198 | The optional argument |
| 199 | \fITYPE\fR |
| 200 | controls how page numbers are determined\&. If present, it can be one of the following: |
| 201 | .TS |
| 202 | tab(:); |
| 203 | lt lt |
| 204 | lt lt. |
| 205 | T{ |
| 206 | \fBindex\fR |
| 207 | T}:T{ |
| 208 | The index of the page in the PDF, starting at 1 for the first page\&. This is the default\&. |
| 209 | T} |
| 210 | T{ |
| 211 | \fBlabel\fR |
| 212 | T}:T{ |
| 213 | The PDF page label\&. This can be an arbitrary string per page, set by the PDF creator (e\&.g\&. roman numerals for the first few pages)\&. |
| 214 | T} |
| 215 | .TE |
| 216 | .sp 1 |
| 217 | .RE |
| 218 | .PP |
| 219 | \fB\-Z\fR, \fB\-\-null\fR |
| 220 | .RS 4 |
| 221 | Output a null byte (called |
| 222 | \fINUL\fR |
| 223 | in ASCII and \*(Aq\e0\*(Aq in C) instead of the colon that usually separates a filename from the rest of the line\&. This option makes the output unambiguous in the presence of colons, spaces or newlines in the filename\&. It can be used in conjunction with commands such as |
| 224 | \fIxargs\ \&\-0\fR |
| 225 | or |
| 226 | \fIperl\ \&\-0\fR\&. |
| 227 | .RE |
| 228 | .PP |
| 229 | \fB\-\-match\-prefix\-separator\fR \fISEP\fR |
| 230 | .RS 4 |
| 231 | Changes the colon used to separate filename, line number and text in the output to |
| 232 | \fISEP\fR, which can be an arbitrary string\&. This is useful when filenames contain colons, but only for interactive usage\&. For scripting, |
| 233 | \fB\-\-null\fR |
| 234 | should be used\&. |
| 235 | .RE |
| 236 | .SS "Context Control" |
| 237 | .PP |
| 238 | \fB\-A\fR \fINUM\fR, \fB\-\-after\-context=NUM\fR |
| 239 | .RS 4 |
| 240 | |
| 241 | \fINUM\fR |
| 242 | lines of context after matching lines\&. Contiguous groups of matches are separated by a line containing |
| 243 | \fB\-\-\fR\&. With |
| 244 | \fB\-o\fR, this option has no effect\&. |
| 245 | .RE |
| 246 | .PP |
| 247 | \fB\-B\fR \fINUM\fR, \fB\-\-before\-context=NUM\fR |
| 248 | .RS 4 |
| 249 | |
| 250 | \fINUM\fR |
| 251 | lines of context before matching lines\&. Contiguous groups of matches are separated by a line containing |
| 252 | \fB\-\-\fR\&. With |
| 253 | \fB\-o\fR, this option has no effect\&. |
| 254 | .RE |
| 255 | .PP |
| 256 | \fB\-C\fR \fINUM\fR, \fB\-\-context=NUM\fR |
| 257 | .RS 4 |
| 258 | |
| 259 | \fINUM\fR |
| 260 | lines of context before and after matching lines\&. Contiguous groups of matches are separated by a line containing |
| 261 | \fB\-\-\fR\&. With |
| 262 | \fB\-o\fR, this option has no effect\&. |
| 263 | .RE |
| 264 | .SS "File Selection" |
| 265 | .PP |
| 266 | \fB\-r\fR, \fB\-\-recursive\fR |
| 267 | .RS 4 |
| 268 | Recursively search all files (restricted by |
| 269 | \fB\-\-include\fR |
| 270 | and |
| 271 | \fB\-\-exclude\fR) under each directory, following symlinks only if they are on the command line\&. |
| 272 | .RE |
| 273 | .PP |
| 274 | \fB\-R\fR, \fB\-\-dereference\-recursive\fR |
| 275 | .RS 4 |
| 276 | Same as |
| 277 | \fB\-r\fR, but follows all symlinks\&. |
| 278 | .RE |
| 279 | .PP |
| 280 | \fB\-\-exclude=\fR\fIGLOB\fR |
| 281 | .RS 4 |
| 282 | Skip files whose base name matches |
| 283 | \fIGLOB\fR\&. See |
| 284 | \fIglob\fR(7) for wildcards you can use\&. You can use this option multiple times to exclude more patterns\&. It takes precedence over |
| 285 | \fB\-\-include\fR\&. Note, that in\- and excludes apply only to files found via |
| 286 | \fB\-\-recursive\fR |
| 287 | and not to the argument list\&. |
| 288 | .RE |
| 289 | .PP |
| 290 | \fB\-\-include=\fR\fIGLOB\fR |
| 291 | .RS 4 |
| 292 | Only search files whose base name matches |
| 293 | \fIGLOB\fR\&. See |
| 294 | \fB\-\-exclude\fR |
| 295 | for details\&. The default is |
| 296 | \fI*\&.[Pp][Dd][Ff]\fR\&. |
| 297 | .RE |
| 298 | .SS "Other Options" |
| 299 | .PP |
| 300 | \fB\-\-cache\fR |
| 301 | .RS 4 |
| 302 | Use a cache for the rendered text to speed up the operation on large files\&. |
| 303 | .RE |
| 304 | .PP |
| 305 | \fB\-\-password=\fR\fIPASSWORD\fR |
| 306 | .RS 4 |
| 307 | Use PASSWORD to decrypt the PDF\-files\&. Can be specified multiple times; all passwords will be tried on all PDFs\&. |
| 308 | \fBNote\fR |
| 309 | that this password will show up in your command history and the output of |
| 310 | \fIps\fR(1)\&. So please do not use this if the security of |
| 311 | \fIPASSWORD\fR |
| 312 | is important\&. |
| 313 | .RE |
| 314 | .PP |
| 315 | \fB\-\-page\-range=\fR\fIRANGE\fR |
| 316 | .RS 4 |
| 317 | Limit search to a specified set of pages\&. |
| 318 | \fIRANGE\fR |
| 319 | is a comma separated list of either a single page number or a range expression of the form |
| 320 | PAGE1\-PAGE2\&. Example: |
| 321 | 2\-3,5,7\-10\&. |
| 322 | .RE |
| 323 | .PP |
| 324 | \fB\-\-debug\fR |
| 325 | .RS 4 |
| 326 | Enable debug output\&. |
| 327 | \fBNote\fR: Due to limitations of poppler before version 0\&.30\&.0, some debug output is also printed without |
| 328 | \fB\-\-debug\fR |
| 329 | when using such a poppler version\&. |
| 330 | .RE |
| 331 | .PP |
| 332 | \fB\-\-warn\-empty\fR |
| 333 | .RS 4 |
| 334 | Print a warning to |
| 335 | \fIstderr\fR |
| 336 | if a PDF contains no searchable text\&. This is the case for PDFs that consist only of images, for example scanned documents\&. |
| 337 | .RE |
| 338 | .PP |
| 339 | \fB\-\-unac\fR |
| 340 | .RS 4 |
| 341 | Remove accents and ligatures from both the search pattern and the PDF documents\&. This is useful if you want to search for a word containing "ae", but the PDF uses the single character "æ" instead\&. See |
| 342 | \fBunac(3)\fR |
| 343 | and |
| 344 | \fBunaccent(1)\fR |
| 345 | for details\&. |
| 346 | .sp |
| 347 | \fBThis option is experimental and only available if pdfgrep is compiled with unac support\&.\fR |
| 348 | .RE |
| 349 | .SH "EXIT STATUS" |
| 350 | .sp |
| 351 | Normally, the exit status is 0 if at least one match is found, 1 if no match is found and 2 if an error occurred\&. But if the \fB\-\-quiet\fR or \fB\-q\fR option is used and a match was found, \fBpdfgrep\fR will return 0 regardless of errors\&. |
| 352 | .SH "ENVIRONMENT VARIABLES" |
| 353 | .sp |
| 354 | The behavior of \fBpdfgrep\fR is affected by the following environment variable\&. |
| 355 | .PP |
| 356 | \fBGREP_COLORS\fR |
| 357 | .RS 4 |
| 358 | Specifies the colors and other attributes used to highlight various parts of the output\&. The syntax and values are like |
| 359 | \fBGREP_COLORS\fR |
| 360 | of |
| 361 | \fBgrep\fR\&. See |
| 362 | \fIgrep\fR(1) for more details\&. Currently only the capabilities |
| 363 | \fBmt\fR, |
| 364 | \fBms\fR, |
| 365 | \fBmc\fR, |
| 366 | \fBfn\fR, |
| 367 | \fBln\fR |
| 368 | and |
| 369 | \fBse\fR |
| 370 | are used by |
| 371 | \fBpdfgrep\fR, where |
| 372 | \fBmt\fR, |
| 373 | \fBms\fR |
| 374 | and |
| 375 | \fBmc\fR |
| 376 | have the same effect\&. |
| 377 | .RE |
| 378 | .SH "FILES" |
| 379 | .PP |
| 380 | \fB${XDG_CACHE_HOME}/pdfgrep/\fR* |
| 381 | .RS 4 |
| 382 | Cache files written and used when |
| 383 | \fB\-\-cache\fR |
| 384 | is enabled\&. At most 200 cache entries older than a day are retained\&. |
| 385 | .RE |
| 386 | .SH "EXAMPLES" |
| 387 | .PP |
| 388 | \fBPrint the first ten lines matching \fR\fB\fIpattern\fR\fR\fB and print their page number:\fR |
| 389 | .RS 4 |
| 390 | .sp |
| 391 | .if n \{\ |
| 392 | .RS 4 |
| 393 | .\} |
| 394 | .nf |
| 395 | pdfgrep \-n \-\-max\-count 10 pattern foo\&.pdf |
| 396 | .fi |
| 397 | .if n \{\ |
| 398 | .RE |
| 399 | .\} |
| 400 | .RE |
| 401 | .PP |
| 402 | \fBSearch all \&.pdf files whose names begin with \fR\fB\fIfoo\fR\fR\fB recursively in the current directory:\fR |
| 403 | .RS 4 |
| 404 | .sp |
| 405 | .if n \{\ |
| 406 | .RS 4 |
| 407 | .\} |
| 408 | .nf |
| 409 | pdfgrep \-r \-\-include "foo*\&.pdf" pattern |
| 410 | .fi |
| 411 | .if n \{\ |
| 412 | .RE |
| 413 | .\} |
| 414 | .RE |
| 415 | .PP |
| 416 | \fBSearch all PDFs in the current directory for \fR\fB\fIfoo\fR\fR\fB that also contain \fR\fB\fIbar\fR\fR\fB:\fR |
| 417 | .RS 4 |
| 418 | .sp |
| 419 | .if n \{\ |
| 420 | .RS 4 |
| 421 | .\} |
| 422 | .nf |
| 423 | pdfgrep \-Z \-\-files\-with\-matches "bar" *\&.pdf | xargs \-0 pdfgrep \-H foo |
| 424 | .fi |
| 425 | .if n \{\ |
| 426 | .RE |
| 427 | .\} |
| 428 | .RE |
| 429 | .PP |
| 430 | \fBSearch all \&.pdf files that are smaller than 12M recursively in the current directory:\fR |
| 431 | .RS 4 |
| 432 | .sp |
| 433 | .if n \{\ |
| 434 | .RS 4 |
| 435 | .\} |
| 436 | .nf |
| 437 | find \&. \-name "*\&.pdf" \-size \-12M \-print0 | xargs \-0 pdfgrep pattern |
| 438 | .fi |
| 439 | .if n \{\ |
| 440 | .RE |
| 441 | .\} |
| 442 | .sp |
| 443 | Note that in contrast to the previous examples, this task could not be solved with pdfgrep alone, but the Unix tools |
| 444 | \fBfind(1)\fR |
| 445 | and |
| 446 | \fBxargs(1)\fR |
| 447 | had to be used\&. That\(cqs because pdfgrep itself doesn\(cqt include options to exclude files by their size\&. But as you see, it doesn\(cqt have to! |
| 448 | .RE |
| 449 | .PP |
| 450 | \fBSearch all \&.pdf files in the current directory in parallel on a multcore CPU\fR |
| 451 | .RS 4 |
| 452 | .sp |
| 453 | .if n \{\ |
| 454 | .RS 4 |
| 455 | .\} |
| 456 | .nf |
| 457 | find \&. \-name "*\&.pdf" \-print0 | parallel \-q0 pdfgrep \-H foobar |
| 458 | .fi |
| 459 | .if n \{\ |
| 460 | .RE |
| 461 | .\} |
| 462 | .sp |
| 463 | This uses GNU |
| 464 | \fBparallel(1)\fR |
| 465 | in addition fo |
| 466 | \fBfind(1)\fR |
| 467 | to search multiple files in parallel on multicore processors\&. Doing this can lead to a good speedup if you have multiple files to search and an underused CPU\&. |
| 468 | .RE |
| 469 | .SH "BUGS" |
| 470 | .SS "Reporting Bugs" |
| 471 | .sp |
| 472 | Bugs can either be reportet to the mailing list (pdfgrep\-users@pdfgrep\&.org) or to the bugtracker on gitlab (https://gitlab\&.com/pdfgrep/pdfgrep/issues)\&. |
| 473 | .SH "AUTHORS" |
| 474 | .sp |
| 475 | \fBpdfgrep\fR is maintained by Hans\-Peter Deifel\&. |
| 476 | .sp |
| 477 | See the \fIAUTHORS\fR file in the source for a full list of contributors\&. |
| 478 | .SH "SEE ALSO" |
| 479 | .sp |
| 480 | grep(1), pcre2(3), regex(7) |
| 481 | .sp |
| 482 | See pdfgrep\(cqs website https://pdfgrep\&.org for more information, downloads, git repository and more\&. |