Skip to content

Commit

Permalink
Merge pull request #462 from chinapandaman/PPF-461
Browse files Browse the repository at this point in the history
PPF-461: using prefix to identify text appearance identifiers
  • Loading branch information
chinapandaman authored Jan 24, 2024
2 parents d9b8f78 + db28987 commit 5391649
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PyPDFForm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Contains any object users might need."""

__version__ = "1.4.4"
__version__ = "1.4.5"

from .wrapper import PdfWrapper, PyPDFForm
4 changes: 2 additions & 2 deletions PyPDFForm/core/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_text_field_font_size(widget: dict) -> Union[float, int]:
if text_appearance:
properties = text_appearance.split(" ")
for i, val in enumerate(properties):
if val == FONT_SIZE_IDENTIFIER:
if val.startswith(FONT_SIZE_IDENTIFIER):
return float(properties[i - 1])

return result
Expand All @@ -144,7 +144,7 @@ def get_text_field_font_color(

text_appearance = text_appearance.split(" ")
for i, val in enumerate(text_appearance):
if val == FONT_COLOR_IDENTIFIER.replace(" ", ""):
if val.startswith(FONT_COLOR_IDENTIFIER.replace(" ", "")):
result = (
float(text_appearance[i - 3]),
float(text_appearance[i - 2]),
Expand Down
Binary file added pdf_samples/scenario/tools/soda.pdf
Binary file not shown.
Binary file added pdf_samples/scenario/tools/soda_expected.pdf
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/scenario/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,28 @@ def test_filling_sejda_dropdown_pdf_form(tool_pdf_directory, request):
request.config.results["stream"] = result.read()
assert len(result.read()) == len(expected)
assert result.read() == expected


def test_filling_soda_pdf_form(tool_pdf_directory, request):
expected_path = os.path.join(tool_pdf_directory, "soda_expected.pdf")
with open(expected_path, "rb+") as f:
expected = f.read()
result = PdfWrapper(os.path.join(tool_pdf_directory, "soda.pdf")).fill(
{
"Text1": "Helvetica 8",
"Text2": "Helvetica 12",
"Text3": "Helvetica 24",
"Text4": "Helvetica 8",
"Text5": "Helvetica 12",
"Text6": "Helvetica 24",
"Text7": "Helvetica 8",
"Text8": "Helvetica 12",
"Text9": "Helvetica 24",
}
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = result.read()

if os.name != "nt":
assert len(result.read()) == len(expected)
assert result.read() == expected

0 comments on commit 5391649

Please sign in to comment.