+ Start a Discussion
Shirish DwivediShirish Dwivedi 

Visual Page: Print as Pdf

Hi everyone,

Suppose I have a "print this" hyperlink at the end of the visual force page on clicking it I want the Visual force page to open in a new window as pdf giving users direct option to print. I know with chrome we can print by right clicking mouse and so on.. but I need this print hyperlink to work.
I have tried Render as="pdf" method but since the page has complex coding structure its not working.

is there anyway I can use jsPdf library or Pdf.js library and execute the above as function. I need a way to know how can I export all the data on the visual form page to the new window as pdf?
Narveer SinghNarveer Singh
Hi Shirish,

You can create new vf page on which all of data will render as below :

<apex:page controller="pdfReport" renderAs="pdf" showHeader="true">
    Event Date,Your Column Name
    <apex:repeat value="{!List}" var="varriable">
       <apex:repeat value="{!List[ID]}" var="eve">
           {!eve.your Filed}

On Button from your current page you need to call a function in controller to redirect to above page :

public PageReference exportToPDF() {
        return Page.PDFPage;

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution.Let me know if any issue.

Best Regards
Shirish DwivediShirish Dwivedi
ok so I have created that reneder page called pdfView and a controller class called viewpdf.cls. How do I call this page onClick event of button?
Narveer SinghNarveer Singh
You can use same controller and List in which you have stored the data from DB.Need to add above function and below is th code for button in VF:

<apex:commandButton value="Download Report" action="{!exportToPDF}"/>