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
Laytro80Laytro80 

Can you batch produce PDFs

Hi,

 

Have a visualforce page rendered as a PDF.

 

I now want to batch produce if possible PDF's.

 

Is this possible?

 

Thanks

 

Ross

Best Answer chosen by Admin (Salesforce Developers) 
Jeremy.NottinghJeremy.Nottingh

Here's a stripped-down view of my batch Invoice page.

<apex:page title="Billing Invoices"
	controller="Invcon"
    showheader="false" contentType="application/pdf" renderas="pdf"
    cache="true">
    
<style>
@page{
	margin-top: 60px;    
	margin-left: 10px;    
	margin-right: .5in;    
	margin-bottom: .75in;
}

</style>

<apex:repeat value="{!invdisplaylist}" var="xdoc"> 
	
<!-- all the invoice display code in here -->	

	<div class="footer" style="{!xdoc.endpage}" />
<!-- that footer div will have the pagebreak value unless this is the last Invoice in the list. 
     This avoids having a blank page at the end.
-->
	
</apex:repeat>
</apex:page>

 

 

The page itself is pretty big, but you've done all that design already. the difference for me was that I had to put my Invoice object into a wrapper class (xdoc) to handle the last-page issue. If it's not the last page, xdoc.endpage is a string: 'page-break-after: always;' otherwise it's null.

 

Good luck!

 

Jeremy

 

All Answers

AnahidAnahid

Hi,

 

I can generate a PDF file as an attachment in a visual force template with the next instruction:

 

<messaging:attachment renderas="pdf" filename="Name's file">

 

I hoppe that this answer help you

 

 

 

 

Jeremy.NottinghJeremy.Nottingh

Depending on what you mean by a "batch" of PDFs. I have an Invoice application that creates one large PDF made up of 25 one-page invoices for printing out. This is done through apex:repeat iterating over a dataset. 

 

If you actually want to have several PDF files all created at once, I'm not sure what that would look like. Can you be more specific?

 

Jeremy

Laytro80Laytro80

Hi,

 

Thanks for the post.

 

So right now I have a custom object called Link.  When viewing a link record you can hit the generate PDF button and create a nicely formatted one page statement based on the data contained within the record.

 

Each Link record is related to a contact.  A contact can have a few link records or a lot say 200 (although it's typically less than 50).

 

The idea would be to have a button on the contact object that would PDF all of the related Link records.  Would prefer one file.

 

Any tips or advice would be welcome.

 

Thanks again

 

Ross

 

 

Jeremy.NottinghJeremy.Nottingh

Here's a stripped-down view of my batch Invoice page.

<apex:page title="Billing Invoices"
	controller="Invcon"
    showheader="false" contentType="application/pdf" renderas="pdf"
    cache="true">
    
<style>
@page{
	margin-top: 60px;    
	margin-left: 10px;    
	margin-right: .5in;    
	margin-bottom: .75in;
}

</style>

<apex:repeat value="{!invdisplaylist}" var="xdoc"> 
	
<!-- all the invoice display code in here -->	

	<div class="footer" style="{!xdoc.endpage}" />
<!-- that footer div will have the pagebreak value unless this is the last Invoice in the list. 
     This avoids having a blank page at the end.
-->
	
</apex:repeat>
</apex:page>

 

 

The page itself is pretty big, but you've done all that design already. the difference for me was that I had to put my Invoice object into a wrapper class (xdoc) to handle the last-page issue. If it's not the last page, xdoc.endpage is a string: 'page-break-after: always;' otherwise it's null.

 

Good luck!

 

Jeremy

 

This was selected as the best answer
Laytro80Laytro80

Thanks for the code.

 

I am very new to APEX and VF but I can follow this.

 

I will have a go first thing tomorrow and let you know how I get on.

 

Thanks again

 

R

Laytro80Laytro80

Thanks for this Jeremy, and sorry for the delay.

 

Client kept changing there mind up until the end of last week.

 

I have been able to use the APEX repeat statement with great affect.

 

Thanks for the pointer.

 

Cheers

 

Ross