diff --git a/.pylintrc b/.pylintrc index 05e46e69..73168af3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=C0103, R0913, R0902, R0903, R0914, C0209, C0123 +disable=C0103, R0913, R0902, R0903, R0914, C0209, C0123, R0917 diff --git a/PyPDFForm/widgets/base.py b/PyPDFForm/widgets/base.py index 01b358cf..8723704a 100644 --- a/PyPDFForm/widgets/base.py +++ b/PyPDFForm/widgets/base.py @@ -52,6 +52,7 @@ def __init__( value[0], value[1], value[2], + value[3] if len(value) == 4 else 1, ) self.acro_form_params[param] = value elif user_input in self.NONE_DEFAULTS: diff --git a/docs/prepare.md b/docs/prepare.md index 6df5b94f..ac7f1296 100644 --- a/docs/prepare.md +++ b/docs/prepare.md @@ -38,7 +38,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget( font="Courier", # optional font_size=15, # optional font_color=(1, 0, 0), # optional - bg_color=(0, 0, 1), # optional + bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha) border_color=(1, 0, 0), # optional border_width=5, # optional alignment=0, # optional, 0=left, 1=center, 2=right @@ -65,7 +65,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget( size=30, # optional button_style="check", # optional tick_color=(0, 1, 0), # optional - bg_color=(0, 0, 1), # optional + bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha) border_color=(1, 0, 0), # optional border_width=5 # optional ) @@ -100,7 +100,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget( font="Courier", # optional font_size=15, # optional font_color=(1, 0, 0), # optional - bg_color=(0, 0, 1), # optional + bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha) border_color=(1, 0, 0), # optional border_width=5 # optional ) diff --git a/pdf_samples/widget/create_text_alpha_bg_color.pdf b/pdf_samples/widget/create_text_alpha_bg_color.pdf new file mode 100644 index 00000000..f2a09530 Binary files /dev/null and b/pdf_samples/widget/create_text_alpha_bg_color.pdf differ diff --git a/tests/test_create_widget.py b/tests/test_create_widget.py index d73dc9c2..ffaef475 100644 --- a/tests/test_create_widget.py +++ b/tests/test_create_widget.py @@ -198,6 +198,28 @@ def test_create_text_default(template_stream, pdf_samples, request): assert obj.stream == expected +def test_create_text_alpha_bg_color(template_stream, pdf_samples, request): + expected_path = os.path.join(pdf_samples, "widget", "create_text_alpha_bg_color.pdf") + with open(expected_path, "rb+") as f: + obj = PdfWrapper(template_stream).create_widget( + "text", + "foo", + 1, + 100, + 100, + bg_color=(0, 0, 1, 0), + ) + assert obj.schema["properties"]["foo"]["type"] == "string" + + 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_create_text_align_center(template_stream, pdf_samples, request): expected_path = os.path.join(pdf_samples, "widget", "create_text_align_center.pdf") with open(expected_path, "rb+") as f: