Skip to content

Commit 7576328

Browse files
authored
Merge branch 'main' into WRSAT-505
2 parents ee26b48 + 495375b commit 7576328

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/pdf_filler/packet_pdf.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

spec/lib/pdf_filler/packet_pdf_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
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",
@@ -214,7 +214,19 @@
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
220232
end

0 commit comments

Comments
 (0)