Save Gmail emails as PDFs automatically

Save Gmail emails as PDFs automatically

Gmail to PDF on autopilot. Save every email with a label, or from a sender, as a PDF in Google Drive with Apps Script or Zapier.

Quick answer. Pick which emails to keep, for example everything with the label "Receipts". A small script or a Zapier step takes each new email, html-pdf.com turns it into a PDF that looks like the original message, and the PDF is saved to a Google Drive folder.

What you'll build

You get a Drive folder that fills itself. Each matching email becomes one PDF with the sender, date, subject and the full message, including formatting and images.

People use this for expense receipts, supplier invoices sent in the email body, signed approvals, legal or HR records, and handing a client a clean copy of a conversation. Printing one email to PDF by hand works fine. This is for when you need it to happen every time.

What you need

Emails are already written as web pages behind the scenes, and html-pdf.com turns that web page into a PDF, so you don't need to design anything.

Option 1 with Apps Script (free, runs every 15 minutes)

  1. Go to script.google.com and create a new project.
  2. Paste the code below. Put your Drive folder ID in FOLDER_ID (it's the last part of the folder's URL).
  3. In Project Settings → Script properties, add HTML_PDF_KEY with your key.
  4. Run savePdfs once and approve the permissions.
  5. Open Triggers, click Add Trigger, choose savePdfs, Time-driven, every 15 minutes.
const FOLDER_ID = "your-folder-id";
const LABEL = "Save as PDF";
const DONE = "Saved as PDF";

function savePdfs() {
  const key = PropertiesService.getScriptProperties().getProperty("HTML_PDF_KEY");
  const done = GmailApp.getUserLabelByName(DONE) || GmailApp.createLabel(DONE);
  const folder = DriveApp.getFolderById(FOLDER_ID);
  const threads = GmailApp.search(`label:"${LABEL}" -label:"${DONE}"`, 0, 20);

  threads.forEach(thread => {
    thread.getMessages().forEach(m => {
      const header = `<div style="font:13px Arial;border-bottom:1px solid #ccc;margin-bottom:16px;padding-bottom:8px">
        <b>From:</b> ${m.getFrom()}<br><b>Date:</b> ${m.getDate()}<br><b>Subject:</b> ${m.getSubject()}</div>`;
      const res = UrlFetchApp.fetch("https://html-pdf.com/v1/pdf", {
        method: "post",
        contentType: "application/json",
        headers: { Authorization: "Bearer " + key },
        payload: JSON.stringify({ html: header + m.getBody(), margin: "15mm" }),
      });
      const name = `${Utilities.formatDate(m.getDate(), "UTC", "yyyy-MM-dd")} ${m.getSubject()}.pdf`;
      folder.createFile(res.getBlob().setName(name));
    });
    thread.addLabel(done);
  });
}

The script adds a "Saved as PDF" label after each thread, so nothing is saved twice. Attachments stay in Gmail. Save them separately with m.getAttachments() if you need them. See the Apps Script guide for more.

Option 2 with Zapier (no code)

  1. Create a Zap with Gmail and the event New Email Matching Search. Use a search like label:"Save as PDF" or from:billing@supplier.com.
  2. Add Webhooks by Zapier → Custom Request. Method POST, URL https://html-pdf.com/v1/pdf, headers Authorization (Bearer hp_live_...) and Content-Type (application/json).
  3. In Data, send the email's HTML body field from the Gmail step as html, with "response": "url".
  4. Add Google Drive → Upload File and map the returned url into File.
{
  "html": "<p>Map the Gmail body HTML field here</p>",
  "margin": "15mm",
  "filename": "email.pdf",
  "response": "url"
}

Email HTML often contains quotes, so building the JSON in a Code by Zapier step is more reliable than pasting the body directly. The Zapier guide has the full setup, and n8n users can use the Gmail Trigger and HTTP Request nodes from the n8n guide.

Ask your AI agent

If Claude or ChatGPT can read your email and has the html-pdf.com MCP server connected, you can ask for one off archives.

Find the emails from Acme Supplies about order 7781, put them in date order as one clean document with a short summary at the top, and use html-pdf to make it a PDF.

For setup, see the Claude guide and ChatGPT guide.

FAQ

Can I save Gmail emails as PDF without any tools?

Yes, one at a time. Open the email, click Print all and choose Save as PDF. Automation helps when you need many emails saved without clicking.

Do images in the email show up in the PDF?

Images hosted online usually appear, since the renderer loads them like a browser would. Images that need you to be signed in, or tracking pixels that are blocked, may not.

Does html-pdf.com keep my emails?

No. The HTML is not stored, and download links expire after 24 hours. The PDFs live only in your own Drive.

How much does it cost?

One credit per PDF page. Most emails are one or two pages. Packs start at $10 for 1,000 pages, and purchased credits never expire.

This page as markdown · text