Hot answers tagged

35

You would need to set the Content-Disposition header. In constructor of the Visualforce controller: Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=AccountReport.pdf'); If you want to make the file name dynamic you will need to refer to several RFCs on how to correctly encode the filename. E.g. if it contains spaces ...


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

You can embed a PDF in a Visualforce (or any other HTML) page via a data URI. Using your example, the code would be something like: <apex:page controller="DownloadPDF" sidebar="false" showHeader="false" contentType="application/pdf"> <script> window.location.href = "data:application/pdf;base64,{!match1}"; </script> </...


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:...


13

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 ...


11

If you're considering calling out to a 3rd party app, you could also consider calling out to your own instance of Salesforce. In this case, you could create a REST service that calls PageReference.getContentAsPdf() and then insert the Attachment against the object. When the service is being called like this (i.e. using HTTPRequest callout from your Batch ...


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

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. ...


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).


11

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> ...


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 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

You can use : apex:page renderAs="pdf" showHeader="false" Than whenever that page open it download as a pdf


9

<apex:page renderAs="{!$CurrentPage.parameters.renderAs}" /> /apex/pageName?renderAs=pdf


9

The solution for this is to wrap the style tag in head tag. Include tag before tag <apex:page standardController="Invoice__c" extensions="PageControllera" showheader="false" sidebar="false" renderAs="pdf" > <head> <style> table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; ...


9

The PDF renderer's support of CSS Is limited and some trial and error is nearly always required to get the results you want. I'm not sure why your colours don't work, I've had no issues with that in the past so you might need to post the CSS and markup to show how you're doing it. The code you're using for landscape is correct, so I'm lead to think that you ...


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

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.


8

There are several mechanisms that allow you to upload files into SFDC. Rich Text Area is not the proper place where you should store these (I don't think its even possible either). Attachments Attachments are linked directly to a SOBject via the ID of the record. (Attachment.ParentId) and show as a related list at the bottom of the Detail Record. ...


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 ...


7

If you need not only convert your page to PDF but save this file with a specific name here is a workaround. You will need two pages – the first page generates an PDF file and the second saves it with specific filename: The main "wrapper" page saves PDF and gives a filename: <apex:page id="MainPage" showHeader="false" cache="true" ...


7

The way we did this in FinancialForce (as mentioned by eyescream above) was to include the VF page in the managed package, but ensure that the controller and all methods the page called by the page (same with any components you use) were marked as global. So the button defaults to using that VF page, all good. When the customer wants to override it they ...


7

Since you mentioned that you're using Visualforce page to send out an email, have you considered using a VisualForce email template? You could generate the PDF using VisualForce components and have that added into the VisualForce email template as an attachment. You may also use workflow rules to send the email to specified users.


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

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="...


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