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
Jannu SairamJannu Sairam 

how to get list of records in tabular format in pdf by using vf page

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Jannu,

Can you try code similar to this.
 
<apex:page controller="AccountControllerfortable" docType="html-5.0" renderAs="{!render}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:input label="Start Date" value="{!startdate}" type="date" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!search}" value="Search" />
                  <apex:commandButton value="download pdf" action="{!Downloadhere}"/>
            </apex:pageBlockButtons>
                    <apex:dataTable value="{!accounts}" var="c" style="border: 1px solid black;">
            <apex:column value="{!c.id}" style="padding: 15px;order-bottom: 1px solid #ddd;border: 1px solid black;" />
             <apex:column value="{!c.name}" style="padding: 15px;order-bottom: 1px solid #ddd;border: 1px solid black;"/>
        </apex:dataTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex:
public class AccountControllerfortable {
    public Date startDate { get; set; }
    public string render {get; set;}
    public Date endDate { get; set; }
    public List<Account> accounts { get; set; }
    public void Downloadhere(){
        render='pdf';
    }
    
    public void search() {
       
        accounts = [SELECT Id, Name, CreatedDate 
                    FROM Account 
                    WHERE CreatedDate >= :startDate ];
       
}
}

Reference: https://dfc-org-production.my.site.com/forums/ForumsMain?id=9062I000000R791QAC
Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,