2

I have a visualforce page which renders PDF OK when viewing in Salesforce. However, the same page doesn't renders the styles in PDF when viewing through a Salesforce community site. Any idea what is going wrong with the PDF generation from community site?? The page is given below:

<apex:page renderAs="pdf" applyBodyTag="false" 
    showHeader="false" sidebar="false" standardStylesheets="false" >
    <head>
        <style>
            .grad{
            Width:600px;
            Height:600px;
            background: #0098d5; /* Old browsers */

            }
            #tst{
            color:red;
            font-size:60pt;
            }
        </style>
    </head>
    <body>
        <div class="grad">
            <span id="tst"> Hello Salesforce</span>
        </div>
    </body>
 </apex:page>

Thanks.

  • What styling doesn't it render from the community? Remember that you also have a community template involved here as well that could be in contention for styling (could depend on how this page is called and where community stylesheets are referenced). – crmprogdev Mar 17 '17 at 14:19
  • The PDF output is is supposed to be a DIV with blue background and Text with font size 60pt. These styles don't appear in the community PDF output. I get a standard black text without background DIV. – Attiq Ur-Rehman Mar 17 '17 at 14:21
  • I suggest you to put styling in static resources and then refer it here – Rohit Mourya Mar 17 '17 at 14:23
  • My requirements include customer specific CSS styles. Static resource will result in a fixed CSS. – Attiq Ur-Rehman Mar 17 '17 at 14:25
  • I'd recommend you replace the span tag with a <p> tag (or table) and use a text align = center if that's what you're looking to accomplish. PDFs can be very finicky and work best with tables. Also, use an @media tag because the 800px won't be valid for print. – crmprogdev Mar 17 '17 at 14:26
3

Add applyHtmlTag="false" to your page and enclose the content of your page in html tags.

Issue is because, when you see the page as a community user. It adds style to your HTML: <html style="display:none !important;">

Just tried in my dev org and it worked:

<apex:page renderAs="pdf" applyBodyTag="false"
    applyHtmlTag="false" 
    showHeader="false" sidebar="false" standardStylesheets="false" >
    <html>
    <head>
        <style>
            .grad{
            Width:600px;
            Height:600px;
            background: #0098d5; /* Old browsers */

            }
            #tst{
            color:red;
            font-size:60pt;
            }
        </style>
    </head>
    <body>
        <div class="grad">
            <span id="tst"> Hello Salesforce</span>
        </div>
    </body>
    </html>
 </apex:page>
  • Cheers, Working with PDF is very tricky sometimes. – Raul Mar 17 '17 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.