I have a seemingly simple question, but I can't find the answer. I have a pre-existing pdf form. Filling in the form manually, one of its text fields shows its value in boldface type. When using HexaPdf to fill this field, the text should also appear in boldface, but it appears in regular type.
I fill the field with
doc.acro_form.field_by_name('text1').field_value = @record.value
To get this to be shown in boldface, I have tried the following, to no avail:
doc.acro_form.field_by_name('text1').set_default_appearance_string(font: 'Helvetica-Bold', font_size: 0)
This gets the error message "The requested font 'Helvetica-Bold' in variant 'none' couldn't be found".
Then I tried:
doc.acro_form.field_by_name('text1').set_default_appearance_string(font: 'Helvetica', variant: :bold, font_size: 0)
This gets: "unknown keyword: variant".
The configured fonts for the document are:
{"Times"=>[:none, :bold, :italic, :bold_italic], "Helvetica"=>[:none, :bold, :italic, :bold_italic], "Courier"=>[:none, :bold, :italic, :bold_italic], "Symbol"=>[:none], "ZapfDingbats"=>[:none]}
So Helvetica with variant :bold should be available.
Could someone please let me know the correct syntax? Thanks in advance!
I got this answer from @gettalong on github:
"It is indeed an issue as there is no way to do this currently with that method - I will fix it for the next release. You can use the following work-around until then:"
name = doc.acro_form.default_resources.add_font(doc.fonts.add('Helvetica', variant: :bold).pdf_object)
doc.acro_form.field_by_name('text1')[:DA] = "0 g /#{name} 0 Tf"
Thank you very much!
With the HexaPDF 0.18.0 release this is now directly possible by using the font_options argument for #set_default_appearance_string. No more work-arounds needed!