Advanced PDF to Render Visualforce Page as PDF File

Advanced PDF renders Visualforce pages as PDF files with broader support for modern HTML standards, such as CSS3, JavaScript, and HTML5. This change applies to both Lightning Experience and Salesforce Classic.

To use Advanced PDF, set renderAs="advanced_pdf" in the <apex:page> tag of a Visualforce page with API version 40.0 or later.

Limitations:
  1. If you use inline CSS styles, set the API version to 28.0 or later. Also set <apex:page applyBodyTag="false">, and add static, valid <head> and <body> tags to your page, as in the previous example.
  2. The maximum response size when creating a PDF file must be less than 15 MB before being rendered as a PDF file. This limit is the standard limit for all Visualforce requests.
  3. The maximum file size for a generated PDF file is 60 MB.
  4. The maximum total size of all images included in a generated PDF is 30 MB.
  5. PDF rendering doesn’t support images encoded in the data: URI scheme format.
  6. The following components don’t support double-byte fonts when rendered as PDF.<apex:pageBlock><apex:sectionHeader>
  7. These components aren’t recommended for use in pages rendered as PDF.
  8. If an <apex:dataTable> or <apex:pageBlockTable> has no <apex:column> components that are rendered, rendering the page as PDF fails. To work around this issue, set the table component’s rendered attribute to false if none of its child <apex:column> components are rendered.

Sample Code:


  1. <apex:page readOnly="true"     
  2.            standardController="Account"    
  3.            applyHtmlTag="false"     
  4.            sidebar="false"     
  5.            showHeader="false"     
  6.            cache="true"     
  7.            renderAs="advanced_pdf">    
  8.         
  9.     <head>    
  10.         <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
  11.         <style type="text/css">    
  12.             
  13.             @page {    
  14.               
  15.                 size: A4 landscape;    
  16.                 border: 2px solid black;    
  17.                 padding-left: 8px;    
  18.                 padding-right: 8px;      
  19.                   
  20.             }    
  21.                 
  22.             th {    
  23.               
  24.                 text-align: center;    
  25.                 font-weight: bold;    
  26.                   
  27.             }    
  28.                 
  29.                 
  30.             td {    
  31.               
  32.                 text-align: center;    
  33.                 font-size: 14px;    
  34.                   
  35.             }    
  36.                 
  37.         </style>    
  38.           
  39.     </head>    
  40.       
  41.     <center>    
  42.       
  43.         <h3>Testing Advanced PDF = {!Account.Name}</h3>    
  44.           
  45.     </center><br/><br/>    
  46.       
  47.     <table border="1" width="99%">    
  48.       
  49.         <tr>    
  50.           
  51.             <th>First Name</th>    
  52.             <th>Last Name</th>    
  53.               
  54.         </tr>    
  55.         <apex:repeat value="{!Account.Contacts}" var="con">    
  56.           
  57.             <tr>    
  58.               
  59.                 <td>{!con.FirstName}</td>    
  60.                 <td>{!con.LastName}</td>    
  61.                   
  62.             </tr>    
  63.               
  64.         </apex:repeat>    
  65.           
  66.     </table>    
  67.     
  68. </apex:page>    

Output:


No comments:

Post a Comment