title: JPEG scans to one PDF with Ruby using Prawn
body: <p>I have a bunch of JPEGs, which are scans of the ~ same size:</p>
  
  <ul>
  <li>image1: 4816 × 6900</li>
  <li>image2: 4816 × 6900</li>
  <li>image3: 4816 × 6848 (tried to make it the same size as other - the image is still broken in export)</li>
  </ul>
  
  <p>I convert them using ImageMagick to PDF using this command:</p>
  
  <pre><code>$ convert image1.jpg image2.jpg image3.jpg output.pdf
  </code></pre>
  
  <p>Output file is rather odd - images of the same size are exported fine, while <code>image3</code>, which has less height (6848), appears to be exported to the page ~10 times smaller compared to other pages.</p>
  
  <p><a href="https://i.stack.imgur.com/VowjF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VowjF.png" alt="enter image description here"></a></p>
  
  <p>So I decided to use Prawn to do the same:</p>
  
  <pre><code>Prawn::Document.generate(pdf_path, page_size: 'EXECUTIVE') do
    images.each do |image|
      # `image` is a service object wrapping image parameters &amp; path to it
      start_new_page(size: image,size, layout: :portrait)
      image image_path, at: [0, 0], width: image.width, height: image.height
    end
  end
  </code></pre>
  
  <p>In the end I get PDF with N empty pages (no images). But according to the PDF size, it contains those image (I suppose), I've just aligned it wrong.</p>
  
  <p>Can't get an idea how to fix that. Any thoughts?</p>
  
  <p>Thanks in advance!</p>