By Raj

Estimated reading time: 10 minutes

How to Auto Generate PDF from Google Sheets (Apps Script + Free Code)

If you're manually exporting PDFs from Google Sheets, you're wasting hours every week. More importantly, you're building a process that doesn't scale.

In this guide, you'll learn exactly how to auto generate PDF from Google Sheets using Google Apps Script, including a working script, real-world use cases, and how to automate the entire workflow (generation, storage, and email delivery).

This is the same system used by agencies and operations teams to generate invoices, reports, and documents automatically, without manual effort.

What Does "Auto-Generate PDF from Google Sheets" Actually Mean?

At its core, this process involves using a script to capture a specific range or sheet, convert that data into a Blob, and save it as a PDF file in Google Drive.

  • Dynamic Data Insertion
  • Triggered Execution
  • Automatic Email Delivery

Real-World Use Cases for PDF Automation

  • Automated Invoice Generation
  • Recurring Reports
  • Payroll Documents
  • Certificates

How the Automation Works

Trigger → Get Spreadsheet → Convert to PDF → Save to Drive → Send Email

Why Your PDF Automation May Not Work (Common Failures)

Many users fail to automate PDF generation due to incorrect setup.

  • OAuth permission issues
  • Wrong sheet ID
  • Formatting problems
  • Trigger misconfiguration

Step-by-Step Setup

Step 1: Prepare Template

Design your print-ready sheet.

Step 2: Open Apps Script

Go to Extensions → Apps Script.

Step 3: Add Script

function generatePDF() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName("Invoice_Template");
  const folderId = "YOUR_FOLDER_ID_HERE";
  const fileName = "Invoice_" + sheet.getRange("B5").getValue();

  const url = "https://docs.google.com/spreadsheets/d/" + ss.getId() + "/export" +
              "?format=pdf&gid=" + sheet.getSheetId();

  const params = {method:"GET",headers:{"Authorization":"Bearer " + ScriptApp.getOAuthToken()}};
  const response = UrlFetchApp.fetch(url, params);
  const blob = response.getBlob().setName(fileName + ".pdf");

  DriveApp.getFolderById(folderId).createFile(blob);
}

Email the PDF Automatically

function emailPDF(fileUrl, recipientEmail) {
  MailApp.sendEmail({
    to: recipientEmail,
    subject: "Your PDF Document",
    body: "Please find your PDF attached.",
    attachments: [UrlFetchApp.fetch(fileUrl).getBlob()]
  });
}

If you want a fully automated system, you can hire a Google Apps Script developer to build it for you.

Conclusion

Automating PDF generation from Google Sheets saves time, reduces errors, and scales your operations efficiently.

Frequently Asked Questions

How do I automatically create a PDF from Google Sheets?

Use Google Apps Script to export a sheet as a PDF and trigger it automatically.

Can Google Sheets send PDFs automatically?

Yes, using Apps Script and Gmail integration.

Is Google Apps Script free?

Yes, within usage limits.

How to automate invoices?

Use a template + script + trigger to generate and send PDFs automatically.

Get the full Apps Script script template

I'll email you a production-ready, commented version you can deploy in 10 minutes.