+ Start a Discussion
DaveIngramDaveIngram 

How do I get backgrounds to render in my Visualforce PDF's?

Hi,

 

We are working on some document templates that i want to have a watermark background on each page.

 

It looks great as an HTML but when i try to render the page as PDF it looses the background .

 

Is there a way to fix this?

 

thanks

Dave

Alderete_SFDCAlderete_SFDC

Dave, I'm working on documenting some best practices in this area. Can you share a code example from your templates, that illustrates the issue your having? I should be able to help you fix it.

Alderete_SFDCAlderete_SFDC

I should have been more specific. What is the HTML/CSS technique you're using to add the background "watermark" image?

 

We recommend adding background images via CSS, rather than as attributes added in the HTML. I am working on a code sample, but if you provide yours, I can tailor it specifically to your situation. Otherwise, I'll post the generic example here tomorrow.

DaveIngramDaveIngram

Hi,

 

I have tried 3 metholds:

 

  1. Pure HTML witht he background on a server
  2. CSS and background tile as a resource
  3. using the z-index to force the image as a fake background(works but is messy)

here are examples:

 

 

  1. <body background="www.url.com/tile.jpg">
  2. Body{

    font-family:"Tahoma";
    font-size:20px;
    background-image: url("tile.jpg");
    }

  3. <img src="{!$Resource.mycss}" style="position: fixed; left: 0.1cm; top:2.5cm; z-index:-1"></img>

 

these all render perfectly as HTML but when you saw to render as PDF the backgorunds dissapear.

 

I am wondering if the PDF is removing the background as it behaves like a printer sometimes.

 

thanks

Dave

 

ptepptep

@Alderete_SFDC, 

 

Did you ever finish this documentation?  I'm interested in generating PDFs with custom watermarks through visualforce and I've basically found it impossible. Any feedback or docs you can provide would be great.

Alderete_SFDCAlderete_SFDC

No, sorry, this specific documentation topic got postponed. I have a blog post that's 3/4 finished, and need to resolve a couple of problems I can into with my sample code. I hope to get it done later this Summer...

ptepptep

Cool, thanks. Please let me know if/when you get to post it.