3

I have a visualforce page with an apex:detail tag which displays the standard detail section of an object. I have also added a new section within the standard details section layout to display google maps with multiple markers.

<apex:page standardController="Custom_Object__c">
    <apex:detail relatedList="true" inlineedit="TRUE" />
    <!-- map markup -->
</apex:page>

I tried rendering the vf page as pdf but it doesn't include the google maps, so i need to know whether there is any possibility to capture the vf page as image on button click and then place the image in pdf. The button will be placed using the 'Detail Page Button or Link" and on clicking this button i need to get the visualforce page content as image.

2
  • Just found this post on stackoverflow. It might be of some help. You can try to create screenshots using JavaScript as suggested by the post.
    – Eduard
    Sep 21, 2017 at 11:21
  • From your description, it doesn't sound to me like you need to involve a custom button here at all. If you're on your target page, click anywhere on your page (to make sure that your browser is your active window), and press alt + prtscn (print screen) if you're on Windows to capture a screenshot of the active window (and only the active window). ctrl+v in paint, and you should be able to take it from there. That only captures the image displayed on your screen (doesn't capture things that have been scrolled off the screen), but partial screen captures should be fine for most uses.
    – Derek F
    Sep 21, 2017 at 13:14

1 Answer 1

2

You seem to be having an X-Y Problem. You do not need to go such a complicated route. Instead, just use the Google Static Maps API. The reason your current approach fails is that you cannot use Javascript when rendering PDF. The reason this API will work instead is that it does not use any Javascript to do its rendering.

I have successfully generated maps for use in PDF renderings using this API. You just formulate the proper endpoint and include it as an img src:

<img src="https://maps.googleapis.com/maps/api/staticmap?parameters=values" />

You will need to actually pay for your own API key if this application is for commercial use.

6
  • I tried the step you suggested but the problem is, I am using another visualforce section within the <apex:detail> by directly adding them to the layout. So when i render the above mentioned page as pdf the static image doesn't show in the pdf since it is within another vf page. Is there a solution to it?
    – Ean
    Sep 21, 2017 at 13:32
  • I can show the static image below the detail section but is it possible to show the static image within the detail section while rendering as pdf?
    – Ean
    Sep 21, 2017 at 13:33
  • 1
    I think rendering an entire detail page complicates things unnecessarily. I would try to render just what is needed.
    – Adrian Larson
    Sep 21, 2017 at 13:54
  • I do understand that rendering an entire detail page complicates things and i don't want to do it. I want to render the detail section using apex detail tag but somehow include the apex map as image within it while converting as pdf. (i.e.) more like taking a screenshot of the detail page along with the map.
    – Ean
    Sep 22, 2017 at 8:13
  • 1
    What I'm saying is, maybe you could just loop over a FieldSet to display what fields you want, and then include the image below. Or you could just include this image below your current detail page and call it good enough. Not sure what other options you have.
    – Adrian Larson
    Sep 22, 2017 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .