Implement tesseract PDF rendering as an alternative
It's much better a rendering text baselines than hocr and seems to produce small file sizes, so it's progress. Not available for Tesseract 3.02 obviously, so both modes need to remove available.
This commit is contained in:
+230
@@ -0,0 +1,230 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
|
||||
-->
|
||||
<!-- Title: Pipeline: Pages: 1 -->
|
||||
<svg width="752pt" height="651pt"
|
||||
viewBox="0.00 0.00 752.00 650.53" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 646.53)">
|
||||
<title>Pipeline:</title>
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-646.53 748,-646.53 748,4 -4,4"/>
|
||||
<g id="clust1" class="cluster"><title>clustertasks</title>
|
||||
<polygon fill="none" stroke="black" points="8,-8 8,-634.53 736,-634.53 736,-8 8,-8"/>
|
||||
<text text-anchor="middle" x="372" y="-606.53" font-family="Times,serif" font-size="30.00" fill="#ff3232">Pipeline:</text>
|
||||
</g>
|
||||
<!-- t0 -->
|
||||
<g id="node1" class="node"><title>t0</title>
|
||||
<polygon fill="#efa03b" stroke="#006000" points="489.791,-588.53 394.209,-588.53 390.209,-584.53 390.209,-552.53 485.791,-552.53 489.791,-556.53 489.791,-588.53"/>
|
||||
<polyline fill="none" stroke="#006000" points="485.791,-584.53 390.209,-584.53 "/>
|
||||
<polyline fill="none" stroke="#006000" points="485.791,-584.53 485.791,-552.53 "/>
|
||||
<polyline fill="none" stroke="#006000" points="485.791,-584.53 489.791,-588.53 "/>
|
||||
<text text-anchor="middle" x="440" y="-564.53" font-family="Times,serif" font-size="20.00" fill="#006000">repair_pdf</text>
|
||||
</g>
|
||||
<!-- t1 -->
|
||||
<g id="node2" class="node"><title>t1</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="474.782,-509.564 382,-526.497 289.218,-509.564 289.304,-482.165 474.696,-482.165 474.782,-509.564"/>
|
||||
<polygon fill="none" stroke="black" points="478.799,-512.902 382,-530.569 285.201,-512.902 285.311,-478.159 478.689,-478.159 478.799,-512.902"/>
|
||||
<text text-anchor="middle" x="382" y="-495.991" font-family="Times,serif" font-size="20.00">split_pages</text>
|
||||
</g>
|
||||
<!-- t0->t1 -->
|
||||
<g id="edge1" class="edge"><title>t0->t1</title>
|
||||
<path fill="none" stroke="gray" d="M425.064,-552.394C420.296,-546.925 414.86,-540.689 409.493,-534.532"/>
|
||||
<polygon fill="gray" stroke="gray" points="411.996,-532.077 402.787,-526.838 406.719,-536.676 411.996,-532.077"/>
|
||||
</g>
|
||||
<!-- t10 -->
|
||||
<g id="node12" class="node"><title>t10</title>
|
||||
<polygon fill="#efa03b" stroke="#006000" points="728.338,-451.452 517.662,-451.452 513.662,-447.452 513.662,-415.452 724.338,-415.452 728.338,-419.452 728.338,-451.452"/>
|
||||
<polyline fill="none" stroke="#006000" points="724.338,-447.452 513.662,-447.452 "/>
|
||||
<polyline fill="none" stroke="#006000" points="724.338,-447.452 724.338,-415.452 "/>
|
||||
<polyline fill="none" stroke="#006000" points="724.338,-447.452 728.338,-451.452 "/>
|
||||
<text text-anchor="middle" x="621" y="-427.452" font-family="Times,serif" font-size="20.00" fill="#006000">generate_postscript_stub</text>
|
||||
</g>
|
||||
<!-- t0->t10 -->
|
||||
<g id="edge15" class="edge"><title>t0->t10</title>
|
||||
<path fill="none" stroke="gray" d="M462.924,-552.422C495.068,-528.433 553.637,-484.724 589.75,-457.773"/>
|
||||
<polygon fill="gray" stroke="gray" points="592.056,-460.42 597.977,-451.634 587.87,-454.81 592.056,-460.42"/>
|
||||
</g>
|
||||
<!-- t2 -->
|
||||
<g id="node3" class="node"><title>t2</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="495.555,-451.452 272.445,-451.452 268.445,-447.452 268.445,-415.452 491.555,-415.452 495.555,-419.452 495.555,-451.452"/>
|
||||
<polyline fill="none" stroke="black" points="491.555,-447.452 268.445,-447.452 "/>
|
||||
<polyline fill="none" stroke="black" points="491.555,-447.452 491.555,-415.452 "/>
|
||||
<polyline fill="none" stroke="black" points="491.555,-447.452 495.555,-451.452 "/>
|
||||
<text text-anchor="middle" x="382" y="-427.452" font-family="Times,serif" font-size="20.00">rasterize_with_ghostscript</text>
|
||||
</g>
|
||||
<!-- t1->t2 -->
|
||||
<g id="edge2" class="edge"><title>t1->t2</title>
|
||||
<path fill="none" stroke="#0044a0" d="M382,-478.092C382,-472.777 382,-467.07 382,-461.593"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="385.5,-461.506 382,-451.506 378.5,-461.506 385.5,-461.506"/>
|
||||
</g>
|
||||
<!-- t11 -->
|
||||
<g id="node10" class="node"><title>t11</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="159.594,-393.452 66.4062,-393.452 62.4062,-389.452 62.4062,-357.452 155.594,-357.452 159.594,-361.452 159.594,-393.452"/>
|
||||
<polyline fill="none" stroke="black" points="155.594,-389.452 62.4062,-389.452 "/>
|
||||
<polyline fill="none" stroke="black" points="155.594,-389.452 155.594,-357.452 "/>
|
||||
<polyline fill="none" stroke="black" points="155.594,-389.452 159.594,-393.452 "/>
|
||||
<text text-anchor="middle" x="111" y="-369.452" font-family="Times,serif" font-size="20.00">skip_page</text>
|
||||
</g>
|
||||
<!-- t1->t11 -->
|
||||
<g id="edge13" class="edge"><title>t1->t11</title>
|
||||
<path fill="none" stroke="#0044a0" d="M322.128,-478.077C301.919,-470.026 279.335,-460.679 259,-451.452 222.194,-434.751 181.273,-413.827 151.805,-398.326"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="153.137,-395.071 142.66,-393.496 149.868,-401.261 153.137,-395.071"/>
|
||||
</g>
|
||||
<!-- t3 -->
|
||||
<g id="node4" class="node"><title>t3</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="467.999,-393.452 300.001,-393.452 296.001,-389.452 296.001,-357.452 463.999,-357.452 467.999,-361.452 467.999,-393.452"/>
|
||||
<polyline fill="none" stroke="black" points="463.999,-389.452 296.001,-389.452 "/>
|
||||
<polyline fill="none" stroke="black" points="463.999,-389.452 463.999,-357.452 "/>
|
||||
<polyline fill="none" stroke="black" points="463.999,-389.452 467.999,-393.452 "/>
|
||||
<text text-anchor="middle" x="382" y="-369.452" font-family="Times,serif" font-size="20.00">preprocess_deskew</text>
|
||||
</g>
|
||||
<!-- t2->t3 -->
|
||||
<g id="edge3" class="edge"><title>t2->t3</title>
|
||||
<path fill="none" stroke="#0044a0" d="M382,-415.346C382,-411.655 382,-407.665 382,-403.695"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="385.5,-403.453 382,-393.453 378.5,-403.453 385.5,-403.453"/>
|
||||
</g>
|
||||
<!-- t6 -->
|
||||
<g id="node6" class="node"><title>t6</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="634.375,-277.452 447.625,-277.452 443.625,-273.452 443.625,-241.452 630.375,-241.452 634.375,-245.452 634.375,-277.452"/>
|
||||
<polyline fill="none" stroke="black" points="630.375,-273.452 443.625,-273.452 "/>
|
||||
<polyline fill="none" stroke="black" points="630.375,-273.452 630.375,-241.452 "/>
|
||||
<polyline fill="none" stroke="black" points="630.375,-273.452 634.375,-277.452 "/>
|
||||
<text text-anchor="middle" x="539" y="-253.452" font-family="Times,serif" font-size="20.00">select_image_for_pdf</text>
|
||||
</g>
|
||||
<!-- t2->t6 -->
|
||||
<g id="edge7" class="edge"><title>t2->t6</title>
|
||||
<path fill="none" stroke="#0044a0" d="M442.809,-415.378C455.168,-409.854 467.327,-402.684 477,-393.452 507.53,-364.315 524.51,-317.195 532.692,-287.567"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="536.178,-288.068 535.317,-277.508 529.405,-286.3 536.178,-288.068"/>
|
||||
</g>
|
||||
<!-- t4 -->
|
||||
<g id="node5" class="node"><title>t4</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="439.705,-335.452 290.295,-335.452 286.295,-331.452 286.295,-299.452 435.705,-299.452 439.705,-303.452 439.705,-335.452"/>
|
||||
<polyline fill="none" stroke="black" points="435.705,-331.452 286.295,-331.452 "/>
|
||||
<polyline fill="none" stroke="black" points="435.705,-331.452 435.705,-299.452 "/>
|
||||
<polyline fill="none" stroke="black" points="435.705,-331.452 439.705,-335.452 "/>
|
||||
<text text-anchor="middle" x="363" y="-311.452" font-family="Times,serif" font-size="20.00">preprocess_clean</text>
|
||||
</g>
|
||||
<!-- t3->t4 -->
|
||||
<g id="edge4" class="edge"><title>t3->t4</title>
|
||||
<path fill="none" stroke="#0044a0" d="M376.196,-357.346C374.87,-353.438 373.43,-349.194 372.006,-344.995"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="375.296,-343.799 368.768,-335.453 368.667,-346.048 375.296,-343.799"/>
|
||||
</g>
|
||||
<!-- t3->t6 -->
|
||||
<g id="edge6" class="edge"><title>t3->t6</title>
|
||||
<path fill="none" stroke="#0044a0" d="M413.697,-357.449C425.088,-350.965 437.865,-343.25 449,-335.452 471.538,-319.668 495.388,-299.622 512.871,-284.226"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="515.277,-286.77 520.427,-277.512 510.627,-281.538 515.277,-286.77"/>
|
||||
</g>
|
||||
<!-- t4->t6 -->
|
||||
<g id="edge5" class="edge"><title>t4->t6</title>
|
||||
<path fill="none" stroke="#0044a0" d="M416.762,-299.346C435.442,-293.402 456.56,-286.683 475.923,-280.522"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="477.099,-283.821 485.567,-277.453 474.977,-277.15 477.099,-283.821"/>
|
||||
</g>
|
||||
<!-- t5 -->
|
||||
<g id="node7" class="node"><title>t5</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="425.922,-277.452 264.078,-277.452 260.078,-273.452 260.078,-241.452 421.922,-241.452 425.922,-245.452 425.922,-277.452"/>
|
||||
<polyline fill="none" stroke="black" points="421.922,-273.452 260.078,-273.452 "/>
|
||||
<polyline fill="none" stroke="black" points="421.922,-273.452 421.922,-241.452 "/>
|
||||
<polyline fill="none" stroke="black" points="421.922,-273.452 425.922,-277.452 "/>
|
||||
<text text-anchor="middle" x="343" y="-253.452" font-family="Times,serif" font-size="20.00">ocr_tesseract_hocr</text>
|
||||
</g>
|
||||
<!-- t4->t5 -->
|
||||
<g id="edge8" class="edge"><title>t4->t5</title>
|
||||
<path fill="none" stroke="#0044a0" d="M356.891,-299.346C355.495,-295.438 353.979,-291.194 352.48,-286.995"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="355.731,-285.694 349.072,-277.453 349.139,-288.048 355.731,-285.694"/>
|
||||
</g>
|
||||
<!-- t9 -->
|
||||
<g id="node11" class="node"><title>t9</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="292.496,-219.452 39.5039,-219.452 35.5039,-215.452 35.5039,-183.452 288.496,-183.452 292.496,-187.452 292.496,-219.452"/>
|
||||
<polyline fill="none" stroke="black" points="288.496,-215.452 35.5039,-215.452 "/>
|
||||
<polyline fill="none" stroke="black" points="288.496,-215.452 288.496,-183.452 "/>
|
||||
<polyline fill="none" stroke="black" points="288.496,-215.452 292.496,-219.452 "/>
|
||||
<text text-anchor="middle" x="164" y="-195.452" font-family="Times,serif" font-size="20.00">tesseract_ocr_and_render_pdf</text>
|
||||
</g>
|
||||
<!-- t4->t9 -->
|
||||
<g id="edge14" class="edge"><title>t4->t9</title>
|
||||
<path fill="none" stroke="#0044a0" d="M300.717,-299.405C284.01,-293.605 266.338,-286.3 251,-277.452 227.033,-263.625 203.489,-242.755 186.95,-226.538"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="189.414,-224.052 179.868,-219.456 184.465,-229.002 189.414,-224.052"/>
|
||||
</g>
|
||||
<!-- t7 -->
|
||||
<g id="node8" class="node"><title>t7</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="708.366,-219.452 551.634,-219.452 547.634,-215.452 547.634,-183.452 704.366,-183.452 708.366,-187.452 708.366,-219.452"/>
|
||||
<polyline fill="none" stroke="black" points="704.366,-215.452 547.634,-215.452 "/>
|
||||
<polyline fill="none" stroke="black" points="704.366,-215.452 704.366,-183.452 "/>
|
||||
<polyline fill="none" stroke="black" points="704.366,-215.452 708.366,-219.452 "/>
|
||||
<text text-anchor="middle" x="628" y="-195.452" font-family="Times,serif" font-size="20.00">render_hocr_page</text>
|
||||
</g>
|
||||
<!-- t6->t7 -->
|
||||
<g id="edge9" class="edge"><title>t6->t7</title>
|
||||
<path fill="none" stroke="#0044a0" d="M566.187,-241.346C574.468,-236.135 583.697,-230.328 592.445,-224.824"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="594.38,-227.741 600.98,-219.453 590.652,-221.817 594.38,-227.741"/>
|
||||
</g>
|
||||
<!-- t8 -->
|
||||
<g id="node9" class="node"><title>t8</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="529.742,-219.452 314.258,-219.452 310.258,-215.452 310.258,-183.452 525.742,-183.452 529.742,-187.452 529.742,-219.452"/>
|
||||
<polyline fill="none" stroke="black" points="525.742,-215.452 310.258,-215.452 "/>
|
||||
<polyline fill="none" stroke="black" points="525.742,-215.452 525.742,-183.452 "/>
|
||||
<polyline fill="none" stroke="black" points="525.742,-215.452 529.742,-219.452 "/>
|
||||
<text text-anchor="middle" x="420" y="-195.452" font-family="Times,serif" font-size="20.00">render_hocr_debug_page</text>
|
||||
</g>
|
||||
<!-- t6->t8 -->
|
||||
<g id="edge11" class="edge"><title>t6->t8</title>
|
||||
<path fill="none" stroke="#0044a0" d="M502.649,-241.346C490.885,-235.809 477.689,-229.6 465.354,-223.795"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="466.666,-220.544 456.128,-219.453 463.686,-226.878 466.666,-220.544"/>
|
||||
</g>
|
||||
<!-- t5->t7 -->
|
||||
<g id="edge10" class="edge"><title>t5->t7</title>
|
||||
<path fill="none" stroke="#0044a0" d="M426.2,-242.104C461.192,-235.228 501.99,-227.212 537.71,-220.193"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="538.503,-223.604 547.641,-218.242 537.154,-216.736 538.503,-223.604"/>
|
||||
</g>
|
||||
<!-- t5->t8 -->
|
||||
<g id="edge12" class="edge"><title>t5->t8</title>
|
||||
<path fill="none" stroke="#0044a0" d="M366.521,-241.346C373.387,-236.352 381.007,-230.811 388.291,-225.513"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="390.594,-228.166 396.623,-219.453 386.477,-222.504 390.594,-228.166"/>
|
||||
</g>
|
||||
<!-- t12 -->
|
||||
<g id="node13" class="node"><title>t12</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="339.845,-105.456 420,-78.0208 500.155,-105.456 500.08,-149.848 339.92,-149.848 339.845,-105.456"/>
|
||||
<polygon fill="none" stroke="black" points="335.836,-102.581 420,-73.7729 504.164,-102.581 504.078,-153.869 335.922,-153.869 335.836,-102.581"/>
|
||||
<text text-anchor="middle" x="420" y="-111.726" font-family="Times,serif" font-size="20.00">merge_pages</text>
|
||||
</g>
|
||||
<!-- t7->t12 -->
|
||||
<g id="edge19" class="edge"><title>t7->t12</title>
|
||||
<path fill="none" stroke="#0044a0" d="M584.65,-183.419C564.063,-175.33 538.602,-165.326 513.908,-155.624"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="515.081,-152.324 504.493,-151.924 512.521,-158.839 515.081,-152.324"/>
|
||||
</g>
|
||||
<!-- t8->t12 -->
|
||||
<g id="edge18" class="edge"><title>t8->t12</title>
|
||||
<path fill="none" stroke="#0044a0" d="M420,-183.12C420,-177.585 420,-171.177 420,-164.592"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="423.5,-164.201 420,-154.201 416.5,-164.201 423.5,-164.201"/>
|
||||
</g>
|
||||
<!-- t11->t12 -->
|
||||
<g id="edge16" class="edge"><title>t11->t12</title>
|
||||
<path fill="none" stroke="#0044a0" d="M92.3128,-357.362C55.4572,-321.636 -19.1794,-237.859 27,-183.452 64.5123,-139.256 221.468,-125.188 325.317,-120.741"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="325.658,-124.23 335.508,-120.328 325.375,-117.236 325.658,-124.23"/>
|
||||
</g>
|
||||
<!-- t9->t12 -->
|
||||
<g id="edge17" class="edge"><title>t9->t12</title>
|
||||
<path fill="none" stroke="#0044a0" d="M217.354,-183.419C248.764,-173.392 289.391,-160.422 326.012,-148.731"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="327.263,-152.006 335.725,-145.63 325.134,-145.337 327.263,-152.006"/>
|
||||
</g>
|
||||
<!-- t10->t12 -->
|
||||
<g id="edge21" class="edge"><title>t10->t12</title>
|
||||
<path fill="none" stroke="gray" d="M653.379,-415.337C684.552,-396.255 727,-362.233 727,-318.452 727,-318.452 727,-318.452 727,-258.452 727,-224.824 739.784,-208.186 717,-183.452 689.882,-154.013 590.624,-136.736 514.239,-127.544"/>
|
||||
<polygon fill="gray" stroke="gray" points="514.437,-124.044 504.097,-126.355 513.621,-130.996 514.437,-124.044"/>
|
||||
</g>
|
||||
<!-- t13 -->
|
||||
<g id="node14" class="node"><title>t13</title>
|
||||
<polygon fill="#efa03b" stroke="black" points="482.338,-52 361.662,-52 357.662,-48 357.662,-16 478.338,-16 482.338,-20 482.338,-52"/>
|
||||
<polyline fill="none" stroke="black" points="478.338,-48 357.662,-48 "/>
|
||||
<polyline fill="none" stroke="black" points="478.338,-48 478.338,-16 "/>
|
||||
<polyline fill="none" stroke="black" points="478.338,-48 482.338,-52 "/>
|
||||
<text text-anchor="middle" x="420" y="-28" font-family="Times,serif" font-size="20.00">validate_pdfa</text>
|
||||
</g>
|
||||
<!-- t12->t13 -->
|
||||
<g id="edge20" class="edge"><title>t12->t13</title>
|
||||
<path fill="none" stroke="#0044a0" d="M420,-73.9482C420,-69.9654 420,-66.007 420,-62.2247"/>
|
||||
<polygon fill="#0044a0" stroke="#0044a0" points="423.5,-62.1573 420,-52.1573 416.5,-62.1574 423.5,-62.1573"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 15 KiB |
+45
-8
@@ -84,7 +84,7 @@ metadata = parser.add_argument_group(
|
||||
"Set output PDF/A metadata (default: use input document's title)")
|
||||
metadata.add_argument(
|
||||
'--title', type=str,
|
||||
help="set document title")
|
||||
help="set document title (place multiple words in quotes)")
|
||||
metadata.add_argument(
|
||||
'--author', type=str,
|
||||
help="set document author")
|
||||
@@ -131,6 +131,9 @@ advanced = parser.add_argument_group(
|
||||
advanced.add_argument(
|
||||
'--tesseract-config', default=[], type=list, action='append',
|
||||
help="Tesseract configuration")
|
||||
advanced.add_argument(
|
||||
'--pdf-renderer', choices=['tesseract', 'hocr'], default='hocr',
|
||||
help='choose OCR PDF renderer')
|
||||
|
||||
debugging = parser.add_argument_group(
|
||||
"Debugging",
|
||||
@@ -467,12 +470,13 @@ def preprocess_clean(
|
||||
unpaper.clean(input_file, output_file, dpi, log)
|
||||
|
||||
|
||||
@active_if(options.pdf_renderer == 'hocr')
|
||||
@transform(
|
||||
input=preprocess_clean,
|
||||
filter=suffix(".pp-clean.png"),
|
||||
output=".hocr",
|
||||
extras=[_log, _pdfinfo, _pdfinfo_lock])
|
||||
def ocr_tesseract(
|
||||
def ocr_tesseract_hocr(
|
||||
input_file,
|
||||
output_file,
|
||||
log,
|
||||
@@ -531,6 +535,7 @@ def ocr_tesseract(
|
||||
print(line, end='') # fileinput.input redirects stdout
|
||||
|
||||
|
||||
@active_if(options.pdf_renderer == 'hocr')
|
||||
@collate(
|
||||
input=[rasterize_with_ghostscript, preprocess_deskew, preprocess_clean],
|
||||
filter=regex(r".*/(\d{6})(?:\.page|\.pp-deskew|\.pp-clean)\.png"),
|
||||
@@ -558,12 +563,13 @@ def select_image_for_pdf(
|
||||
re_symlink(image, output_file)
|
||||
|
||||
|
||||
@active_if(options.pdf_renderer == 'hocr')
|
||||
@collate(
|
||||
input=[select_image_for_pdf, ocr_tesseract],
|
||||
input=[select_image_for_pdf, ocr_tesseract_hocr],
|
||||
filter=regex(r".*/(\d{6})(?:\.image|\.hocr)"),
|
||||
output=os.path.join(work_folder, r'\1.rendered.pdf'),
|
||||
extras=[_log, _pdfinfo, _pdfinfo_lock])
|
||||
def render_page(
|
||||
def render_hocr_page(
|
||||
infiles,
|
||||
output_file,
|
||||
log,
|
||||
@@ -580,13 +586,14 @@ def render_page(
|
||||
showBoundingboxes=False, invisibleText=True)
|
||||
|
||||
|
||||
@active_if(options.pdf_renderer == 'hocr')
|
||||
@active_if(options.debug_rendering)
|
||||
@collate(
|
||||
input=[select_image_for_pdf, ocr_tesseract],
|
||||
input=[select_image_for_pdf, ocr_tesseract_hocr],
|
||||
filter=regex(r".*/(\d{6})(?:\.image|\.hocr)"),
|
||||
output=os.path.join(work_folder, r'\1.debug.pdf'),
|
||||
extras=[_log, _pdfinfo, _pdfinfo_lock])
|
||||
def render_debug_page(
|
||||
def render_hocr_debug_page(
|
||||
infiles,
|
||||
output_file,
|
||||
log,
|
||||
@@ -603,6 +610,36 @@ def render_debug_page(
|
||||
showBoundingboxes=True, invisibleText=False)
|
||||
|
||||
|
||||
@active_if(options.pdf_renderer == 'tesseract')
|
||||
@transform(
|
||||
input=preprocess_clean,
|
||||
filter=suffix(".pp-clean.png"),
|
||||
output=".rendered.pdf",
|
||||
extras=[_log, _pdfinfo, _pdfinfo_lock])
|
||||
def tesseract_ocr_and_render_pdf(
|
||||
input_file,
|
||||
output_file,
|
||||
log,
|
||||
pdfinfo,
|
||||
pdfinfo_lock):
|
||||
|
||||
args_tesseract = [
|
||||
'tesseract',
|
||||
'-l', '+'.join(options.language),
|
||||
input_file,
|
||||
os.path.splitext(output_file)[0], # Tesseract appends suffix
|
||||
'pdf'
|
||||
] + options.tesseract_config
|
||||
p = Popen(args_tesseract, close_fds=True, stdout=PIPE, stderr=PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = p.communicate(timeout=180)
|
||||
if stdout:
|
||||
log.info(stdout)
|
||||
if stderr:
|
||||
log.error(stderr)
|
||||
|
||||
|
||||
@transform(
|
||||
input=repair_pdf,
|
||||
filter=suffix('.repaired.pdf'),
|
||||
@@ -656,8 +693,8 @@ def skip_page(
|
||||
|
||||
|
||||
@merge(
|
||||
input=[render_page, render_debug_page, skip_page,
|
||||
generate_postscript_stub],
|
||||
input=[render_hocr_page, render_hocr_debug_page, skip_page,
|
||||
tesseract_ocr_and_render_pdf, generate_postscript_stub],
|
||||
output=os.path.join(work_folder, 'merged.pdf'),
|
||||
extras=[_log, _pdfinfo, _pdfinfo_lock])
|
||||
def merge_pages(
|
||||
|
||||
Reference in New Issue
Block a user