Compare commits

..
11 Commits
Author SHA1 Message Date
James R. Barlow fbaad570c7 v16.4.2 release notes 2024-07-22 15:02:53 -07:00
James R. Barlow f974e3b3c1 ghostscript: change input filename order for 10.03.1
Ghostscript now expects the pdfa.ps file to precede other files. Fixes #1359.
2024-07-22 14:56:03 -07:00
James R. Barlow 46b49cc176 Suppress missing jbig2dec warning message
Windows users can't resolve it easily.
2024-07-22 14:54:40 -07:00
Johannes KalliauerandGitHub 5256e74d0c Update installation.rst "python -m venv .venv" (#1355) 2024-07-18 06:28:07 -07:00
James R. Barlow 621d6a0b89 Fix image size calculation when SMask dimensions do not match image
Closes [Bug]: Ghostscript rasterizing failed #1351
2024-07-16 13:36:48 -07:00
IrisandGitHub 08be7c8bbe update arch base-devel install command (#1354)
the '--needed' flag only installs the package if it isn't installed, otherwise it would reinstall it if already installed.
2024-07-15 13:28:36 -07:00
James R. Barlow 980a5472b6 Fix test failures due to 4dde378 2024-07-09 15:54:53 -07:00
James R. Barlow 51c618e357 Merge branch 'main' of github.com:ocrmypdf/OCRmyPDF 2024-07-09 14:46:58 -07:00
James R. Barlow 4dde3786c2 Fix KeyError '/Subtype'
Fixes #1350
2024-07-09 14:46:47 -07:00
James Barlow d544342602 Merge branch 'main' of https://github.com/ocrmypdf/OCRmyPDF 2024-07-04 22:59:33 -07:00
James Barlow 6a8eb7daaa docs: page seg mode 2024-06-26 01:16:31 -07:00
6 changed files with 83 additions and 8 deletions
+53
View File
@@ -228,6 +228,59 @@ then run ocrmypdf as follows (along with any other desired arguments):
Some combinations of control parameters will break Tesseract or break Some combinations of control parameters will break Tesseract or break
assumptions that OCRmyPDF makes about Tesseract's output. assumptions that OCRmyPDF makes about Tesseract's output.
Changing page segmentation mode
-------------------------------
The directive ``--tesseract-pagesegmode Nmode`` forwards the desired page segmentation
mode to Tesseract OCR. The default is 3.
Page segmentation can improve OCR results when you know that a PDF ought to be
analyzed a particular way, such as PDFs whose pages contain only a single line of
text. For the vast majority of users, changing the page segmentation mode will only
make things worse.
As of June 2024, the Tesseract page segmentation modes are:
+-----+----------------------------------------------------------------------------------+
| ID | Description |
+=====+==================================================================================+
| 0 | Orientation and script detection (OSD) only. |
+-----+----------------------------------------------------------------------------------+
| 1 | Automatic page segmentation with OSD. |
+-----+----------------------------------------------------------------------------------+
| 2 | Automatic page segmentation, but no OSD, or OCR. (not implemented) |
+-----+----------------------------------------------------------------------------------+
| 3 | Fully automatic page segmentation, but no OSD. (Default) |
+-----+----------------------------------------------------------------------------------+
| 4 | Assume a single column of text of variable sizes. |
+-----+----------------------------------------------------------------------------------+
| 5 | Assume a single uniform block of vertically aligned text. |
+-----+----------------------------------------------------------------------------------+
| 6 | Assume a single uniform block of text. |
+-----+----------------------------------------------------------------------------------+
| 7 | Treat the image as a single text line. |
+-----+----------------------------------------------------------------------------------+
| 8 | Treat the image as a single word. |
+-----+----------------------------------------------------------------------------------+
| 9 | Treat the image as a single word in a circle. |
+-----+----------------------------------------------------------------------------------+
| 10 | Treat the image as a single character. |
+-----+----------------------------------------------------------------------------------+
| 11 | Sparse text. Find as much text as possible in no particular order. |
+-----+----------------------------------------------------------------------------------+
| 12 | Sparse text with OSD. |
+-----+----------------------------------------------------------------------------------+
| 13 | Raw line. Treat the image as a single text line, bypassing hacks that are |
| | Tesseract-specific. |
+-----+----------------------------------------------------------------------------------+
Modes 0, 1, 2, and 12 (all of those that enable orientation and script detection)
are not compatible with OCRmyPDF, which performs OSD in a separate step from OCR.
Their use may interfere with ``--rotate-pages`` and other features.
It is currently not possible to use advanced Tesseract OCR features, such as creating
OCR information, when using Tesseract through OCRmyPDF.
Changing the PDF renderer Changing the PDF renderer
========================= =========================
+2 -2
View File
@@ -224,7 +224,7 @@ standard tooling needed to build packages, such as a compiler and binary tools.
.. code-block:: bash .. code-block:: bash
sudo pacman -S base-devel sudo pacman -S --needed base-devel
Now you are ready to install the OCRmyPDF package. Now you are ready to install the OCRmyPDF package.
@@ -681,7 +681,7 @@ To install all of the development and test requirements:
.. code-block:: bash .. code-block:: bash
git clone -b main https://github.com/ocrmypdf/OCRmyPDF.git git clone -b main https://github.com/ocrmypdf/OCRmyPDF.git
python -m .venv python -m venv .venv
source .venv/bin/activate source .venv/bin/activate
cd OCRmyPDF cd OCRmyPDF
pip install -e .[test] pip install -e .[test]
+11
View File
@@ -30,6 +30,17 @@ OCRmyPDF typically supports the three most recent Python versions.
.. |OCRmyPDF PyPI| image:: https://img.shields.io/pypi/v/ocrmypdf.svg .. |OCRmyPDF PyPI| image:: https://img.shields.io/pypi/v/ocrmypdf.svg
v16.4.2
=======
- Fixed order of filenames passed to Ghostscript for PDF/A generation. :issue:`1359`
- Suppressed missing jbig2dec warning message. :issue:`1358`
- Fixed calculation of image size when soft mask dimensions don't match image
dimension. :issue:`1351`
- Several fixes to documentation. Thanks to users Iris and JoKalliauer
who contributed these changes.
- Fixed error on processing PDFs that are missing certain image metadata. :issue:`1315`
v16.4.1 v16.4.1
======= =======
+1 -1
View File
@@ -129,7 +129,7 @@ def generate_pdfa(
): ):
"""Generate a PDF/A from the list of PDF pages and PDF/A metadata.""" """Generate a PDF/A from the list of PDF pages and PDF/A metadata."""
ghostscript.generate_pdfa( ghostscript.generate_pdfa(
pdf_pages=[*pdf_pages, pdfmark], pdf_pages=[pdfmark, *pdf_pages],
output_file=output_file, output_file=output_file,
compression=context.options.pdfa_image_compression, compression=context.options.pdfa_image_compression,
color_conversion_strategy=context.options.color_conversion_strategy, color_conversion_strategy=context.options.color_conversion_strategy,
+3 -1
View File
@@ -268,7 +268,9 @@ def check_pdf(input_file: Path) -> bool:
return False return False
else: else:
with pdf: with pdf:
messages = pdf.check() with warnings.catch_warnings():
warnings.filterwarnings('ignore', message=r'pikepdf.*JBIG2.*')
messages = pdf.check()
success = True success = True
for msg in messages: for msg in messages:
if 'error' in msg.lower(): if 'error' in msg.lower():
+13 -4
View File
@@ -369,8 +369,18 @@ class ImageInfo:
pim = PdfImage(pdfimage) pim = PdfImage(pdfimage)
else: else:
raise ValueError("Either pdfimage or inline must be set") raise ValueError("Either pdfimage or inline must be set")
self._width = pim.width if pim.obj.get(Name.SMask, None) is not None:
self._height = pim.height # SMask is pretty much an alpha channel, but in PDF it's possible
# for channel to have different dimensions than the image
# itself. Some PDF writers use this to create a grayscale stencil
# mask. For our purposes, the effective size is the size of the
# larger component (image or smask).
smask = pim.obj[Name.SMask]
self._width = max(smask.get(Name.Width, 0), pim.width)
self._height = max(smask.get(Name.Height, 0), pim.height)
else:
self._width = pim.width
self._height = pim.height
# If /ImageMask is true, then this image is a stencil mask # If /ImageMask is true, then this image is a stencil mask
# (Images that draw with this stencil mask will have a reference to # (Images that draw with this stencil mask will have a reference to
@@ -573,7 +583,7 @@ def _find_form_xobject_images(pdf: Pdf, container: Object, contentsinfo: Content
xobjs = resources[Name.XObject].as_dict() xobjs = resources[Name.XObject].as_dict()
for xobj in xobjs: for xobj in xobjs:
candidate = xobjs[xobj] candidate = xobjs[xobj]
if candidate is None or candidate[Name.Subtype] != Name.Form: if candidate is None or candidate.get(Name.Subtype) != Name.Form:
continue continue
form_xobject = candidate form_xobject = candidate
@@ -1071,7 +1081,6 @@ class PageInfo:
arg_max_dpi = image_dpis.index(max_dpi) arg_max_dpi = image_dpis.index(max_dpi)
max_area_ratio = image_areas[arg_max_dpi] / total_drawn_area max_area_ratio = image_areas[arg_max_dpi] / total_drawn_area
return PageResolutionProfile( return PageResolutionProfile(
weighted_dpi, weighted_dpi,
max_dpi, max_dpi,