Skip to content

Commit 75a6003

Browse files
BUG: Fix check box value which should be name object (#3124)
Relates to #3115.
1 parent 9505412 commit 75a6003

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

pypdf/_writer.py

+1
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ def update_page_form_field_values(
11121112
v = NameObject("/Off")
11131113
# other cases will be updated through the for loop
11141114
annotation[NameObject(AA.AS)] = v
1115+
annotation[NameObject(FA.V)] = v
11151116
elif (
11161117
parent_annotation.get(FA.FT) == "/Tx"
11171118
or parent_annotation.get(FA.FT) == "/Ch"

tests/test_forms.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Test form-related functionality. Separate file to keep overview."""
2+
3+
from io import BytesIO
4+
5+
import pytest
6+
7+
from pypdf import PdfReader, PdfWriter
8+
from tests import get_data_from_url
9+
10+
11+
@pytest.mark.enable_socket
12+
def test_form_button__v_value_should_be_name_object():
13+
url = "https://github.com/user-attachments/files/18736500/blank-form.pdf"
14+
name = "issue3115.pdf"
15+
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
16+
writer = PdfWriter(clone_from=reader)
17+
writer.update_page_form_field_values(
18+
writer.pages[0],
19+
{"Other": "/On"},
20+
auto_regenerate=False,
21+
)
22+
stream = BytesIO()
23+
writer.write(stream)
24+
25+
# Wrong: `/V (/On)`.
26+
assert b"\n/V /On\n" in stream.getvalue()

tests/test_workflows.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ def test_inline_images():
10351035

10361036

10371037
@pytest.mark.enable_socket
1038-
def test_iss():
1038+
def test_issue1899():
10391039
url = "https://github.com/py-pdf/pypdf/files/11801077/lv2018tconv.pdf"
10401040
name = "lv2018tconv.pdf"
10411041
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))

0 commit comments

Comments
 (0)