[*] Функция работает локально, но, но работает локально, но, но, но работает локально, но Не в приложении django
[*] Хотя оно работает локально, оно не создает скрещивания или клещей, а точки кружки (огромная точка в флажке)
Код: Выделить всё
def check_the_checkbox(pdf_annotation, nm_substring):
# regex identifiaction of checkbox and construction of checkbox_field_name_composer here
if checkbox_field_name_composer and checkbox_field_name_composer in checkboxes_to_map.keys():
parent = annotation.get('/Parent')
if "/AP" in annotation and checkbox_field_name_composer in nm_substring:
ap_element = annotation.get('/AP')
# Explicitly set checkbox to checked by modifying the AP element
if isinstance(ap_element, PdfDict):
ap_element.update(PdfDict(D="/Yes")) # Set the appearance to checked
ap_element.update(PdfDict(N="/Yes")) # Normal state (checked)
annotation.update(PdfDict(AS=pdfrw.PdfName('Yes'))) # Set appearance state to checked
print(f"Updated AP Element to checked: {ap_element}")
if not isinstance(ap_element, PdfDict):
ap_element = PdfDict(D="/Yes", N="/Yes") # Ensure the AP is set correctly
annotation.update(ap_element)
print(f"Set AP Element to default (checked): {ap_element}")
if parent and ("/T" not in annotation.keys() and parent.get('/FT') == '/Btn'):
# Mark the checkbox as checked by setting the value to "On"
annotation.update(PdfDict(V=pdfrw.PdfName('On')))
print("Checkbox marked as checked.")
# Optionally adjust the Rect to ensure proper display
rect = annotation.get('/Rect')
if rect:
# Extract numeric values from the PdfObjects
x0 = extract_numeric(rect[0])
y0 = extract_numeric(rect[1])
x1 = extract_numeric(rect[2])
y1 = extract_numeric(rect[3])
# Calculate new width and height (if needed)
new_width = x1 - x0
new_height = y1 - y0
scale_factor = 0.8 # Adjust the scale factor to make the circle smaller
new_width *= scale_factor
new_height *= scale_factor
# Update the Rect with the new size
annotation.update(PdfDict(Rect=[x0, y0, x0 + new_width, y0 + new_height]))
print(f"Updated Rect with new size: {annotation.get('/Rect')}")
else:
print(f"Annotation does not match checkbox: {annotation.keys()}")
else:
print(f"Checkbox field name {checkbox_field_name_composer} not found in checkboxes_to_map
Подробнее здесь: https://stackoverflow.com/questions/794 ... -and-pdfrw