我正在使用pdf-forms(https://github.com/jkraemer/pdf-forms)gem在我的rails应用程序中填写PDF表单,基于PDFtk。文本字段按我的预期工作,但我的复选框字段没有。这些框在Chrome中显示良好,但在预览和邮件中,复选框字段显示为空。
class FormsController < ApplicationController
require 'pdf_forms'
def acord25
@policy = Policy.find(params[:id])
pdftk = PdfForms.new('/usr/local/bin/pdftk')
# find out the field names that are present in form.pdf
pdftk.get_field_names 'lib/pdfs/acord25.pdf'
# take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
pdftk.fill_form '/lib/pdfs/acord25.pdf', "acord25.pdf",
"F[0].P1[0].Form_CompletionDate_A[0]" => @policy.dateIssued,
"F[0].P1[0].Producer_FullName_A[0]" => @policy.client.broker.name,
"F[0].P1[0].Producer_MailingAddress_LineOne_A[0]" => @policy.client.broker.company,
"F[0].P1[0].Producer_MailingAddress_LineTwo_A[0]" => @policy.client.broker.address,
"F[0].P1[0].Producer_ContactPerson_FullName_A[0]" => @policy.legalVesting,
"F[0].P1[0].Producer_ContactPerson_PhoneNumber_A[0]" => @policy.client.broker.phone,
"F[0].P1[0].Producer_FaxNumber_A[0]" => @policy.client.broker.fax,
"F[0].P1[0].Producer_ContactPerson_EmailAddress_A[0]" => @policy.client.broker.email,
"F[0].P1[0].NamedInsured_FullName_A[0]" => @policy.client.name,
"F[0].P1[0].NamedInsured_MailingAddress_LineOne_A[0]" => @policy.client.address.titlecase,
"F[0].P1[0].GeneralLiability_CoverageIndicator_A[0]" => 1,
"F[0].P1[0].GeneralLiability_OccurrenceIndicator_A[0]" => 1,
"F[0].P1[0].GeneralLiability_GeneralAggregate_LimitAppliesPerLocationIndicator_A[0]" => 1,
"F[0].P1[0].Policy_PolicyNumberIdentifier_A[0]" => @policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_A[0]" => @policy.dateEffective,
"F[0].P1[0].PolicyExpirationGeneral[0]" => @policy.term.dayEnd,
"F[0].P1[0].Insurer_FullName_A[0]" => "Lexington Insurance Company",
"F[0].P1[0].Insurer_NAICCode_A[0]" => 19437,
"F[0].P1[0].Insurer_FullName_B[0]" => "Commerce & Industry Insurance Company",
"F[0].P1[0].Insurer_NAICCode_B[0]" => 19410,
"F[0].P1[0].Insurer_FullName_C[0]" => "Great American Insurance Company",
"F[0].P1[0].Insurer_NAICCode_C[0]" => 37532,
"F[0].P1[0].Insurer_FullName_D[0]" => "Admiral Insurance Company",
"F[0].P1[0].Insurer_NAICCode_D[0]" => 24856,
"F[0].P1[0].GeneralLiability_InsurerLetterCode_A[0]" => "A",
"F[0].P1[0].GeneralLiability_EachOccurrence_LimitAmount_A[0]" => 1000000,
"F[0].P1[0].GeneralLiability_FireDamageRentedPremises_EachOccurrenceLimitAmount_A[0]" => 50000,
"F[0].P1[0].GeneralLiability_MedicalExpense_EachPersonLimitAmount_A[0]" => "Excluded",
"F[0].P1[0].GeneralLiability_PersonalAndAdvertisingInjury_LimitAmount_A[0]" => 1000000,
"F[0].P1[0].GeneralLiability_GeneralAggregate_LimitAmount_A[0]" => 2000000,
"F[0].P1[0].GeneralLiability_ProductsAndCompletedOperations_AggregateLimitAmount_A[0]" => 2000000,
"F[0].P1[0].Vehicle_InsurerLetterCode_A[0]" => "A",
"F[0].P1[0].Vehicle_HiredAutosIndicator_A[0]" => 1,
"F[0].P1[0].Vehicle_NonOwnedAutosIndicator_A[0]" => 1,
"F[0].P1[0].Policy_PolicyNumberIdentifier_B[0]" => @policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_B[0]" => @policy.dateEffective,
"F[0].P1[0].Policy_ExpirationDate_B[0]" => @policy.term.dayEnd,
"F[0].P1[0].Vehicle_CombinedSingleLimit_EachAccidentAmount_A[0]" => 1000000,
"F[0].P1[0].ExcessUmbrella_InsurerLetterCode_A[0]" => "B",
"F[0].P1[0].ExcessUmbrella_OccurrenceIndicator_A[0]" => 1,
"F[0].P1[0].ExcessUmbrella_DeductibleIndicator_A[0]" => 1,
"F[0].P1[0].ExcessUmbrella_Umbrella_DeductibleOrRetentionAmount_A[0]" => @policy.coverages.first.deductibleOcc,
"F[0].P1[0].Policy_PolicyNumberIdentifier_D[0]" => @policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_D[0]" => @policy.dateEffective,
"F[0].P1[0].Policy_ExpirationDate_D[0]" => @policy.term.dayEnd,
"F[0].P1[0].ExcessUmbrella_Umbrella_EachOccurrenceAmount_A[0]" => 10000000,
"F[0].P1[0].ExcessUmbrella_Umbrella_AggregateAmount_A[0]" => 10000000
send_file("#{Rails.root}/acord25.pdf", filename: "#{@policy.client.name} - #{@policy.carrier.name} - #{@policy.policyNumber} (#{Time.now}).pdf", type: "application/vnd.ms-excel")
end
end
TL; DR:选中的复选框显示在Chrome中,但不会显示在预览或邮件中。
我感谢任何帮助或引导可能出现的问题。谢谢!
答案 0 :(得分:0)
原来PDF格式已损坏。不得不重新创建表单,而不是PDFTK问题。