Repository: robocorp/rpaframework

Issue:
`RPA.PDF` can't correctly set fields (ticking checkboxes)
Test [robot](https://github.com/cmin764/robots/blob/main/pdf-parse/tasks.robot#L245-L256):
```robotframework
Tick Alianz Checkbox
    Open Pdf    devdata${/}alianz.pdf
    
    ${fields} =    Get Input Fields
    Log To Console    ${fields}
    ${checkboxes} =    Evaluate    {key: value['value'] for key, value in $fields.items() if hasattr(value['value'], 'name') and value['value'].name in ('Off', 'Yes')}
    Log    Checkboxes:
    Log Dictionary    ${checkboxes}

    Set Field Value    VeroeffentlichungInst    Yes
    Save Field Values    output_path=${OUTPUT_DIR}${/}alianz-ticked.pdf
    ...    use_appearances_writer=${True}  # can be False as well, doesn't change a thing
```
[alianz.pdf](https://github.com/robocorp/rpaframework/files/8732240/alianz.pdf) (as found [here](https://www.allianz-fuer-cybersicherheit.de/Webs/ACS/DE/Home/_/Teilnahmeantrag_Allianz_fuer_CyberSicherheit.pdf?__blob=publicationFile&v=2) as well)


Outcome: PDF looks the same (**if opened in the browser**, but with Preview on Mac it is checked indeed)
Expected: having the first checkbox set (which it is if opened in some previewing software)


Discussion:

Resolving patch:
diff --git a/packages/pdf/src/RPA/PDF/keywords/model.py b/packages/pdf/src/RPA/PDF/keywords/model.py
--- a/packages/pdf/src/RPA/PDF/keywords/model.py
+++ b/packages/pdf/src/RPA/PDF/keywords/model.py
@@ -522,7 +522,7 @@ def get_input_fields(
         :param replace_none_value: Enable this to conveniently visualize the fields. (
             replaces the null value with field's name)
         :param encoding: Use an explicit encoding for field name/value parsing. (
-            defaults to "iso-8859-1" but "utf-16" might work for you)
+            defaults to "iso-8859-1" but "utf-8/16" might be the one working for you)
         :returns: A dictionary with all the found fields. Use their key names when
             setting values into them.
         :raises KeyError: If no input fields are enabled in the PDF.


Test patch:
diff --git a/packages/pdf/tests/python/__init__.py b/packages/pdf/tests/python/__init__.py
--- a/packages/pdf/tests/python/__init__.py
+++ b/packages/pdf/tests/python/__init__.py
@@ -27,6 +27,7 @@ class TestFiles:
     seal_of_approval = RESOURCE_DIR / "approved.png"
     big_nope = RESOURCE_DIR / "big_nope.png"
     foersom_pdf = RESOURCE_DIR / "foersom.pdf"
+    alianz_pdf = RESOURCE_DIR / "alianz.pdf"
     receipt_pdf = RESOURCE_DIR / "receipt.pdf"
     robot_png = RESOURCE_DIR / "robot.png"
 
diff --git a/packages/pdf/tests/python/test_model.py b/packages/pdf/tests/python/test_model.py
--- a/packages/pdf/tests/python/test_model.py
+++ b/packages/pdf/tests/python/test_model.py
@@ -1,3 +1,5 @@
+import re
+
 import pytest
 
 from . import (
@@ -74,6 +76,22 @@ def test_set_field_value_encoding(library):
         assert new_name.encode() in content
 
 
+def test_set_field_value_checkbox(library):
+    fields = library.get_input_fields(TestFiles.alianz_pdf)
+    checkbox_name = "VeroeffentlichungInst"
+    assert fields[checkbox_name]["value"].name == "Off"
+
+    library.set_field_value(checkbox_name, "Yes")  # ticks it
+    with temp_filename(suffix=".pdf") as tmp_file:
+        library.save_field_values(output_path=tmp_file)
+        library.switch_to_pdf(tmp_file)
+        with pytest.raises(KeyError):
+            # This output can't retrieve fields after save anymore.
+            library.get_input_fields()
+        content = library.active_pdf_document.fileobject.read()
+        assert re.search(rf"{checkbox_name}[^>]+Yes".encode(), content)
+
+
 @pytest.mark.xfail(reason="Known issue: PDF won't show as having fields after saving")
 def test_save_field_values_fields_exist(library):
     new_number = "12313123"
diff --git a/packages/pdf/tests/resources/alianz.pdf b/packages/pdf/tests/resources/alianz.pdf
new file mode 100644
Binary files /dev/null and b/packages/pdf/tests/resources/alianz.pdf differ