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
AbAb 

converting a web page to a Pdf

Hello,

I want to realize below use case in Apex code

1) go to below url www.wxyztest.com/abcd
2) convert that webpage to Pdf
3) Attach that Pdf to a Quote

I am more interested in the forst two parts.

thanks for suggestion !
Best Answer chosen by Ab
Arun_KharbArun_Kharb
For that you have to use some third party tool through which you can get pdf generated of a URL.
Have a look on this :
http://salesforce.stackexchange.com/questions/46217/how-to-render-as-pdf-when-loading-the-existing-website-into-the-vf-page
 

All Answers

Arun_KharbArun_Kharb
Hi Sandrine,
Here is your answer.
First create one VF page with like this with following attribute
renderAs="pdf"
FYR - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_renderas_pdf.htm

In that VF page use an IFRAME where source would be - "www.wxyztest.com/abcd"
Now the APEX part.
Create one method like this.
@future(callout=true)
public static void generatePDFFuture(Id RecordId){
    	Attachment pdfattachment = new Attachment();
        pdfattachment.Name = system.now() + '.pdf'; //put your attachment name 
        PageReference pdfPage = new PageReference( '/apex/YOUR_PAGE_NAME'); 
        pdfattachment.Body = pdfPage.getContentAsPDF(); 
        pdfattachment.ContentType = 'application/pdf';
        pdfattachment.parentId = RecordId; //(Put your Parent Object ID here)
        insert pdfattachment;
    }
This would add the attachment to your Object.


If that works for you then do mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help. :)
AbAb
I want to access a public webpage for example www.google.com and convert it to Pdf
Arun_KharbArun_Kharb
For that you have to use some third party tool through which you can get pdf generated of a URL.
Have a look on this :
http://salesforce.stackexchange.com/questions/46217/how-to-render-as-pdf-when-loading-the-existing-website-into-the-vf-page
 
This was selected as the best answer