Module: PdfFill::Filler
- Defined in:
- lib/pdf_fill/filler.rb
Constant Summary collapse
- PDF_FORMS =
PdfForms.new(Settings.binaries.pdftk)
- UNICODE_PDF_FORMS =
PdfForms.new(Settings.binaries.pdftk, data_format: 'XFdf', utf8_fields: true)
- FORM_CLASSES =
{ '21P-527EZ' => PdfFill::Forms::Va21p527ez, '21P-530' => PdfFill::Forms::Va21p530, '21-4142' => PdfFill::Forms::Va214142, '21-0781a' => PdfFill::Forms::Va210781a, '21-0781' => PdfFill::Forms::Va210781, '21-8940' => PdfFill::Forms::Va218940, '10-10CG' => PdfFill::Forms::Va1010cg, '10-10EZ' => PdfFill::Forms::Va1010ez, '686C-674' => PdfFill::Forms::Va686c674, '28-1900' => PdfFill::Forms::Va281900, '28-8832' => PdfFill::Forms::Va288832, '21-674' => PdfFill::Forms::Va21674, '21-0538' => PdfFill::Forms::Va210538, '26-1880' => PdfFill::Forms::Va261880, '5655' => PdfFill::Forms::Va5655 }.freeze
Class Method Summary collapse
- .combine_extras(old_file_path, extras_generator) ⇒ Object
- .fill_ancillary_form(form_data, claim_id, form_id) ⇒ Object
- .fill_form(saved_claim, file_name_extension = nil, fill_options = {}) ⇒ Object
- .process_form(form_id, form_data, form_class, file_name_extension, fill_options = {}) ⇒ Object
Class Method Details
.combine_extras(old_file_path, extras_generator) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pdf_fill/filler.rb', line 43 def combine_extras(old_file_path, extras_generator) if extras_generator.text? file_path = "#{old_file_path.gsub('.pdf', '')}_final.pdf" extras_path = extras_generator.generate PDF_FORMS.cat(old_file_path, extras_path, file_path) File.delete(extras_path) File.delete(old_file_path) file_path else old_file_path end end |
.fill_ancillary_form(form_data, claim_id, form_id) ⇒ Object
66 67 68 |
# File 'lib/pdf_fill/filler.rb', line 66 def fill_ancillary_form(form_data, claim_id, form_id) process_form(form_id, form_data, FORM_CLASSES[form_id], claim_id) end |
.fill_form(saved_claim, file_name_extension = nil, fill_options = {}) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/pdf_fill/filler.rb', line 59 def fill_form(saved_claim, file_name_extension = nil, = {}) form_id = saved_claim.form_id form_class = FORM_CLASSES[form_id] process_form(form_id, saved_claim.parsed_form, form_class, file_name_extension || saved_claim.id, ) end |
.process_form(form_id, form_data, form_class, file_name_extension, fill_options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pdf_fill/filler.rb', line 70 def process_form(form_id, form_data, form_class, file_name_extension, = {}) folder = 'tmp/pdfs' FileUtils.mkdir_p(folder) file_path = "#{folder}/#{form_id}_#{file_name_extension}.pdf" hash_converter = HashConverter.new(form_class.date_strftime) new_hash = hash_converter.transform_data( form_data: form_class.new(form_data).merge_fields(), pdftk_keys: form_class::KEY ) (form_id == SavedClaim::CaregiversAssistanceClaim::FORM ? UNICODE_PDF_FORMS : PDF_FORMS).fill_form( "lib/pdf_fill/forms/pdfs/#{form_id}.pdf", file_path, new_hash, flatten: Rails.env.production? ) combine_extras(file_path, hash_converter.extras_generator) end |