|  |  | @ -211,11 +211,11 @@ module Submissions | 
			
		
	
		
		
			
				
					
					|  |  |  |       image_pdfs = [] |  |  |  |       image_pdfs = [] | 
			
		
	
		
		
			
				
					
					|  |  |  |       original_documents = template.documents.preload(:blob) |  |  |  |       original_documents = template.documents.preload(:blob) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       results = |  |  |  |       result_attachments = | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         submitter.submission.template_schema.map do |item| |  |  |  |         submitter.submission.template_schema.map do |item| | 
			
		
	
		
		
			
				
					
					|  |  |  |           pdf = pdfs_index[item['attachment_uuid']] |  |  |  |           pdf = pdfs_index[item['attachment_uuid']] | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |           attachment = save_pdf(pdf:, submitter:, pkcs:, tsa_url:, |  |  |  |           attachment = build_pdf_attachment(pdf:, submitter:, pkcs:, tsa_url:, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                                             uuid: item['attachment_uuid'], |  |  |  |                                             uuid: item['attachment_uuid'], | 
			
		
	
		
		
			
				
					
					|  |  |  |                                             name: item['name']) |  |  |  |                                             name: item['name']) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -224,15 +224,15 @@ module Submissions | 
			
		
	
		
		
			
				
					
					|  |  |  |           attachment |  |  |  |           attachment | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       return results if image_pdfs.size < 2 |  |  |  |       return result_attachments.map { |e| e.tap(&:save!) } if image_pdfs.size < 2 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       images_pdf = |  |  |  |       images_pdf = | 
			
		
	
		
		
			
				
					
					|  |  |  |         image_pdfs.each_with_object(HexaPDF::Document.new) do |pdf, doc| |  |  |  |         image_pdfs.each_with_object(HexaPDF::Document.new) do |pdf, doc| | 
			
		
	
		
		
			
				
					
					|  |  |  |           pdf.pages.each { |page| doc.pages << doc.import(page) } |  |  |  |           pdf.pages.each { |page| doc.pages << doc.import(page) } | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       images_pdf_result = |  |  |  |       images_pdf_attachment = | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         save_pdf( |  |  |  |         build_pdf_attachment( | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           pdf: images_pdf, |  |  |  |           pdf: images_pdf, | 
			
		
	
		
		
			
				
					
					|  |  |  |           submitter:, |  |  |  |           submitter:, | 
			
		
	
		
		
			
				
					
					|  |  |  |           tsa_url:, |  |  |  |           tsa_url:, | 
			
		
	
	
		
		
			
				
					|  |  | @ -241,10 +241,10 @@ module Submissions | 
			
		
	
		
		
			
				
					
					|  |  |  |           name: template.name |  |  |  |           name: template.name | 
			
		
	
		
		
			
				
					
					|  |  |  |         ) |  |  |  |         ) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       results + [images_pdf_result] |  |  |  |       (result_attachments + [images_pdf_attachment]).map { |e| e.tap(&:save!) } | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     def save_pdf(pdf:, submitter:, pkcs:, tsa_url:, uuid:, name:) |  |  |  |     def build_pdf_attachment(pdf:, submitter:, pkcs:, tsa_url:, uuid:, name:) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |       io = StringIO.new |  |  |  |       io = StringIO.new | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       pdf.trailer.info[:Creator] = info_creator |  |  |  |       pdf.trailer.info[:Creator] = info_creator | 
			
		
	
	
		
		
			
				
					|  |  | @ -282,7 +282,7 @@ module Submissions | 
			
		
	
		
		
			
				
					
					|  |  |  |       end |  |  |  |       end | 
			
		
	
		
		
			
				
					
					|  |  |  |       # rubocop:enable Metrics |  |  |  |       # rubocop:enable Metrics | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       ActiveStorage::Attachment.create!( |  |  |  |       ActiveStorage::Attachment.new( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         blob: ActiveStorage::Blob.create_and_upload!(io: StringIO.new(io.string), filename: "#{name}.pdf"), |  |  |  |         blob: ActiveStorage::Blob.create_and_upload!(io: StringIO.new(io.string), filename: "#{name}.pdf"), | 
			
		
	
		
		
			
				
					
					|  |  |  |         metadata: { original_uuid: uuid, |  |  |  |         metadata: { original_uuid: uuid, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     analyzed: true, |  |  |  |                     analyzed: true, | 
			
		
	
	
		
		
			
				
					|  |  | 
 |