[SalesForce] Scaling Images in Visualforce PDFs

In our org, users are able to create PDFs with a logo in the header. We're using renderAs="pdf" to achieve this. The problem is we can't control the dimensions of the logos, so we need to scale them appropriately when we render the page. Here's what I've tried:

  <style>
        .headerLogo{
            max-height:100px; 
            max-width:200px; 
        }
  </style>

  <div class="header">
        <div>
            <img class="headerLogo" src="{!imageURL}"/>
        </div>
  </div>

When I don't render the page as a PDF this works great, but once i render as a PDF, the logo just expands to its original size. Is max-height/max-width supported in the Salesforce PDF generator?

Best Answer

From the "What about embedded images? Are images downscaled?" section of The Flying Saucer User's Guide (the technology usually assumed to generate PDF in Salesforce):

For intrinsic width/height calculations we assume a resolution of 96 DPI, but setting an explicit width/height makes it possible to use an arbitrary DPI.

In repositories such as https://github.com/flyingsaucerproject/flyingsaucer there isn't obvious evidence that the max-height and max-width are supported for images. So try width or height instead in your CSS.