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
torotoro 

Open PDF in new window after save

Hello,

 

I'm looking for a way to open PDF file in new window after saving current change on the page.

 

I created "Order Report" page, which shows lots of custom fields added on Opportunity, like customer PO#, shipping instruction etc.

When the user finish editing the order report, they need to save it in PDF.

so I've created command button "Convert to PDF" and code is:

 

<apex:commandButton value="Convert to PDF"  onClick="window.open('/apex/orderReportPDF?id={!Opportunity.Id}');" />

 The problenm is the PDF shows the data before the user edit order report.

I think I need to put some code in APEX  extension class, but don't know how to code to open the PDF in new window.

 

or is there a way to show pop-up message to tell them to click "SAVE" button before "Convert to PDF"?

 

Thanks for your help.

Best Answer chosen by Admin (Salesforce Developers) 
torotoro

Figured out by myself.

All Answers

torotoro

Figured out by myself.

This was selected as the best answer
Starz26Starz26

Do share

Ahmed AdelAhmed Adel

can you tell me how you did it , because I need this way too

Starz26Starz26

If it is anything like excel this is how I did it...

 

I created a second VF page with only the data output sections. Then on the main VF page I created a command button that called this function in the controller:

 

public Pagereference createOutput()

{

     return new Pagereference('/apex/vfDLHImpactDollarsExcel?year=' + paramYear);

}

 

you can make the new pagereference(......) anything you need it to to point to your second data only output. I used get and a parameter to set the data in the second vf page.

torotoro

Here is what I did.

 

Create a second VF page (render as PDF).

On first VF page, add command button with action="{!save}" and onClick to open PDF in new window.

(see code below)



 <apex:commandButton value="Convert PDF"  action="{!save}" rerender="{!Opportunity}" onClick="window.open('/apex/orderReportPDF?id={!Opportunity.Id}');" />

 First page is the page that use enter information in, when user click "Convert PDF" button it will asve it and open PDF in new window.

On second page, I made it nicely format and put company logo on it, but you can use same code and just add "render as PDF" in Apex:page line.

 

Hope this will help.

mmrrmmrr

Can you please give me the solution which worked.

The requirement is to open a PDF file when the record is clicked. I am either able to open a blank pdf when the record is clicked  or the datas are getting stored as an pdf attachment in the record. Hope you could help me on this.