In today’s blog post we’re going to show you the codes needed to convert a GIF shipping label into a PDF document.
We’re going to use pages, classes, and controllers.
The first method we need to look at is regenerateGifToPdfLabel (line 2). The steps are as follows:
- Select all the attachments that have been generated and add them to the allLabels list (line 3-8)
- Create the new list gifLabels, which are the GIFs that will be converted to PDFs. (line 10-16)
- For all the items in the gifLabels list call the createPDFLabels method and insert the pdf record (line 19-20) and finally delete the GIF file that is no longer needed. (line 21)
The createPDFLabels (line 25) method in step 3 above calls the generatePDFLabel method (line 35).
Next create a new attachment object pdfLabel, which will be the PDF file (line 36). Line 38 is where we reference our VisualForce page, that will contain the original GIF file. The VisualForce page code can be found at the bottom of this post.
Line 41 sets the Body of the new attachment object as the blob that is returned from the standard SalesForce method getContentAsPDF();.
- Line 6-7 basically set the variable that will be used in the
- Line 25 is where the GIF shipping label is inserted, which is then rendered as a pdf from the code we have already looked at above.