6

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?

2
  • Are these images a known ratio or could they be pretty much anything? Aug 25, 2014 at 21:12
  • Unfortunately they can be pretty much anything.
    – Sean
    Aug 25, 2014 at 21:14

1 Answer 1

7

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.

4
  • Unfortunately I won't know the dimensions of the logos since Users can choose their own logos, so if I set width/height it may distort the images. I want to use max-width/max-height so that that I can make sure the picture is not distorted and so it fits in the header.
    – Sean
    Aug 25, 2014 at 22:20
  • @Sean Just set the width or the height; the other dimension should scale in proportion. But not a perfect solution. And tell your users what sizes are required/recommended/allowed.
    – Keith C
    Aug 25, 2014 at 22:34
  • Yeah I figured that would be the best I could get. Setting just the width causes issues with tall skinny images, and just the height causes issues with short fat images. Thanks for your input!
    – Sean
    Aug 25, 2014 at 22:40
  • @Sean There is mention in this thread word-wrap not working with VisualForce PDF generation? of the PDF engine changing in the future so eventually this problem might be solved.
    – Keith C
    Aug 26, 2014 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .