Hot answers tagged

25

Visualforce Charts are rendered by JavaScript after the page has been initially rendered. PDF does not support JavaScript, and so those charts never have a chance to render before the PDF file is created. This is in direct contrast to Google Charts, which are rendered as images on the Google server before being delivered. You will need to use a image-based ...


14

I've handled this directly as part of my Apex code by using some CSS tricks. Try this out. <apex:variable var="cnt" value="{!0}" /> <apex:repeat value="{!cases}" var="cse"> <!-- apex:OutputText value="{!cnt}"/ --> <div style="{!if(cnt < 1, 'page-break-before:avoid;','page-break-before:always;')}"> <apex:...


14

As of Summer '18, this pilot program has been cancelled. The service didn't quite meet the scalability goals we needed. Safe harbor, we're working on a way to bring the program back and adapt it to support Lightning components as well.


12

Change your Batch Apex class from this: string path = '/' + c.id + '/p'; BatchPDF.PageReference pr = new BatchPDF.PageReference( path ); to this: string path = Page.CaseDetail.getUrl() + '?id=' + c.Id; BatchPDF.PageReference pr = new BatchPDF.PageReference( path ); So instead of using the printable view URL like/001000000000000AAA/p/, you get the ...


12

The current v31.0 "official" line is that there is a limited set of fonts available. Fonts Available When Using Visualforce PDF Rendering Visualforce PDF rendering supports a limited set of fonts. Use the following font names to ensure that PDF output renders as you expect. The fonts available when you’re rendering a page as a PDF are as follows. ...


12

I think the main issues is that you should put your margin measurements in the @page element and remove them from the content div. For readability, i've put this all in one VF page: <apex:page standardStylesheets="false" id="pge" renderAs="pdf" controller="DynaPdfPageCTRL" applyHtmlTag="false" showHeader="false" > <head> <style> ...


11

Here's an idea for an overall simpler solution. First, you need a way to expose your information to a 3rd Party (your "Users" without access). This is exactly what Sites are for. Now, creating the pages & code to properly verify users and log them in as well as creating methods to guarantee that you don't expose data you don't want to (sessionCheck ...


11

You can set the name and extension of the PDF explicitly as follows, for example Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=AccountReport.pdf'); Unfortunately this is directly not supported in tag in Visualforce.


11

Inside your CSS in tables style tag, you need to add the following attribute: table { -fs-table-paginate: paginate; } puts a header at the start of each new page where a table crosses a page boundary. The -fs reportedly refers to Flying Saucer, the render engine used by SF to create PDFs and is specific to that render engine (not for use elsewhere).


10

You can either wrap the text in a <pre> tag or give the container a style of white-space: pre; <apex:page renderAs="pdf"> <apex:outputPanel style="white-space: pre;" layout="block"> herp derp derpity doop </apex:outputPanel> </apex:page>


10

