From 9cc85595e34297c0b48d957ac912e0169ca57ca2 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Wed, 9 Aug 2023 09:33:14 +0300 Subject: [PATCH] fix font size on large pdfs --- lib/submissions/generate_result_attachments.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 3f53af2c..b0733b47 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -37,6 +37,7 @@ module Submissions width = page.box.width height = page.box.height + font_size = ((page.box.width / A4_SIZE[0].to_f) * FONT_SIZE).to_i value = submitter.values[field['uuid']] @@ -70,13 +71,13 @@ module Submissions items = Array.wrap(value).each_with_object([]) do |uuid, acc| attachment = submitter.attachments.find { |a| a.uuid == uuid } - acc << HexaPDF::Layout::InlineBox.create(width: FONT_SIZE, height: FONT_SIZE, + acc << HexaPDF::Layout::InlineBox.create(width: font_size, height: font_size, margin: [0, 1, -2, 0]) do |cv, box| cv.image(PdfIcons.paperclip_io, at: [0, 0], width: box.content_width) end acc << HexaPDF::Layout::TextFragment.create("#{attachment.filename}\n", font: pdf.fonts.add(FONT_NAME), - font_size: FONT_SIZE) + font_size:) end lines = layouter.fit(items, area['w'] * width, height).lines @@ -132,7 +133,7 @@ module Submissions value.chars.each_with_index do |char, index| text = HexaPDF::Layout::TextFragment.create(char, font: pdf.fonts.add(FONT_NAME), - font_size: FONT_SIZE) + font_size:) cell_layouter.fit([text], cell_width, area['h'] * height) .draw(canvas, ((area['x'] * width) + (cell_width * index)), @@ -142,7 +143,7 @@ module Submissions value = I18n.l(Date.parse(value), format: :long) if field['type'] == 'date' text = HexaPDF::Layout::TextFragment.create(Array.wrap(value).join(', '), font: pdf.fonts.add(FONT_NAME), - font_size: FONT_SIZE) + font_size:) lines = layouter.fit([text], area['w'] * width, height).lines box_height = lines.sum(&:height)