I need to generate a document for any given account that lists a detailed view of their contacts, opportunities, activity etc. My first instinct is to simply use renderAs on a custom visualforce page that contains all the account info I need. However, I'm realizing that I would need to generate such a page for each opportunity connected to the account (and possibly each contact though I might get by with a related list there). Is there a way to generate a page for each item that would appear in a related list so we could see (for example) the description of an opportunity that would be too long for a related list column?

Secondarily, if they do end up being separate pages, how would you recommend turning them into a single document with as little effort on the part of the user as possible?

1 Answer 1


You'll probably want to use a combination of pages and components. Each top-level page uses renderAs to make the PDF files, but uses components so you can have the same look-and-feel across the various types. For example, you might declare three components: pdfAccount, pdfContact, and pdfOpportunity. Then, depending on the page, you'll simply render the pages as you like.


<apex:page standardController="Account" renderAs="PDF">
    <c:pdfAccount account="{!Account}" />
    <apex:repeat var="accountContact" value="{!Account.Contacts}">
        <c:pdfContact contact="{!accountContact}" />
    <!-- and opportunity code here... -->

As far as making it easy for the user: just create a Custom Button or Link, using the Visualforce pages you just created. The user clicks it, and the PDF will be generated for them to view or print.

Also, if each record should be its own page, just set up a div with the page-break-before attribute in each component:

    <div style="page-break-before: always"></div>
    <!-- rest of code here -->

You must log in to answer this question.

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