I am trying to convert an HTML email that is sent to an Email Service into a PDF file. Some of the options I have explored:
attachment.fileName = fileName + '.pdf';
attachment.mimeTypeSubType = 'application/pdf';
attachment.body = Blob.toPdf(attachmentBody);
This works great with text and some css, but when I send a rich HTML email with images and lots of styling it fails and generates an error - System.InvalidParameterValueException: An error occurred while parsing the input string.
The second option, I tried to pass in the HTML from the email to a Visualforce page where it was rendered as a PDF and used as an attachment, but there are limitations in the Email Service that you can't use visualforce pages and the HTML markup from the email raised validation exceptions where HTML tags were not closed properly.
I know there are lots of paid HTMLtoPDF services out there on the web with APIs that you can call, but I'd like to explore any alternate Salesforce options before resorting to this or building my own HTMLtoPDF web app.
Cheers
