Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

353
Visualizações
Fill PDF AcroForm text field with boldface text using HexaPdf

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!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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!

over 4 years ago · Santiago Trujillo Relatório

0

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!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda