pdfrw checkbox AS values gets unwanted parentheses

So I'm trying to mark checkboxes in a PDF file with pdfrw. That means changing the checkboxes "AS" value from the default "/Off" to "/Yes". pdfrw is currently forcing parentheses around my "/Yes" when it writes to file, so it doesn't work. How do I keep it from adding these parentheses?

My code:

template_pdf = pdfrw.PdfReader(input_pdf_path)
annotations = template_pdf.pages[0][/Annots]
for annotation in annotations:
    annotation.update(pdfrw.PdfDict(AS="/Yes"))
    pdfrw.PdfWriter().write(output_pdf_path, template_pdf)

My checkboxes in the PDF-file ends up like this, first word in third line is the important one:

1661 0 obj
<</AP <</D <</Off 1845 0 R /Yes 1846 0 R>> /N <</Yes 1847 0 R>>>> /AS
    (/Yes) /F 4 /FT /Btn /MK <</CA (l)>> /P 1608 0 R /Rect
    [101.275 576.22 107.395 584.91] /Subtype /Widget /T (box1) /Type
    /Annot>>
endobj

But to make the check mark actually show up in most PDF-viewers it needs to be like this:

1661 0 obj
<</AP <</D <</Off 1845 0 R /Yes 1846 0 R>> /N <</Yes 1847 0 R>>>> /AS
    /Yes /F 4 /FT /Btn /MK <</CA (l)>> /P 1608 0 R /Rect
    [101.275 576.22 107.395 584.91] /Subtype /Widget /T (box1) /Type
    /Annot>>
endobj

I could always just open the file in python and just replace all the instances of "(/Yes)" with "/Yes", but there has to be some way to get the right values with pdfrw.

I think that you might need to use PdfName('Yes') instead of "/Yes":

annotation.update(pdfrw.PdfDict(AS=pdfrw.PdfName('Yes')))

I didn't test this. But it works.

pdfrw checkbox AS values gets unwanted parentheses So I'm trying to mark checkboxes in a PDF file with pdfrw. That means changing the checkboxes "AS" value from the default "/Off" to "/Yes". pdfrw is currently forcing parentheses around my "/Yes" when

annotation.update(pdfrw.PdfDict(V=pdfrw.PdfName('On')))

Above worked for me.

The field name is used to identify the values that are provided during signing when the data gets exported from the service. Note: If a document has more than one text tag with the same name but different directives, or those directives are in a different order amongst the same-name text tags, Adobe Sign automatically adds "efield" + unique

template.Root.Pages.Kids[0].Annots[0].update(PdfDict(AS=PdfName('On'), V=PdfName('On')))

What About this?. The handling of this is also different in arrow functions compared to regular functions.. In short, with arrow functions there are no binding of this. In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever.

Example: Pass a Button Value to an Inline Function. Another common use of an inline function is to pass in a button’s value as an argument. This is also very common when using input elements and the onChange event handler. Take a look at the example below. Notice the value e that’s returned from the onClick event handler:

Sometimes sheet gets so locked that, even in an emergency, we would not be able to change anything. If we forget the password, then also there is no way to make changes in data. There will be only one way, which is to create a new file with the same data to proceed further. Things to Remember about Lock Column in Excel

The Measure Values field contains all the measures in your data, collected into a single field with continuous values. Drag individual measure fields out of the Measure Values card to remove them from the view. The Measure Names field contains the names of all measures in your data, collected into a single field with discrete values.

Comments
  • Works for me as well.
  • pdfrw.PdfDict(V=pdfrw.PdfName('On')) worked for me.
  • The () wrapper indicates a PDF String, but you needed a PDF Name. I'd have been shocked if this didn't work. One of the things that most vexed me in the PDF standard was that while both String and Name have numeric escape sequences, in String the escapes were in hexadecimal, while names use... octal? Just pick one already. (but it's far to late to change now). IIRC, "Names" are hashed, while strings are kept as character strings.
  • Could you please add some explanation .
  • template = PdfReader(TEMPLATE_PATH_AND_FILENAME) template.Root.Pages.Kids[0].Annots[0].update(PdfDict(AS=PdfName('On'), V=PdfName('On'))) remember. this is indexed. you should know your page index and the annotation index.