Activity Forums Salesforce® Discussions How to include stylesheet in visualforce page rendered as pdf ?

  • Ravi

    Member
    March 22, 2016 at 11:12 am

    You're not going to be able to render PDFs properly that were created with Bootstrap. The Flying Saucer Render engine used by Salesforce only supports CSS 2.1 and HTML 4.1.

    When you remove render as pdf then bootstrap is available. Also keep in mind that there many css which will not work with renderAs=pdf

  • Prafull

    Member
    March 22, 2016 at 1:10 pm

    We can't use external/internal CSS in PDF. We can use inline CSS for best result. PDF will open with no bug in different browser when you use inline CSS.

  • Parul

    Member
    September 18, 2018 at 8:00 am

    When you remove render as pdf then bootstrap is available. Also keep in mind that there many css which will not work with renderAs=pdf so best to use inline CSS.

     

    Thanks

     

  • shariq

    Member
    September 21, 2018 at 12:12 am

    Hi,

    VisualForce allows you to create PDF documents (<apex:page RenderAs="PDF">), but did you know those files can be easily manipulated with CSS, for example you can break a document on different pages, you can set footers and headers, set the page size, and add page numbering.
    Resolution

     

    This page creates a PDF file that:
    Uses "Letter" as the paper size
    Has margins of 1/4 centimetres
    Has a title on every page
    Every page shows the page number in this format (page # of #)
    Controls what content goes on each page.

    Note: Provided solution may not work for all situations. You may have to enable/disable <apex:page> options to get the desired result.

    Hope this helps.

  • Parul

    Member
    September 21, 2018 at 4:27 am

    Here is the example:

    A Visualforce page rendered as a PDF file displays either in the browser or is downloaded, depending on the browser’s settings. Specific behavior depends on the browser, version, and user settings, and is outside the control of Visualforce.
    The following page includes some account details and renders as a PDF file.

    <apex:page standardController="Account" renderAs="pdf">

    <apex:stylesheet value="{!URLFOR($Resource.Styles,'pdf.css')}"/>

    <h1>Welcome to Universal Samples!</h1>

    <p>Thank you, <b><apex:outputText value=" {!Account.Name}"/></b>, for
    becoming a new account with Universal Samples.</p>

    <p>Your account details are:</p>

    <table>
    <tr><th>Account Name</th>
    <td><apex:outputText value="{!Account.Name}"/></td>
    </tr>
    <tr><th>Account Rep</th>
    <td><apex:outputText value="{!Account.Owner.Name}"/></td>
    </tr>
    <tr><th>Customer Since</th>
    <td><apex:outputText value="{0,date,long}">
    <apex:param value="{!Account.CreatedDate}"/>
    </apex:outputText></td>
    </tr>
    </table>

    </apex:page>

     

    Thanks

Log In to reply.

Popular Salesforce Blogs