Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

added configuration option for the font #197 #207

jonaswinklerf964dd59353a
diff --git a/docs/configuration.rst b/docs/configuration.rst
index efc1a9db1..5ccb80b3a 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -400,6 +400,15 @@ PAPERLESS_FILENAME_DATE_ORDER=<format>
Defaults to none, which disables this feature.
+PAPERLESS_THUMBNAIL_FONT_NAME=<filename>
+ Paperless creates thumbnails for plain text files by rendering the content
+ of the file on an image and uses a predefined font for that. This
+ font can be changed here.
+
+ Note that this won't have any effect on already generated thumbnails.
+
+ Defaults to ``/usr/share/fonts/liberation/LiberationSerif-Regular.ttf``.
+
Binaries
########
diff --git a/paperless.conf.example b/paperless.conf.example
index 910fc22a0..139453cf3 100644
--- a/paperless.conf.example
+++ b/paperless.conf.example
@@ -54,6 +54,7 @@
#PAPERLESS_POST_CONSUME_SCRIPT=/path/to/an/arbitrary/script.sh
#PAPERLESS_FILENAME_DATE_ORDER=YMD
#PAPERLESS_FILENAME_PARSE_TRANSFORMS=[]
+#PAPERLESS_THUMBNAIL_FONT_NAME=
# Binaries
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
index 0aa162739..5af1be85e 100644
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -422,3 +422,5 @@ for t in json.loads(os.getenv("PAPERLESS_FILENAME_PARSE_TRANSFORMS", "[]")):
# TODO: this should not have a prefix.
# Specify the filename format for out files
PAPERLESS_FILENAME_FORMAT = os.getenv("PAPERLESS_FILENAME_FORMAT")
+
+THUMBNAIL_FONT_NAME = os.getenv("PAPERLESS_THUMBNAIL_FONT_NAME", "/usr/share/fonts/liberation/LiberationSerif-Regular.ttf")
diff --git a/src/paperless_text/parsers.py b/src/paperless_text/parsers.py
index 030c2c2c2..a38bd7a91 100644
--- a/src/paperless_text/parsers.py
+++ b/src/paperless_text/parsers.py
@@ -1,10 +1,9 @@
import os
-import subprocess
from PIL import ImageDraw, ImageFont, Image
from django.conf import settings
-from documents.parsers import DocumentParser, ParseError
+from documents.parsers import DocumentParser
class TextDocumentParser(DocumentParser):
@@ -23,7 +22,8 @@ class TextDocumentParser(DocumentParser):
img = Image.new("RGB", (500, 700), color="white")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(
- "/usr/share/fonts/liberation/LiberationSerif-Regular.ttf", 20,
+ font=settings.THUMBNAIL_FONT_NAME,
+ size=20,
layout_engine=ImageFont.LAYOUT_BASIC)
draw.text((5, 5), read_text(), font=font, fill="black")