{"id":2412,"date":"2026-10-22T09:00:00","date_gmt":"2026-10-22T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/"},"modified":"2026-11-15T11:29:55","modified_gmt":"2026-11-15T05:59:55","slug":"visualforce-pdf-lightning","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/","title":{"rendered":"Visualforce PDF Rendering and Visualforce in Lightning Experience"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Visualforce PDF rendering is still the simplest way to produce a document from Salesforce data without buying anything. Add one attribute to a page and the platform returns a file instead of a web page. So a fee receipt, a certificate or a statement becomes a button click.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/visualforce-basics-standard-controllers\/\">Visualforce Basics<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/visualforce-custom-controllers-extensions\/\">Custom Controllers<\/a>. We will build a fee receipt for Bright Path Tutors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Visualforce PDF Rendering?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Visualforce PDF rendering means setting <code>renderAs=\"pdf\"<\/code> on a page. Salesforce builds the HTML as usual, then passes it to a conversion engine that produces a PDF file. The user gets a download rather than a page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of printing a web page to PDF from your browser. The difference is that Salesforce does it on the server, so the file is identical for everyone and can be attached to a record.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Visualforce PDF Still Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Lightning Web Components cannot generate a PDF. Neither can Flow on its own. So when a business asks for a printable receipt, Visualforce is usually the answer that costs nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Visualforce PDF output is also predictable. Because it renders server side, the result does not change with the user&#8217;s browser, which matters for anything official.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Visualforce PDF Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The page runs normally, then a conversion step turns the HTML into a file.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-1-1024x640.png\" alt=\"Visualforce PDF diagram showing how a page becomes a downloadable file\" class=\"wp-image-2410\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How a page request becomes a downloadable file.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The Minimum Page<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page standardController=\"Fee__c\"\n           renderAs=\"pdf\"\n           applyBodyTag=\"false\"\n           showHeader=\"false\"\n           standardStylesheets=\"false\"&gt;\n    &lt;head&gt;\n        &lt;style type=\"text\/css\"&gt;\n            @page { size: A4; margin: 20mm; }\n            body { font-family: Arial, sans-serif; font-size: 11pt; }\n        &lt;\/style&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h2&gt;Fee receipt&lt;\/h2&gt;\n        &lt;p&gt;Received from {!Fee__c.Student_Name__c}&lt;\/p&gt;\n        &lt;p&gt;Amount: {!Fee__c.Amount__c}&lt;\/p&gt;\n    &lt;\/body&gt;\n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Those four attributes matter. Turning off the header and standard stylesheets stops Salesforce styling from leaking into the document.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Page Size and Margins<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>@page<\/code> rule is where you control paper.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@page {\n    size: A4 portrait;\n    margin: 15mm 20mm;\n\n    @top-center { content: \"Bright Path Tutors\"; }\n    @bottom-right { content: \"Page \" counter(page) \" of \" counter(pages); }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Those at-rules give you a running header and automatic page numbers, which plain HTML cannot do.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Controlling Page Breaks<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div style=\"page-break-after: always;\"&gt;First page content&lt;\/div&gt;\n&lt;table style=\"page-break-inside: avoid;\"&gt;...&lt;\/table&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>page-break-inside: avoid<\/code> on tables and blocks you do not want split across pages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fonts and Unicode<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The PDF engine ships a limited font set. Arial, Times New Roman and Courier are safe. For Indian language text, you usually need to embed a font.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@font-face {\n    font-family: 'Noto';\n    src: url('{!URLFOR($Resource.NotoFont)}');\n}\nbody { font-family: 'Noto', Arial, sans-serif; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Upload the font file as a static resource first. Without this, non-Latin characters often render as empty boxes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Visualforce PDF Attributes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This table lists the attributes that control the output.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Attribute<\/th><th>Effect<\/th><\/tr><\/thead><tbody><tr><td>renderAs=&#8221;pdf&#8221;<\/td><td>Produces a PDF instead of HTML<\/td><\/tr><tr><td>applyBodyTag=&#8221;false&#8221;<\/td><td>Lets you write your own head and body<\/td><\/tr><tr><td>showHeader=&#8221;false&#8221;<\/td><td>Removes the Salesforce chrome<\/td><\/tr><tr><td>standardStylesheets=&#8221;false&#8221;<\/td><td>Stops platform CSS interfering<\/td><\/tr><tr><td>cache=&#8221;false&#8221;<\/td><td>Prevents a stale document being served<\/td><\/tr><tr><td>contentType<\/td><td>Can force a download with a file name<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Saving the PDF to a Record<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Generating the file is half the job. Attaching it needs Apex.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ReceiptService {\n    public static void attach(Id feeId) {\n        PageReference p = Page.FeeReceipt;\n        p.getParameters().put('id', feeId);\n\n        Blob body = Test.isRunningTest()\n            ? Blob.valueOf('test')\n            : p.getContentAsPDF();\n\n        ContentVersion cv = new ContentVersion();\n        cv.Title = 'Receipt';\n        cv.PathOnClient = 'Receipt.pdf';\n        cv.VersionData = body;\n        insert cv;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>getContentAsPDF<\/code> throws inside a test, which is why the check is there. That single line catches most developers out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Visualforce in Lightning Experience<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Old pages do not automatically work in Lightning. Two settings control it.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open Setup, then Visualforce Pages.<\/li>\n\n<li>Click Edit on the page.<\/li>\n\n<li>Tick Available for Lightning Experience, Experience Builder sites, and the mobile app.<\/li>\n\n<li>Save, then test the page inside Lightning.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">These are the common problems after switching.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem<\/th><th>Cause<\/th><\/tr><\/thead><tbody><tr><td>Page looks unstyled<\/td><td>Standard stylesheets turned off<\/td><\/tr><tr><td>window.location fails<\/td><td>Page runs inside an iframe<\/td><\/tr><tr><td>Buttons do nothing<\/td><td>The container blocks page redirects<\/td><\/tr><tr><td>Styling clashes<\/td><td>Salesforce Lightning Design System not applied<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To move the user elsewhere inside Lightning, use the <code>sforce.one<\/code> object rather than changing the browser location.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (typeof sforce != 'undefined' &amp;&amp; sforce.one) {\n    sforce.one.navigateToSObject('{!Fee__c.Id}');\n} else {\n    window.location.href = '\/{!Fee__c.Id}';\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Visualforce PDF vs a Document App<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This table shows when free is not enough.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Visualforce PDF<\/th><th>Paid app<\/th><\/tr><\/thead><tbody><tr><td>Cost<\/td><td>Free<\/td><td>Licensed<\/td><\/tr><tr><td>Who builds it<\/td><td>Developer<\/td><td>Admin<\/td><\/tr><tr><td>Complex layouts<\/td><td>Difficult<\/td><td>Designed for it<\/td><\/tr><tr><td>E-signature<\/td><td>No<\/td><td>Usually yes<\/td><\/tr><tr><td>Word output<\/td><td>No<\/td><td>Often yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-2-1024x640.png\" alt=\"Visualforce PDF compared with a paid document generation app\" class=\"wp-image-2411\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Visualforce PDF compared with a document generation app.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use Visualforce for simple receipts and statements. Buy a tool when you need contracts, signatures or admin-built templates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Visualforce PDF Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bright Path emails a receipt when a parent pays. The receipt must carry the centre logo and be attached to the fee record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Add the Logo<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Upload the image as a static resource, then reference it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"{!URLFOR($Resource.BrightPathLogo)}\" width=\"120\"\/&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Images must come from a static resource or a full URL. A relative path will not resolve during conversion.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Build the Receipt<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page standardController=\"Fee__c\" renderAs=\"pdf\"\n           applyBodyTag=\"false\" showHeader=\"false\" standardStylesheets=\"false\"&gt;\n    &lt;head&gt;\n        &lt;style type=\"text\/css\"&gt;\n            @page { size: A4; margin: 18mm; @bottom-center { content: counter(page); } }\n            body { font-family: Arial, sans-serif; font-size: 11pt; color: #222; }\n            .total { font-weight: bold; border-top: 2px solid #333; }\n            table { width: 100%; border-collapse: collapse; }\n            td { padding: 6px 0; }\n        &lt;\/style&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;img src=\"{!URLFOR($Resource.BrightPathLogo)}\" width=\"120\"\/&gt;\n        &lt;h2&gt;Fee Receipt&lt;\/h2&gt;\n        &lt;table&gt;\n            &lt;tr&gt;&lt;td&gt;Student&lt;\/td&gt;&lt;td&gt;{!Fee__c.Student_Name__c}&lt;\/td&gt;&lt;\/tr&gt;\n            &lt;tr&gt;&lt;td&gt;Course&lt;\/td&gt;&lt;td&gt;{!Fee__c.Course__r.Name}&lt;\/td&gt;&lt;\/tr&gt;\n            &lt;tr&gt;&lt;td&gt;Date&lt;\/td&gt;&lt;td&gt;{!Fee__c.Paid_On__c}&lt;\/td&gt;&lt;\/tr&gt;\n            &lt;tr class=\"total\"&gt;&lt;td&gt;Amount&lt;\/td&gt;&lt;td&gt;{!Fee__c.Amount__c}&lt;\/td&gt;&lt;\/tr&gt;\n        &lt;\/table&gt;\n    &lt;\/body&gt;\n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Watch the Limits<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These limits apply to Visualforce PDF output.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Limit<\/th><th>Value<\/th><\/tr><\/thead><tbody><tr><td>Response size<\/td><td>15 MB maximum<\/td><\/tr><tr><td>Rendering time<\/td><td>Times out on very large documents<\/td><\/tr><tr><td>Images<\/td><td>Must be static resources or full URLs<\/td><\/tr><tr><td>JavaScript<\/td><td>Not executed during conversion<\/td><\/tr><tr><td>getContentAsPDF in tests<\/td><td>Throws, so guard it<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Visualforce PDF<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Leaving standard stylesheets on, which breaks the print layout.<\/li>\n\n<li>Using relative image paths that do not resolve in the PDF engine.<\/li>\n\n<li>Expecting JavaScript to run, when the engine ignores it entirely.<\/li>\n\n<li>Calling getContentAsPDF in a test without a guard.<\/li>\n\n<li>Forgetting to tick Available for Lightning Experience on old pages.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Visualforce PDF<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Turn off the header and standard stylesheets on every PDF page.<\/li>\n\n<li>Use the @page rule for size, margins and page numbers.<\/li>\n\n<li>Embed a font when you need non-Latin characters.<\/li>\n\n<li>Keep documents short, since large ones time out.<\/li>\n\n<li>Test the PDF on real data before release, not just a sample record.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Build a one-page PDF for any object with a logo, three fields and a page number in the footer. Hint: the page number comes from counter(page) inside the @page rule.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Visualforce PDF Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Visualforce PDF questions come up when an interviewer asks about documents.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Visualforce PDF Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: How do you render a page as a PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Visualforce PDF output comes from setting renderAs equal to pdf on the apex:page tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: Why turn off standard stylesheets?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because platform CSS is built for screens and breaks print layout.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: Does JavaScript run in a PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. The conversion engine ignores scripts entirely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: How do you add an image?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reference a static resource with URLFOR, or use a full absolute URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you set the paper size?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the @page CSS rule, for example size A4 with margins.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: How do you force a page break?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the CSS property page-break-after or page-break-before on an element.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What is the response size limit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fifteen megabytes for the generated file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: Can LWC generate a PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. It must call a Visualforce page or an external service.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Intermediate Visualforce PDF Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you attach the PDF to a record?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call getContentAsPDF on a PageReference in Apex, then save the Blob as a ContentVersion.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: Why does getContentAsPDF fail in tests?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is not supported in a test context, so guard it with Test.isRunningTest and use a dummy Blob.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you add page numbers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use counter(page) and counter(pages) inside an @page at-rule such as bottom-center.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Why do non-Latin characters show as boxes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The default fonts lack those glyphs. So embed a font through a static resource with font-face.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you stop a table splitting across pages?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apply page-break-inside avoid to the table or the wrapping element.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: What makes a Visualforce page work in Lightning?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ticking Available for Lightning Experience on the page, then testing links and buttons inside the container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Why does window.location fail in Lightning?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the page runs inside an iframe. So use the sforce.one methods instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: How do you email the PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Generate the Blob, add it as an EmailFileAttachment and send with Messaging.sendEmail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Visualforce PDF Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Scenario: a PDF times out for large invoices. What do you change?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reduce rows per document, split into several files, or move generation to a Batch Apex job that saves files one at a time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How would you generate 5,000 receipts overnight?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use Batch Apex with a small scope, call getContentAsPDF per record and insert the ContentVersion records in bulk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Scenario: the PDF looks fine for admins but breaks for users. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Field level security hides fields, so expressions render blank. Check access on every field used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you keep the design maintainable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Put CSS in a static resource and reference it, so designers can change the look without touching the page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: What are the alternatives to Visualforce PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A paid document app, an external rendering service called from Apex, or client-side generation in LWC with a JavaScript library.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How do you version a document template?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep the page in source control and record the template version on the generated file, so you know which layout produced it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: Does Visualforce PDF respect sharing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It follows the controller. So a standard controller respects user access, while a custom controller needs with sharing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: Why avoid heavy CSS in a PDF page?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The engine supports an older CSS subset, so flexbox and grid often fail. Simple tables remain the most reliable layout.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Can a Visualforce PDF include a chart?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Only as an image. Because scripts do not run, a chart library will not draw, so generate the image first or build it with table cells.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: How do you preview a Visualforce PDF while developing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the page URL with a record Id and add the parameter to render it. Then check the file, since the browser view can differ.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: Does a Visualforce PDF count against API limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No, it is a page request rather than an API call. However, generating many in a batch still uses CPU time and heap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Scenario: the logo is missing from the PDF only in production. What do you check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whether the static resource deployed and whether the URLFOR reference matches its name. A missing resource renders nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: Should new document needs always use Visualforce PDF?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For simple layouts, yes, since it is free. For contracts or admin-edited templates, a purpose built tool saves far more time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.pages.meta\/pages\/pages_output_pdf_renderas.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Visualforce Guide: Rendering a Page as a PDF<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.pages.meta\/pages\/pages_lightning_experience.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Visualforce Guide: Visualforce in Lightning Experience<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_classes_restful_pagereference.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Reference: PageReference Class<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visualforce PDF output comes from one attribute, renderAs pdf.<\/li>\n\n<li>Turn off the header and standard stylesheets for clean print.<\/li>\n\n<li>The @page rule controls size, margins and page numbers.<\/li>\n\n<li>getContentAsPDF attaches the file, but throws inside tests.<\/li>\n\n<li>Old pages need Available for Lightning Experience ticked.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we modernise old pages with <a href=\"https:\/\/swapnilzambare.com\/blog\/migrating-visualforce-to-lwc\/\">Migrating Visualforce to LWC<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visualforce PDF rendering is still the simplest way to produce a document from Salesforce data without buying anything. Add one attribute to a page&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2409,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[245,8,96],"tags":[68,254,252],"swapz_series":[],"class_list":["post-2412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightning-web-components","category-salesforce","category-salesforce-developer","tag-advanced","tag-aura-and-visualforce","tag-lightning-ui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visualforce PDF Rendering and Lightning Guide<\/title>\n<meta name=\"description\" content=\"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visualforce PDF Rendering and Lightning Guide\" \/>\n<meta property=\"og:description\" content=\"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-22T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T05:59:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Visualforce PDF Rendering and Visualforce in Lightning Experience\",\"datePublished\":\"2026-10-22T03:30:00+00:00\",\"dateModified\":\"2026-11-15T05:59:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/\"},\"wordCount\":1695,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/visualforce-pdf-lightning-featured.png\",\"keywords\":[\"Advanced\",\"Aura and Visualforce\",\"Lightning UI\"],\"articleSection\":[\"Lightning Web Components\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/\",\"name\":\"Visualforce PDF Rendering and Lightning Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/visualforce-pdf-lightning-featured.png\",\"datePublished\":\"2026-10-22T03:30:00+00:00\",\"dateModified\":\"2026-11-15T05:59:55+00:00\",\"description\":\"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/visualforce-pdf-lightning-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/visualforce-pdf-lightning-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Visualforce PDF featured image: code editor card with renderAs pdf page\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/visualforce-pdf-lightning\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visualforce PDF Rendering and Visualforce in Lightning Experience\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visualforce PDF Rendering and Lightning Guide","description":"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/","og_locale":"en_US","og_type":"article","og_title":"Visualforce PDF Rendering and Lightning Guide","og_description":"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-22T03:30:00+00:00","article_modified_time":"2026-11-15T05:59:55+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Visualforce PDF Rendering and Visualforce in Lightning Experience","datePublished":"2026-10-22T03:30:00+00:00","dateModified":"2026-11-15T05:59:55+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/"},"wordCount":1695,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png","keywords":["Advanced","Aura and Visualforce","Lightning UI"],"articleSection":["Lightning Web Components","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/","url":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/","name":"Visualforce PDF Rendering and Lightning Guide","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png","datePublished":"2026-10-22T03:30:00+00:00","dateModified":"2026-11-15T05:59:55+00:00","description":"Learn Visualforce PDF rendering with renderAs, page size, headers, fonts and limits, plus running Visualforce in Lightning, with interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/visualforce-pdf-lightning-featured.png","width":2400,"height":1260,"caption":"Visualforce PDF featured image: code editor card with renderAs pdf page"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/visualforce-pdf-lightning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Visualforce PDF Rendering and Visualforce in Lightning Experience"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=2412"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2412\/revisions"}],"predecessor-version":[{"id":3053,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2412\/revisions\/3053"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2409"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2412"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}