<apex:page standardController="Account" recordSetVar="Acct" renderAs="PDF" applyBodyTag="false">
<apex:pageBlock>
<table>
<apex:repeat value="{!Acct}" var="acc">
<tr>
<td><apex:outputText value="{!acc.Name}"/></td>
<apex:repeat value="{!acc.Contacts}" var="cont">
<td><apex:outputText value="{!cont.Name}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</apex:pageBlock>
</apex:page>
Hi Christen,Please use the code below to fetchonly related contacts when you click on the custom link of account record. VF page code :
<apex:page standardController="Account" extensions="CurrentRecordIdDemoController" renderAs="Pdf">
<apex:form >
<apex:pageBlock title="Related Contacts ">
<apex:pageblockTable value="{!Contacts}" var="a" cellPadding="4" border="1">
<apex:column >
<apex:facet name="header">Contact ID</apex:facet>
{!a.id}
</apex:column>
<apex:column >
<apex:facet name="header"> First Name</apex:facet>
{!a.firstname}
</apex:column>
<apex:column >
<apex:facet name="header">Last Name</apex:facet>
{!a.Lastname}
</apex:column>
<apex:column >
<apex:facet name="header">Account Name</apex:facet>
{!a.Account.name}
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class for "CurrentRecordIdDemoController"
Create a custom link on detail page and add your VF page.Hope this helps! Please mark as solved if it does.Thankspublic class CurrentRecordIdDemoController{
public String currentRecordId {get;set;}
public Account acc{get;set;}
public list<Contact> Contacts{get;set;}
public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
acc = [select id ,name, AccountNumber, Type, Industry from Account where id =: currentRecordId ];
Contacts=[select id, firstname,lastname,Account.name from Contact where Accountid=: currentRecordId ];
}
}