Skip to content

Commit

Permalink
Merge pull request #678 from chinapandaman/PPF-677
Browse files Browse the repository at this point in the history
PPF-677: draw text support new line symbol
  • Loading branch information
chinapandaman authored Jun 26, 2024
2 parents 70bc942 + 184f657 commit cd66b68
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion PyPDFForm/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .adapter import fp_or_f_obj_or_stream_to_stream
from .constants import (DEFAULT_FONT, DEFAULT_FONT_COLOR, DEFAULT_FONT_SIZE,
VERSION_IDENTIFIER_PREFIX, VERSION_IDENTIFIERS)
VERSION_IDENTIFIER_PREFIX, VERSION_IDENTIFIERS, NEW_LINE_SYMBOL)
from .coordinate import generate_coordinate_grid
from .filler import fill, simple_fill
from .font import register_font
Expand Down Expand Up @@ -244,6 +244,9 @@ def draw_text(
new_widget.font_size = kwargs.get("font_size", DEFAULT_FONT_SIZE)
new_widget.font_color = kwargs.get("font_color", DEFAULT_FONT_COLOR)

if NEW_LINE_SYMBOL in text:
new_widget.text_lines = text.split(NEW_LINE_SYMBOL)

watermarks = create_watermarks_and_draw(
self.stream,
page_number,
Expand Down
Binary file not shown.
Binary file modified pdf_samples/widget/create_dropdown.pdf
Binary file not shown.
Binary file modified pdf_samples/widget/create_text_complex.pdf
Binary file not shown.
Binary file modified pdf_samples/widget/create_text_default.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ def test_draw_text_on_one_page(template_stream, pdf_samples, request):
assert obj.stream == expected


def test_draw_text_new_line_symbol(template_stream, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "sample_pdf_with_drawn_text_new_line_symbol.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(template_stream).draw_text(
"test\ntest\ntest",
1,
300,
225,
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_draw_image_on_one_page(template_stream, image_samples, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "sample_pdf_with_image.pdf")
with open(expected_path, "rb+") as f:
Expand Down

0 comments on commit cd66b68

Please sign in to comment.