Save Gmail Messages as PDF – Google Apps Script

The following Google Apps Script will convert a Gmail Message into a PDF file using the built-in PDF converter of Google Docs (now Google Drive).

The script reads the body of the Gmail threads, strips the inline images, saves the thread as an HTML file and then converts the HTML into a PDF. If there are any file attachments in the email thread, they are saved as well. The downloads links of the attachments are appended to the PDF as well.