Skip to content

Commit ca263c1

Browse files
committed
PPF-1051: should improve some performances
1 parent d6dfdb5 commit ca263c1

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

PyPDFForm/adapter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
stream before further processing.
1111
"""
1212

13+
from functools import lru_cache
1314
from os.path import isfile
1415
from typing import Any, BinaryIO, Union
1516

@@ -31,6 +32,7 @@ def readable(obj: Any) -> bool:
3132
return callable(getattr(obj, "read", None))
3233

3334

35+
@lru_cache
3436
def fp_or_f_obj_or_stream_to_stream(
3537
fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO],
3638
) -> bytes:

PyPDFForm/font.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .utils import stream_to_io
2424

2525

26+
@lru_cache
2627
def register_font(font_name: str, ttf_stream: bytes) -> bool:
2728
"""
2829
Registers a TrueType font with the ReportLab library.
@@ -217,6 +218,7 @@ def get_new_font_name(fonts: dict) -> str:
217218
return f"{FONT_NAME_PREFIX}{n}"
218219

219220

221+
@lru_cache
220222
def get_all_available_fonts(pdf: bytes) -> dict:
221223
"""
222224
Retrieves all available fonts from a PDF document's AcroForm.

PyPDFForm/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def enable_adobe_mode(pdf: bytes) -> bytes:
8585
return f.read()
8686

8787

88+
@lru_cache
8889
def remove_all_widgets(pdf: bytes) -> bytes:
8990
"""
9091
Removes all widgets (form fields) from a PDF, effectively flattening the form.

0 commit comments

Comments
 (0)