You can do just about anything you can dream up using apex code and inline SOQL to write a custom controller or controller extension that can aggregate data from all sorts of places.
As far as your original question of merging 2 documents into one PDF this can also be accomplished with a fairly simple custom controller that then delegates to 2 calls to PageReference.getContent() and then exposes the results as 2 properties that you can then bind your renderAs="pdf" page to using a couple of 's in.
I would still recommend the first approach of using a custom controller to aggregate the data you need and then bind your pdf gen page to that...
I'm actually in this boat. I have 2 controllers - 1 that generates the actual page and the 2nd that's compiling the data together. I've used the getcontent() method to generate the blobs - but I haven't been able to figure out the correct syntax to "merge" these into a single blob.
map<string,string> MapID = new Map<string, string>{};
MapId.put('Primary', 'a00R000000288XHIAY');
MapId.put('0', 'a00R000000288XGIAY');
map<string,string> MapID2 = new Map<string, string>{};
MapId2.put('Primary', 'a00R000000288XPIAY');
MapId2.put('0', 'a00R000000288XQIAY');
// Retrieve the PDF as a Blob from the Visualforce page
PageReference s7statusreport = Page.s7statusreport;
s7statusreport.getParameters().putall(MapID);
Blob pdf1 = s7statusreport.getContent() ;
PageReference s7statusreport2 = Page.s7statusreport;
s7statusreport2.getParameters().putall(MapID2);
Blob pdf2 = s7statusreport2.getContent();
As a test I've created a map of IDs to simulate what the end controller will eventually do. I've confirmed with a PageReference that the page does actually render in PDF with the attributes attached.
So here are two page references with two different sets of data. I have 2 blobs - pdf1 and pdf2. How do I combine them?
You can't slam 2 PDF documents together like that in apex or in any language - PDF is a very specific kind of binary format that does not lend itself to simple concatenation like this. You can, however, use calls to getContent() on pages that produce HTML or some other text based content (e.g. the source pages should not have be renderAs="pdf") and then use a separate page (this one does have renderAs="pdf") that aggregates the text/HTML content via htmlBlob1.toString() + htmlBlob2.toString()...
I would describe this approach as "Merge n HTML pages into another page that is used to perform the HTML-to-PDF conversion"...
You can use a commercial product called PDF Merger. This tool let you convert multiple pdf file into one single file. You can easily merge as many as the pdf file into just one single file.
I’m running a free program - PDF Merge Tool It works perfectly most of time except for some minor bugs. Visit this site https://www.softwarewiki.org/merge-pdf/
Merge the PDF files with the help PDF merge tool (https://bit.ly/369RVR9), the tool is specially designed for this purpose and merge the PDF files in a fraction of a second. The tool can merge the PDF files in bulk thus, save your time and effort, and it does not require Adobe Acrobat to merge the PDF. The tool is highly compatible and is supported by all PDF makers and by all versions of windows.
With File ZIPO its possible to Merge Multiple Files & Documents into a PDF File which you can even download on desktop. Here's the link - https://appexchange.salesforce.com/appxListingDetail?listingId=a0N4V00000G5xfiUAB
I have the same problem. I tried it with getContent as blob, convert to string, add new content and convert to blob again
blob tempblob = pdf.getContent(); String blobcontent =tempblob.toString(); addedblobcontent += blobcontent; } // Create attachment Blob b = Blob.valueof(addedblobcontent); Attachment a = new Attachment(parentId =ObjectID, name='mypdf',body=b);
In this cae, my VF is renderas= PDF. I'm only getting an empty PDF.
One step closer:
I can convert a blob to a base64encoded string and decode again to blob. But I can't add this string to one PDF
PageReference pdf = new Pagereference(MyPDFPage + ID); // Create PDF tempblob = pdf.getContent(); system.debug('############################# Tempblob'+tempblob); blobcontent += EncodingUtil.base64Encode(tempblob); system.debug('############################# blobcontent'+blobcontent); // Create attachment Blob b = EncodingUtil.base64Decode(blobcontent); system.debug('############################# b'+b); Attachment a = new Attachment(parentId =ID, Name='MyPDF',body=b);
You can do just about anything you can dream up using apex code and inline SOQL to write a custom controller or controller extension that can aggregate data from all sorts of places.
As far as your original question of merging 2 documents into one PDF this can also be accomplished with a fairly simple custom controller that then delegates to 2 calls to PageReference.getContent() and then exposes the results as 2 properties that you can then bind your renderAs="pdf" page to using a couple of 's in.
I would still recommend the first approach of using a custom controller to aggregate the data you need and then bind your pdf gen page to that...
dchasman,
I'm actually in this boat. I have 2 controllers - 1 that generates the actual page and the 2nd that's compiling the data together. I've used the getcontent() method to generate the blobs - but I haven't been able to figure out the correct syntax to "merge" these into a single blob.
map<string,string> MapID = new Map<string, string>{}; MapId.put('Primary', 'a00R000000288XHIAY'); MapId.put('0', 'a00R000000288XGIAY'); map<string,string> MapID2 = new Map<string, string>{}; MapId2.put('Primary', 'a00R000000288XPIAY'); MapId2.put('0', 'a00R000000288XQIAY'); // Retrieve the PDF as a Blob from the Visualforce page PageReference s7statusreport = Page.s7statusreport; s7statusreport.getParameters().putall(MapID); Blob pdf1 = s7statusreport.getContent() ; PageReference s7statusreport2 = Page.s7statusreport; s7statusreport2.getParameters().putall(MapID2); Blob pdf2 = s7statusreport2.getContent();
As a test I've created a map of IDs to simulate what the end controller will eventually do. I've confirmed with a PageReference that the page does actually render in PDF with the attributes attached.
So here are two page references with two different sets of data. I have 2 blobs - pdf1 and pdf2. How do I combine them?
I've tried blob pdf3 = Page.S7statusReport.getcontent() + pageS7StatusReport2.getcontent();
That returns an error that arithmetic expression must use numeric arguments. I've tried change it to && and &
I've also tried setting these to PD1 and PD2 and then setting it to a blob with same results.
Is there a way I can do this?
Each time I call my s7StatusReport page generates a new "report." I'm trying to have multiple reports listed in a single pdf document.
You can't slam 2 PDF documents together like that in apex or in any language - PDF is a very specific kind of binary format that does not lend itself to simple concatenation like this. You can, however, use calls to getContent() on pages that produce HTML or some other text based content (e.g. the source pages should not have be renderAs="pdf") and then use a separate page (this one does have renderAs="pdf") that aggregates the text/HTML content via htmlBlob1.toString() + htmlBlob2.toString()...
I would describe this approach as "Merge n HTML pages into another page that is used to perform the HTML-to-PDF conversion"...
Thanks to all for the information,
Kind regards
Here's a link to a developer webinar which discuses how to do it along with code examples:
Cloud based PDF merge solution for Force.com
Have you resolved the issue? I have the same requirement. Can i get support from your side ?
Have you resolved the issue? I have the same requirement. Can i get support from your side ?
Here's the link - https://appexchange.salesforce.com/appxListingDetail?listingId=a0N4V00000G5xfiUAB