File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,18 @@ def hash_for_generated_pdf
6363 def filled_pdf_path
6464 source_pdf_path = "app/assets/pdfs/nc_packet--no-income.pdf"
6565 template_doc = HexaPDF ::Document . open ( source_pdf_path )
66+
67+ unless template_doc
68+ Rails . logger . error "Unable to generate PDF from #{ source_pdf_path } "
69+ return
70+ end
71+
6672 hash_for_fillable_pdf . each do |field_name , field_value |
6773 template_doc . acro_form . field_by_name ( field_name . to_s ) . field_value = field_value
6874 end
75+
76+ template_doc . acro_form . flatten
77+
6978 pdf_tempfile = Tempfile . new ( [ "packet" , ".pdf" ] , "tmp/" )
7079 template_doc . write ( pdf_tempfile )
7180 pdf_tempfile . path
Original file line number Diff line number Diff line change 181181 end
182182
183183 describe "#filled_pdf_path" do
184- it "fills the PDF without errors " do
184+ it "fills and flattens the PDF (no editable fields remain) " do
185185 screener . assign_attributes (
186186 phone_number : "9195550123" ,
187187 is_american_indian : "yes" ,
214214 preventing_work_write_in : "Chronic back pain"
215215 )
216216
217- expect { packet_pdf . filled_pdf_path } . not_to raise_error
217+ path = nil
218+
219+ expect {
220+ path = packet_pdf . filled_pdf_path
221+ } . not_to raise_error
222+
223+ doc = HexaPDF ::Document . open ( path )
224+
225+ # Assert it's flattened (read-only)
226+ form = doc . acro_form
227+ expect ( form ) . to be_nil . or have_attributes ( fields : be_empty )
228+ ensure
229+ File . delete ( path ) if path && File . exist? ( path )
218230 end
219231 end
220232end
You can’t perform that action at this time.
0 commit comments