This file is indexed.

/usr/share/doc/ocrmypdf/html/cookbook.html is in ocrmypdf-doc 6.1.2-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Cookbook &mdash; ocrmypdf 6.1.2 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="genindex.html"/>
        <link rel="search" title="Search" href="search.html"/>
    <link rel="top" title="ocrmypdf 6.1.2 documentation" href="index.html"/>
        <link rel="next" title="Advanced features" href="advanced.html"/>
        <link rel="prev" title="Installing additional language packs" href="languages.html"/> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="index.html" class="icon icon-home"> ocrmypdf
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="release_notes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="languages.html">Installing additional language packs</a></li>
</ul>
<p class="caption"><span class="caption-text">Usage</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Cookbook</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#basic-examples">Basic examples</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#help">Help!</a></li>
<li class="toctree-l3"><a class="reference internal" href="#add-an-ocr-layer-and-convert-to-pdf-a">Add an OCR layer and convert to PDF/A</a></li>
<li class="toctree-l3"><a class="reference internal" href="#add-an-ocr-layer-and-output-a-standard-pdf">Add an OCR layer and output a standard PDF</a></li>
<li class="toctree-l3"><a class="reference internal" href="#create-a-pdf-a-with-all-color-and-grayscale-images-converted-to-jpeg">Create a PDF/A with all color and grayscale images converted to JPEG</a></li>
<li class="toctree-l3"><a class="reference internal" href="#modify-a-file-in-place">Modify a file in place</a></li>
<li class="toctree-l3"><a class="reference internal" href="#correct-page-rotation">Correct page rotation</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ocr-languages-other-than-english">OCR languages other than English</a></li>
<li class="toctree-l3"><a class="reference internal" href="#produce-pdf-and-text-file-containing-ocr-text">Produce PDF and text file containing OCR text</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ocr-images-not-pdfs">OCR images, not PDFs</a></li>
<li class="toctree-l2"><a class="reference internal" href="#image-processing">Image processing</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#ocr-and-correct-document-skew-crooked-scan">OCR and correct document skew (crooked scan)</a></li>
<li class="toctree-l3"><a class="reference internal" href="#don-t-actually-ocr-my-pdf">Don’t actually OCR my PDF</a></li>
<li class="toctree-l3"><a class="reference internal" href="#redo-ocr">Redo OCR</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#improving-ocr-quality">Improving OCR quality</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="advanced.html">Advanced features</a></li>
<li class="toctree-l1"><a class="reference internal" href="batch.html">Batch processing</a></li>
<li class="toctree-l1"><a class="reference internal" href="security.html">PDF security issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="errors.html">Common error messages</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">ocrmypdf</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Cookbook</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/cookbook.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="cookbook">
<h1>Cookbook<a class="headerlink" href="#cookbook" title="Permalink to this headline"></a></h1>
<div class="section" id="basic-examples">
<h2>Basic examples<a class="headerlink" href="#basic-examples" title="Permalink to this headline"></a></h2>
<div class="section" id="help">
<h3>Help!<a class="headerlink" href="#help" title="Permalink to this headline"></a></h3>
<p>ocrmypdf has built-in help.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --help
</pre></div>
</div>
</div>
<div class="section" id="add-an-ocr-layer-and-convert-to-pdf-a">
<h3>Add an OCR layer and convert to PDF/A<a class="headerlink" href="#add-an-ocr-layer-and-convert-to-pdf-a" title="Permalink to this headline"></a></h3>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf input.pdf output.pdf
</pre></div>
</div>
</div>
<div class="section" id="add-an-ocr-layer-and-output-a-standard-pdf">
<h3>Add an OCR layer and output a standard PDF<a class="headerlink" href="#add-an-ocr-layer-and-output-a-standard-pdf" title="Permalink to this headline"></a></h3>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --output-type pdf input.pdf output.pdf
</pre></div>
</div>
</div>
<div class="section" id="create-a-pdf-a-with-all-color-and-grayscale-images-converted-to-jpeg">
<h3>Create a PDF/A with all color and grayscale images converted to JPEG<a class="headerlink" href="#create-a-pdf-a-with-all-color-and-grayscale-images-converted-to-jpeg" title="Permalink to this headline"></a></h3>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --output-type pdfa --pdfa-image-compression jpeg input.pdf output.pdf
</pre></div>
</div>
</div>
<div class="section" id="modify-a-file-in-place">
<h3>Modify a file in place<a class="headerlink" href="#modify-a-file-in-place" title="Permalink to this headline"></a></h3>
<p>The file will only be overwritten if OCRmyPDF is successful.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf myfile.pdf myfile.pdf
</pre></div>
</div>
</div>
<div class="section" id="correct-page-rotation">
<h3>Correct page rotation<a class="headerlink" href="#correct-page-rotation" title="Permalink to this headline"></a></h3>
<p>OCR will attempt to automatic correct the rotation of each page. This can help fix a scanning job that contains a mix of landscape and portrait pages.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --rotate-pages myfile.pdf myfile.pdf
</pre></div>
</div>
<p>You can increase (decrease) the parameter <code class="docutils literal"><span class="pre">--rotate-pages-threshold</span></code> to make page rotation more (less) aggressive.</p>
</div>
<div class="section" id="ocr-languages-other-than-english">
<h3>OCR languages other than English<a class="headerlink" href="#ocr-languages-other-than-english" title="Permalink to this headline"></a></h3>
<p>By default OCRmyPDF assumes the document is English.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf -l fre LeParisien.pdf LeParisien.pdf
ocrmypdf -l eng+fre Bilingual-English-French.pdf Bilingual-English-French.pdf
</pre></div>
</div>
<p>Language packs must be installed for all languages specified. See <a class="reference internal" href="languages.html#lang-packs"><span class="std std-ref">Installing additional language packs</span></a>.</p>
</div>
<div class="section" id="produce-pdf-and-text-file-containing-ocr-text">
<h3>Produce PDF and text file containing OCR text<a class="headerlink" href="#produce-pdf-and-text-file-containing-ocr-text" title="Permalink to this headline"></a></h3>
<p>This produces a file named “output.pdf” and a companion text file named “output.txt”.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --sidecar output.txt input.pdf output.pdf
</pre></div>
</div>
</div>
</div>
<div class="section" id="ocr-images-not-pdfs">
<h2>OCR images, not PDFs<a class="headerlink" href="#ocr-images-not-pdfs" title="Permalink to this headline"></a></h2>
<p>Use a program like <a class="reference external" href="https://gitlab.mister-muffin.de/josch/img2pdf">img2pdf</a> to convert your images to PDFs, and then pipe the results to run ocrmypdf:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>img2pdf my-images*.jpg <span class="p">|</span> ocrmypdf - myfile.pdf
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">img2pdf</span></code> also has features to control the position of images on a page, if desired.</p>
<p>For convenience, OCRmyPDF can convert single images to PDFs on its own. If the resolution (dots per inch, DPI) of an image is not set or is incorrect, it can be overridden with <code class="docutils literal"><span class="pre">--image-dpi</span></code>. (As 1 inch is 2.54 cm, 1 dpi = 0.39 dpcm).</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --image-dpi <span class="m">300</span> image.png myfile.pdf
</pre></div>
</div>
<p>If you have multiple images, you must use <code class="docutils literal"><span class="pre">img2pdf</span></code> to convert the images to PDF.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">ImageMagick <code class="docutils literal"><span class="pre">convert</span></code> can also convert a group of images to PDF, but in the author’s experience it takes a long time, transcodes unnecessarily and gives poor results.</p>
</div>
<p>You can also use Tesseract 3.04+ directly to convert single page images or multi-page TIFFs to PDF:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>tesseract my-image.jpg output-prefix pdf
</pre></div>
</div>
</div>
<div class="section" id="image-processing">
<h2>Image processing<a class="headerlink" href="#image-processing" title="Permalink to this headline"></a></h2>
<p>OCRmyPDF perform some image processing on each page of a PDF, if desired.  The same processing is applied to each page.  It is suggested that the user review files after image processing as these commands might remove desirable content, especially from poor quality scans.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">--rotate-pages</span></code> attempts to determine the correct orientation for each page and rotates the page if necessary.</li>
<li><code class="docutils literal"><span class="pre">--remove-background</span></code> attempts to detect and remove a noisy background from grayscale or color images.  Monochrome images are ignored. This should not be used on documents that contain color photos as it may remove them.</li>
<li><code class="docutils literal"><span class="pre">--deskew</span></code> will correct pages were scanned at a skewed angle by rotating them back into place.  Skew determination and correction is performed using <a class="reference external" href="http://www.leptonica.com/skew-measurement.html">Postl’s variance of line sums</a> algorithm as implemented in <a class="reference external" href="http://www.leptonica.com/index.html">Leptonica</a>.</li>
<li><code class="docutils literal"><span class="pre">--clean</span></code> uses <a class="reference external" href="https://www.flameeyes.eu/projects/unpaper">unpaper</a> to clean up pages before OCR, but does not alter the final output.  This makes it less likely that OCR will try to find text in background noise.</li>
<li><code class="docutils literal"><span class="pre">--clean-final</span></code> uses unpaper to clean up pages before OCR and inserts the page into the final output.  You will want to review each page to ensure that unpaper did not remove something important.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In many cases image processing will rasterize PDF pages as images, potentially losing quality.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><code class="docutils literal"><span class="pre">--clean-final</span></code> and <code class="docutils literal"><span class="pre">-remove-background</span></code> may leave undesirable visual artifacts in some images where their algorithms have shortcomings. Files should be visually reviewed after using these options.</p>
</div>
<div class="section" id="ocr-and-correct-document-skew-crooked-scan">
<h3>OCR and correct document skew (crooked scan)<a class="headerlink" href="#ocr-and-correct-document-skew-crooked-scan" title="Permalink to this headline"></a></h3>
<p>Deskew:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --deskew input.pdf output.pdf
</pre></div>
</div>
<p>Image processing commands can be combined. The order in which options are given does not matter. OCRmyPDF always applies the steps of the image processing pipeline in the same order (rotate, remove background, deskew, clean).</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --deskew --clean --rotate-pages input.pdf output.pdf
</pre></div>
</div>
</div>
<div class="section" id="don-t-actually-ocr-my-pdf">
<h3>Don’t actually OCR my PDF<a class="headerlink" href="#don-t-actually-ocr-my-pdf" title="Permalink to this headline"></a></h3>
<p>If you set <code class="docutils literal"><span class="pre">--tesseract-timeout</span> <span class="pre">0</span></code> OCRmyPDF will apply its image processing without performing OCR, if all you want to is to apply image processing or PDF/A conversion.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --tesseract-timeout<span class="o">=</span><span class="m">0</span> --remove-background input.pdf output.pdf
</pre></div>
</div>
</div>
<div class="section" id="redo-ocr">
<h3>Redo OCR<a class="headerlink" href="#redo-ocr" title="Permalink to this headline"></a></h3>
<p>To redo OCR on a file OCRed with other OCR software or a previous version of OCRmyPDF and/or Tesseract, you may use the <code class="docutils literal"><span class="pre">--force-ocr</span></code> argument. Normally, OCRmyPDF does not modify files that already appear to contain OCR text.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ocrmypdf --force-ocr input.pdf output.pdf
</pre></div>
</div>
<p>Note that the method above will force rasterization of all pages, potentially reducing quality or losing vector content.</p>
<p>To ensure quality is preserved, one could extract all of the images and rebuild the PDF for a lossless transformation. This recipe does not work when PDFs contain multiple images per page, as many do in practice. It will also lose any page rotation information.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>pdfimages -all old-ocr.pdf prefix  <span class="c1"># extract all images</span>
img2pdf -o temp.pdf prefix*        <span class="c1"># construct new PDF from the images</span>
<span class="c1"># review the new PDF to ensure it visually matches the old one</span>
ocrmypdf --output-type pdf temp.pdf new-ocr.pdf
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">--output-type</span> <span class="pre">pdf</span></code> is used here to avoid using Ghostscript which will also rasterize images.</p>
</div>
</div>
<div class="section" id="improving-ocr-quality">
<h2>Improving OCR quality<a class="headerlink" href="#improving-ocr-quality" title="Permalink to this headline"></a></h2>
<p>The <a class="reference internal" href="#image-processing">Image processing</a> features can improve OCR quality.</p>
<p>Rotating pages and deskewing helps to ensure that the page orientation is correct before OCR begins. Removing the background and/or cleaning the page can also improve results. The <code class="docutils literal"><span class="pre">--oversample</span> <span class="pre">DPI</span></code> argument can be specified to resample images to higher resolution before attempting OCR; this can improve results as well.</p>
<p>OCR quality will suffer if the resolution of input images is not correct (since the range of pixel sizes that will be checked for possible fonts will also be incorrect).</p>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="advanced.html" class="btn btn-neutral float-right" title="Advanced features" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="languages.html" class="btn btn-neutral" title="Installing additional language packs" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, James R. Barlow. Licensed under Creative Commons Attribution-ShareAlike 4.0..

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'6.1.2',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>