Skip to content

Commit

Permalink
conversion: Do not let PyMuPDF print to stdout
Browse files Browse the repository at this point in the history
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]: #700
[2]: pymupdf/PyMuPDF#3137
  • Loading branch information
apyrgio committed Mar 5, 2024
1 parent 37cba4f commit a535b91
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions dangerzone/conversion/pixels_to_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
- 95%-100%: Compress the final PDF
"""
import asyncio
import contextlib
import glob
import io
import json
import os
import shutil
Expand Down Expand Up @@ -49,9 +51,14 @@ async def convert(
# 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(
Expand Down

0 comments on commit a535b91

Please sign in to comment.