title: Make PDF page sizes fit image sizes
body: <p>I'm trying to create a PDF document from images of varying sizes so that each page of the PDF displays one of the images unscaled, the page size should fit the image dimensions.</p>
  
  <p>I'm using Prawn to generate the PDF from a list of image file names. To get the image dimensions I use FastImage.</p>
  
  <pre><code>Prawn::Document.generate('Output.pdf') do
    list_of_image_filenames.each do |i|
      image_size = FastImage.size(i)
      start_new_page(:size =&gt; image_size, :layout =&gt; :portrait)
      image(i)
    end
  end
  </code></pre>
  
  <p>To test it I'm using three PNG files of dimensions 560x560, 600x600, and 600x600. I've made sure that FastImage returns the correct image dimensions.</p>
  
  <p>The resulting PDF (Preview tells me it's PDF version 1.4) looks like this: </p>
  
  <ol>
  <li>It starts with 3 empty pages (one of which is probably due to the fact that I didn't put anything on the first page), then the first image, which is cropped. Except the first one, which I'm ignoring for now, these pages are of size 560x560 px, according to Preview.</li>
  <li>Next are two empty pages, then the second image, which also doesn't fit on the page. These pages have dimensions 600x600 px. </li>
  <li>Finally, two more blank pages and the third image, cropped again, page dimensions also 600x600 px.</li>
  </ol>
  
  <p>Here is a sample of one of the cropped images; the original image is a complete rounded rectangle with the digit "1" inside.</p>
  
  <p><img src="https://i.stack.imgur.com/X3WlM.jpg" alt="Sample of incorrectly displayed image"></p>
  
  <p>Why do the images not fit on the page? How can I put the individual unscaled images on pages fitting their dimensions?</p>