mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
conversion: Do not let PyMuPDF print to stdout
PyMuPDF has some hardcoded log messages that print to stdout [1]. We don't have a way to silence them, because they don't use the Python logging infrastructure. What we can do here is silence a particular call that's been creating debug messages. For a long term solution, we have sent a PR to the PyMuPDF team, and we will follow up there [2]. Fixes #700 [1]: https://github.com/freedomofpress/dangerzone/issues/700 [2]: https://github.com/pymupdf/PyMuPDF/pull/3137
This commit is contained in:
parent
be8e2aa36b
commit
74c467eaf7
1 changed files with 10 additions and 3 deletions
|
@ -6,7 +6,9 @@ Here are the steps, with progress bar percentages:
|
|||
- 95%-100%: Compress the final PDF
|
||||
"""
|
||||
import asyncio
|
||||
import contextlib
|
||||
import glob
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
|
@ -49,9 +51,14 @@ class PixelsToPDF(DangerzoneConverter):
|
|||
# The first few operations happen on a per-page basis.
|
||||
page_size = len(untrusted_rgb_data)
|
||||
total_size += page_size
|
||||
pixmap = fitz.Pixmap(
|
||||
fitz.Colorspace(fitz.CS_RGB), width, height, untrusted_rgb_data, False
|
||||
)
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
pixmap = fitz.Pixmap(
|
||||
fitz.Colorspace(fitz.CS_RGB),
|
||||
width,
|
||||
height,
|
||||
untrusted_rgb_data,
|
||||
False,
|
||||
)
|
||||
pixmap.set_dpi(DEFAULT_DPI, DEFAULT_DPI)
|
||||
if ocr_lang: # OCR the document
|
||||
self.update_progress(
|
||||
|
|
Loading…
Reference in a new issue