diff --git a/modules/representation_management/lib/representation_management/v0/pdf_constructor/base.rb b/modules/representation_management/lib/representation_management/v0/pdf_constructor/base.rb index ce0399bcd9e..8aec2109540 100644 --- a/modules/representation_management/lib/representation_management/v0/pdf_constructor/base.rb +++ b/modules/representation_management/lib/representation_management/v0/pdf_constructor/base.rb @@ -151,10 +151,16 @@ def unformat_phone_number(phone_number) # def fill_and_combine_pdf(data, flatten: true) pdftk = PdfForms.new(Settings.binaries.pdftk) - next_steps_tempfile = generate_next_steps_page(data) if next_steps_page? template_tempfile = fill_template_form(pdftk, data, flatten: flatten) + # Only combine PDFs if needed. Otherwise directly write the template to the output tempfile. + if next_steps_page? + next_steps_tempfile = generate_next_steps_page(data) + combine_pdfs(next_steps_tempfile, template_tempfile) + else + FileUtils.copy_file(template_tempfile.path, @tempfile.path) + @tempfile.rewind + end - combine_pdfs(next_steps_tempfile, template_tempfile) cleanup_tempfiles(template_tempfile, next_steps_tempfile) end @@ -207,10 +213,12 @@ def fill_template_form(pdftk, data, flatten: true) end def combine_pdfs(next_steps_tempfile, template_tempfile) - pdf = CombinePDF.new - pdf << CombinePDF.load(next_steps_tempfile.path) if next_steps_page? - pdf << CombinePDF.load(template_tempfile.path) - pdf.save(@tempfile.path) + pdf = HexaPDF::Document.new + next_steps_pdf = HexaPDF::Document.open(next_steps_tempfile.path) + next_steps_pdf.pages.each { |page| pdf.pages << pdf.import(page) } + template_pdf = HexaPDF::Document.open(template_tempfile.path) + template_pdf.pages.each { |page| pdf.pages << pdf.import(page) } + pdf.write(@tempfile.path, optimize: true) @tempfile.rewind end diff --git a/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122.rb b/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122.rb index 6798cfdebc4..85ae294956f 100644 --- a/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122.rb +++ b/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122.rb @@ -10,7 +10,7 @@ class Form2122 < RepresentationManagement::V0::PdfConstructor::Base protected def next_steps_page? - true + false end def next_steps_part1(pdf) diff --git a/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122a.rb b/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122a.rb index 7fa3136f890..2efe5e85e11 100644 --- a/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122a.rb +++ b/modules/representation_management/lib/representation_management/v0/pdf_constructor/form_2122a.rb @@ -11,7 +11,7 @@ class Form2122a < RepresentationManagement::V0::PdfConstructor::Base protected def next_steps_page? - true + false end def next_steps_part1(pdf) diff --git a/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations.pdf b/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations.pdf index ae2f22578dc..8642ebe0b15 100644 Binary files a/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations.pdf and b/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations_no_claimant.pdf b/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations_no_claimant.pdf index 0f315a3e051..8d4af1d0107 100644 Binary files a/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations_no_claimant.pdf and b/modules/representation_management/spec/fixtures/21-22/v0/default/2122_with_limitations_no_claimant.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations.pdf b/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations.pdf index 1328071d7a6..79bdd8eccf3 100644 Binary files a/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations.pdf and b/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations_no_claimant.pdf b/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations_no_claimant.pdf index ad0da5a8bce..869ea6005b1 100644 Binary files a/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations_no_claimant.pdf and b/modules/representation_management/spec/fixtures/21-22/v0/unflattened/2122_with_limitations_no_claimant.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations.pdf b/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations.pdf index 604baaa9214..7a77dd4a9a2 100644 Binary files a/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations.pdf and b/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations_no_claimant.pdf b/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations_no_claimant.pdf index 4b92fc9bfb6..10ab3af39a1 100644 Binary files a/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations_no_claimant.pdf and b/modules/representation_management/spec/fixtures/21-22A/v0/default/2122a_conditions_and_limitations_no_claimant.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations.pdf b/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations.pdf index 0bdbc00b8ef..e452751713f 100644 Binary files a/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations.pdf and b/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations.pdf differ diff --git a/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations_no_claimant.pdf b/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations_no_claimant.pdf index 02e9bf5cb1c..09ca2428b43 100644 Binary files a/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations_no_claimant.pdf and b/modules/representation_management/spec/fixtures/21-22A/v0/unflattened/2122a_conditions_and_limitations_no_claimant.pdf differ