pdfa: replace pkg_resources with importlib.resources

This commit is contained in:
James R. Barlow
2021-09-13 01:10:49 -07:00
parent f3de980447
commit 208657f840
2 changed files with 18 additions and 6 deletions
+8
View File
@@ -0,0 +1,8 @@
# © 2021 James R. Barlow: github.com/jbarlow83
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Data files used to generate certain PDFs."""
+10 -6
View File
@@ -10,16 +10,20 @@ Utilities for PDF/A production and confirmation with Ghostspcript.
"""
import base64
import importlib.resources
from pathlib import Path
from typing import Dict, Iterator, Union
import pikepdf
import pkg_resources
import pkg_resources # deprecated
# Deprecated
ICC_PROFILE_RELPATH = 'data/sRGB.icc'
# Deprecated
SRGB_ICC_PROFILE = pkg_resources.resource_filename('ocrmypdf', ICC_PROFILE_RELPATH)
SRGB_ICC_PROFILE_NAME = 'sRGB.icc'
def _postscript_objdef(
alias: str,
@@ -97,12 +101,12 @@ def generate_pdfa_ps(target_filename: Path, icc: str = 'sRGB'):
References:
Adobe PDFMARK Reference: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
"""
if icc == 'sRGB':
icc_profile = SRGB_ICC_PROFILE
else:
if icc != 'sRGB':
raise NotImplementedError("Only supporting sRGB")
bytes_icc_profile = Path(icc_profile).read_bytes()
bytes_icc_profile = importlib.resources.read_binary(
'ocrmypdf.data', SRGB_ICC_PROFILE_NAME
)
ps = '\n'.join(_make_postscript(icc, bytes_icc_profile, 3))
# We should have encoded everything to pure ASCII by this point, and