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
geniousxugeniousxu 

generate mutiple pages in one PDF file

Hello, I am an amateur about the PDF generation.

What I am doing now is that I want to render a page into PDF file and save it in database when I click a botton.

Source like this:

 

// botton action
public void pdfOutPut() { document dc = new document(); String pdfPageURL = '/apex/PdfOutputLayout?id=' + pageId; PageReference pageRef = new PageReference(pdfPageURL); dc.body = pageRef.getContent(); dc.name = 'pdftest' + System.DateTime.now() + '.pdf'; dc.folderid = folderId; insert dc; }

 

Now the problem is when I want to render mutiple pages into one PDF, how can I do?

My consideration likes this:

 

public void pdfOutPut() {
    document dc = new document();
    for(int i = 0; i < list.size(); i++){
String pdfPageURL = '/apex/PdfOutputLayout?id=' + pageId; PageReference pageRef = new PageReference(pdfPageURL); dc.body += pageRef.getContent(); }
dc.name = 'pdftest' + System.DateTime.now() + '.pdf'; dc.folderid = folderId; insert dc; }

I use "pageRef.getContent()" to get the PDF's binary data so I guess I could add each PDF's binary data into one. But there is error seems like "+=" is not supported.

 

 

Does anyone could help me?

Or maybe there is another way to achieve it?

 

Thank you.