0

I am currently looking to set a face and export value to a PDF combobox using the good PyMuPDF module but I can't find the way. Normally, using Adobe API Javascript it would be something like this : f.setItems( ["Ohio", "OH"], ["Oregon", "OR"], ["Arizona", "AZ"] );

I am wondering if I it would be possible to apply something like this:

import fitz
myPDFfile = r"C:\temp\myPDFfile.pdf"     
with fitz.open(myPDFfile) as doc:
    for page in doc: 
        widgets = page.widgets()
        for widget in widgets:
            if widget.field_type_string in ('ComboBox'):
                print('widget.field_name', widget.field_name, 'widget.field_value', widget.field_value)
                if widget.field_name == 'ComboBox1':
                    print('widget.field_name',widget.field_name)
                    widget.choice_values=( ["Ohio", "OH"], ["Oregon", "OR"], ["Arizona", "AZ"] )
                    widget.field_value = 'test'
                    widget.update()

    doc.saveIncr()

This code is making crash my Jupyter Notebook Kernel. The only way to use it is by correcting the following line: widget.choice_values= ["Ohio", "Oregon", "Arizona"] but it wont set any export value to the combobox.

Any ideas or is something not available yet using this module?

Camilo
  • 335
  • 5
  • 7
  • 1
    **_Pairs_** of values as combobox items are currently not supported in PyMuPDF when creating this field type. Please add an enhancement request on our repo here https://github.com/pymupdf/PyMuPDF/issues. – Jorj McKie May 18 '23 at 11:40

1 Answers1

0

After being contacted by Jorj, they determined combobox pairs (export value, face value) is already supported by PyMuPDF but instead of using a list of lists (like API Javascript) it has to be a list of tuples.

 f.setItems( ("Ohio", "OH"), ("Oregon", "OR"), ("Arizona", "AZ"))
Camilo
  • 335
  • 5
  • 7