Assuming "Project" is a custom object. Enable notes and attachment for the custom object. When you click 'generate invoice', just before redirecting to VF page use getContent() method. E.g; public PageReference generateInvoice() { Attachment att = new Attachment(name ='Invoice_AnyUniqueName.pdf'); PageReference invoicePage = Page....


10

I found an easy solution for the problem, no need to implement any logic for the same just included the following attribute -fs-table-paginate: paginate; in tables style tag and worked like a miracle.


10

I just figured this out after 30 minutes of Googling and thought a concise post may help others in future. It was not documented in the SFDC documentation but was on an different post from 2012. Is it possible to use images in Visualforce generated PDFs which are not static resources? The issue was that the PDF rendering engine runs under the same ...


9

From the phrasing of your question, it sounds as though you may have a bit of a misunderstanding of how PDF "previews" work, either that or the terminology you're using is in reference to visualforce page you're starting the preview/render process from rather than the actual page that's being previewed/rendered as a PDF. PDF's are typically rendered from a ...


9

This was actually solved by setting the pdf filetype to 'Execute in Browser' from Setup -> Security Controls -> File Upload and Download Security


8

In the Code Coverage podcast with Josh Birk there was mention of an improved PDF rendering engine pilot at the 19 minute 30 second mark. I couldn't find mention of it on Google or in the IdeaExchange Pilot/Beta list. It sounds like you need to raise a ticket or contact Josh directly to get in the pilot. Will it solve you word-wrap issue? I don't know. But ...


8

You have to use applyBodyTag="false" attribute in <apex:page tag as explained in Visualforce Developer Guide to render the PDF properly. I checked with the below code and I am able to render the PDF in landscape mode. <apex:page standardController="Account" renderAs="pdf" applyBodyTag="false"> <head> <style> @...


8

It is a common assumption that the HTML to PDF engine presently used by Salesforce is Flying Saucer that only supports version 2.1 of CSS (W3C Recommendation 07 June 2011) whereas SLDS is designed to work with modern browsers only that support version 3 CSS. So while you may be able to eventually get some parts of the SLDS markup to work, the PDF output is ...


7

With API 29. there are some changes how the PDF rendering engine works. Have a look at the below example <apex:page standardController="Account" standardStylesheets="false" applyHtmlTag="false" showHeader="false" renderAs="PDF"> <head> <style type="text/CSS"> body{ font-family:"Helvetica Neue",...


7

You can't get the PDF content unfortunately. While Email Services do run under a 'Context User', you will notice that UserInfo.getSessionId() returns null from any InboundEmailHandler implementation you may have. The HTML with JavaScript is serving up a client-side redirect to a Salesforce login page. This is because pdf.getContent() runs in a different ...


7

Welcome to SF.SE Bolt. <apex: outputField> is considered an unsafe component to use when rendering a PDF. See Best Practices for Rendering PDFs to learn which ones can and cannot be safely used.


7

After nearly giving up and trying to recreate the standard template in VisualForce (ouch!), I somehow managed to find a WordPress article on how to create a PDF with the standard template (or a custom template) created through the UI. It is sort of hacky, but it beats having to recreate a template from scratch! The article can be found here. I also came up ...


7

Here is my modified version of the Visualforce page from Adding page header/footer into a VisualForce page rendered as PDF. As you have done, I've added applyBodyTag="false" to the apex:page element to get the header/footer to render correctly. I think the issue is that flying saucer isn't considering the height of the header content when positioning the ...


7

Kudos to @SFDCGOD for suggesting this. I was so intrigued by his suggestion, I gave it a try. First, I created resources for each of the Javascript files (FileSaver.js and jszip.js) and then created a simple Visualforce page referencing them so I could use it as a listview button: <apex:page standardController="c2g__codaInvoice__c" recordSetVar="...


6

I ran into this recently. I don't know if it is a bug or not, but it is annoying! Basically if your two pages share the same controllers, then it ignores the new page. If you do TestPDF.getContentasPDF(), you'll see that it is rendering Page 1 instead of Page 2. If you take the oncomplete and the rerender off the CommandButton, it will render the correct ...


6

Try to add a border to the @page css rule (the page area includes the boxes laid out on that page). Because of the page area the border will be drawn on each generated page: <apex:page renderAs="pdf" applyHtmlTag="false" showHeader="false" cache="true" readOnly="true"> <head> <meta http-...


6

This is possible with having some extra css. Wrap your invoice data with a div and introduce css class as below <style> .page-break { page-break-before:always; } .page-break:first-child { page-break-before: avoid; } @page { size: A4; @bottom-center { content: "Page " counter(page) " of " counter(...


6

From the "What about embedded images? Are images downscaled?" section of The Flying Saucer User's Guide (the technology usually assumed to generate PDF in Salesforce): For intrinsic width/height calculations we assume a resolution of 96 DPI, but setting an explicit width/height makes it possible to use an arbitrary DPI. In repositories such as https:/...


6

Assuming the PDF generation in Salesforce is based on Flying Saucer, the Flying Saucer FAQ includes an example of how to embed a custom font: @font-face { font-family: "UbuntuMono"; src: url("UbuntuMono-R.ttf"); -fs-pdf-font-embed: embed; -fs-pdf-font-encoding: Identity-H; } * { font-family: "UbuntuMono"; } which ...


6

It seems that Salesforce converts attachment to html links when total size exceeds 3Mb. This is very annoying. Source 1 Source 2


Only top voted, non community-wiki answers of a minimum length are eligible