Today’s blog post shows how easy it is to merge two or more PDF files to create a single PDF file on Salesforce.
We use our own PDF merging solution which is hosted at pdfmerge.zenkraft.com, if you want to utilize this service please contact us.
Lets look at the simple code snippet below that will merge two PDF files together:
Lines 2-5: details the location of the two PDF files we need to merge.
Lines 8-13: sets up the HTTP Request with the endpoint and the headers. You will notice that line 13 is where your authorization code will be added. You will need to contact us to get this.
Line 16-21: Here we are converting the first PDF file into Hex in preparation to send to the web service.
Line 24-34: This converts the second PDF file into Hex.
Line 41: We make the request to the PDF Merge service.
Line 44-53: The final part of the code snippet is retrieving the newly merged PDF file and saving it back to the Parent object.
In our tests on salesforce the whole process can take between 0.5 and 2 seconds, but these times depend on the current workload of your salesforce instance, and the size of the PDF files you are trying to merge.
Let us know if you have any questions by contacting us, we are happy to help.
Comments currently disabled