diff --git a/app/javascript/template_builder/field.vue b/app/javascript/template_builder/field.vue index a70937c6..586b8d1b 100644 --- a/app/javascript/template_builder/field.vue +++ b/app/javascript/template_builder/field.vue @@ -485,11 +485,13 @@ export default { const areaString = JSON.stringify(field.areas[0]) this.template.documents.forEach((attachment) => { - attachment.preview_images.forEach((page) => { - if (!field.areas.find((area) => area.attachment_uuid === attachment.uuid && area.page === parseInt(page.filename))) { - field.areas.push({ ...JSON.parse(areaString), attachment_uuid: attachment.uuid, page: parseInt(page.filename) }) + const numberOfPages = attachment.metadata?.pdf?.number_of_pages || attachment.preview_images.length + + for (let page = 0; page <= numberOfPages - 1; page++) { + if (!field.areas.find((area) => area.attachment_uuid === attachment.uuid && area.page === page)) { + field.areas.push({ ...JSON.parse(areaString), attachment_uuid: attachment.uuid, page }) } - }) + } }) this.$nextTick(() => { diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index d1529519..80d88031 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -37,6 +37,7 @@ module Submissions account = submitter.submission.template.account pkcs = Accounts.load_signing_pkcs(account) tsa_url = Accounts.load_timeserver_url(account) + attachments_data_cache = {} pdfs_index = build_pdfs_index(submitter) @@ -78,7 +79,9 @@ module Submissions when 'image', 'signature', 'initials', 'stamp' attachment = submitter.attachments.find { |a| a.uuid == value } - image = Vips::Image.new_from_buffer(attachment.download, '').autorot + attachments_data_cache[attachment.uuid] ||= attachment.download + + image = Vips::Image.new_from_buffer(attachments_data_cache[attachment.uuid], '').autorot scale = [(area['w'] * width) / image.width, (area['h'] * height) / image.height].min