+ Start a Discussion
Tim BarsottiTim Barsotti 

Convert Visualforce to HTML? Or Screenscrape VisualForce?

I have a unique requirement. There is a desire to perform a screenscrape from a VisualForce page and email it out.

 

I've looked into rendering as PDF and it is not an option. 

 

Is there a method to convert a VF page to HTML in order to email it out as the email body? 

 

OR

 

Is there a method to perform a screenscrape (e.g. screenshot) of a VisualForce page and email it out?

 

Thanks in advance! 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Try using getcontent() method of page reference class..

 

From Docs

 

getContent: Returns the output of the page, as displayed to a user in a Web browser. The content of the returned Blob is dependent on how the page is rendered. If the page is rendered as a PDF, it returns the PDF. If the page is not rendered as a PDF, it returns the HTML. To access the content of the returned HTML as a string, use the toString Blob method.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

Tim BarsottiTim Barsotti

Thanks Sam. This is close to what I need. However, it strips out all of the standard formatting (headers / stylesheets) that is rendered on the page. Any idea on how to preserve the actual layout that is rendered in SFDC? 

 

 

 

 

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

I am not sure but I would recommend trying out some javascript DOM elements/methods to see if you can capture complete html of the page and pass it to the salesforce controller upon some event(button click etc).

 

Checkout something around innerhtml and outerhtml...