function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrianFarrellBrianFarrell 

How do I open a new PDF window from a VF Page

Hi ,

I have a VisualForce page that allows you to enter text in fields and then display them in a formatted PDF page by clicking a preview button. This is done by using a second VisualForce page to display the rendered PDF. I want the rendered PDF page to appear in a separate windows page.

First VF Page - Enter PDF Text

                <apex:commandButton id="previewButton" action="{!previewPDF}" value="Preview"/>

the action !previewPDF is then called in an apex class

Apex Class

The class contains processing to calculate and format fields on the final rendered page and finally
creates a new page reference

  public pagereference previewPDF () {
        // Direct to the PDF page
        PageReference pageRef = new PageReference('/apex/vfNCDLetterBF?id=' + Policy__c.Id);      
        return pageRef;
  }

Second VF Page - Render PDF Text

This VF page should then render the text as a PDF in a separate window but it appears in the original window which forces the user to use the back button to return to the first VF Page.

I have tried adding the onClick.Window javascript to the first VF page but this does not work.
I have found similiar answers to this question but they dont work with my pages and classes
I have already tried this solution which did not work for me as a need to call the apex class before I

execute the onclick command.

 

http://boards.developerforce.com/t5/Visualforce-Development/opening-a-new-window-from-apex-code/m-p/241731/highlight/true#M31916

 

Any insights or help would be appreciated

Many Thanks
Brian

Best Answer chosen by Admin (Salesforce Developers) 
Ulas KutukUlas Kutuk

You can try this,

 

<apex:commandLink target="_blank"  value="Download Page" action="/apex/YourVFPage"/>

 

 

All Answers

VishwanathVishwanath

 

Hi,

try this it might be help you

 

<apex:Commandbutton><a href="/Pdfpagename?id=passidhere" target="_blank">previewPDF</a></commandbutton>

 

 

Ulas KutukUlas Kutuk

You can try this,

 

<apex:commandLink target="_blank"  value="Download Page" action="/apex/YourVFPage"/>

 

 

This was selected as the best answer
BrianFarrellBrianFarrell

Many Thanks UK1925 this works perfectly