1

I would like to generate a multi-page PDF using Salesforce \ Visualforce, so that I can print multiple records at once.

Each PDF page comes from a ContentVersion record.

I know I can generate a PDF using a visualforce page with the renderAs="pdf" attribute.

And I know I can control the page size using:

<style>
    @page {
          margin: 0;
          padding: 0;
          size: 6in 4in;
    }
</style>

But the challenge is generating each individual page, as they need to print in a batch, but each record should appear on a new page.

I thought I might be able to do something like:

<apex:repeat ... >
    <apex:include pageName="page1?contentVersionId=xxxxxxxx" />
</apex:repeat>

So I could loop over the ContentVersion records passing the ContentVersion.ID into the <apex:include but it doesn't seem to be possible to pass parameters into the <apex:include

Questions

  1. How can I generate a PDF with multiple pages where each page is a ContentVersion record?

1 Answer 1

1

Do you already have it generating with everything you need, but without the page-breaks? If so, then your problem is just one of how to do page-breaks in the fairly limited CSS that Visualforce's PDF renderer supports.

There's a good reference for print formatting in PDF here: https://www.antennahouse.com/CSSInfo/CSS-Page-Tutorial-en.pdf

Using something like that, you could write:

<apex:repeat... >
  <div style="page-break-after: always;">
    <!-- whatever to output the ContentVersion -->
  </div>
</apex:repeat>

Additional

Following discussion in the comments, the root of the problem is not page-breaks in a PDFS. It is joining together separate PDFs. That is not possible directly on the platform, so the solution is to make a callout to some compute-platform and go from there. If you know Apex, then you can probably at least get by in Java, so the Java version of http://www.pdfsharp.com/PDFsharp/ is a decent start.

Once you start to think about it, merging PDFs has lots of intricacies... What if the page sizes are different? What about margins? Table-of-contents? Footnotes? etc. So even with the library to help, it can still be moderately hairy.

Nonetheless, I've managed to do this on AWS Lambda. I guess you could do it on Google or Heroku, depending on what environment you're most used to.

3
  • Thanks Aidan, I was aware of this, my question relates more to how to get multiple ContentVerison to render as one PDF (with multiple pages).
    – Robs
    Jul 16, 2019 at 16:07
  • 1
    Are you saying each ContentVersion contains a PDF itself? If so, you can't do it on-platform as far as I'm aware. When I had to do that, I wrote a function on AWS Lambda (using pdfsharp.com/PDFsharp), and called out to that from SF. If the ContentVersions are things that can be rendered in normal pages, then it should be quite simple
    – Aidan
    Jul 16, 2019 at 16:27
  • Yes, each ContentVersion is an independent PDF and I want to join them together so I can print on mass
    – Robs
    Jul 16, 2019 at 16:41

You must log in to answer this question.

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