|
19 | 19 | PdfWriter, |
20 | 20 | Transformation, |
21 | 21 | ) |
| 22 | +from pypdf._font import HAS_FONTTOOLS |
22 | 23 | from pypdf.annotations import Link |
23 | 24 | from pypdf.errors import DeprecationError, PageSizeNotDefinedError, PdfReadError, PyPdfError |
24 | 25 | from pypdf.generic import ( |
@@ -1728,6 +1729,33 @@ def test_update_form_fields2(caplog): |
1728 | 1729 | assert "Text string 'شهرزاد' contains characters not supported by font encoding." in caplog.text |
1729 | 1730 |
|
1730 | 1731 |
|
| 1732 | +@pytest.mark.enable_socket |
| 1733 | +def test_update_form_fields3(): |
| 1734 | + if HAS_FONTTOOLS: |
| 1735 | + url = "https://github.com/user-attachments/files/21073581/CERERE.INMATRICULARE.form.pdf" |
| 1736 | + name = "iss3361.pdf" |
| 1737 | + writer = PdfWriter() |
| 1738 | + writer.append(BytesIO(get_data_from_url(url, name=name))) |
| 1739 | + data = { |
| 1740 | + "subsemnatul": "Σὲ γνωρίζω ἀπὸ τὴν κόψη", |
| 1741 | + "strada": "Căpitan Nicolae Licăreț", |
| 1742 | + "adresa_judet": "Конференция", |
| 1743 | + } |
| 1744 | + writer.update_page_form_field_values(writer.pages[0], data, auto_regenerate=False) |
| 1745 | + apstream_object = (writer.pages[0]["/Annots"][0]["/AP"]["/N"].get_data()) |
| 1746 | + found_hex = "".join(re.findall(r"<(.*?)>", apstream_object.decode())) |
| 1747 | + expected_hex = data["subsemnatul"].encode("utf-16-be").hex() |
| 1748 | + assert expected_hex in found_hex |
| 1749 | + apstream_object = (writer.pages[0]["/Annots"][7]["/AP"]["/N"].get_data()) |
| 1750 | + found_hex = re.findall(r"<(.*?)>", apstream_object.decode()) |
| 1751 | + expected_hex = data["strada"].encode("utf-16-be").hex() |
| 1752 | + assert expected_hex in found_hex |
| 1753 | + apstream_object = (writer.pages[0]["/Annots"][9]["/AP"]["/N"].get_data()) |
| 1754 | + found_hex = re.findall(r"<(.*?)>", apstream_object.decode()) |
| 1755 | + expected_hex = data["adresa_judet"].encode("utf-16-be").hex() |
| 1756 | + assert expected_hex in found_hex |
| 1757 | + |
| 1758 | + |
1731 | 1759 | @pytest.mark.enable_socket |
1732 | 1760 | def test_iss1862(): |
1733 | 1761 | # The file here has "/B" entry to define the font in a object below the page |
|
0 commit comments