Unlock Custom PDF Exports from Google Sheets with URL Parameters

Generating a PDF from a Google Sheet is easy using the standard File > Download > PDF menu. But what if you need to export the same specific range or a customized view frequently? Doing it manually over and over can be tedious.

 

Luckily, Google Workspace often hides powerful features within document URLs. For Google Sheets, you can construct a special URL to export precisely what you need, exactly how you want it, directly to a PDF file. This is perfect for generating reports, sharing specific data snippets, or automating workflows.

The Magic: The /export URL

The core trick lies in modifying the standard Google Sheet URL. Instead of /edit, you use /export and add parameters after a question mark (?) to define the output.

The basic structure looks like this:

1https://docs.google.com/spreadsheets/d/DOCUMENT_ID/export?format=pdf&...[other parameters]

 

Finding Your IDs

You'll need two key IDs from your spreadsheet's regular URL:

  1. DOCUMENT_ID: This is the long string of characters found in the middle of your sheet's URL:
1https://docs.google.com/spreadsheets/d/THIS_IS_THE_DOCUMENT_ID/edit#gid=0
  1. gid (Sheet ID): This identifies the specific sheet (tab) you want to export. When you click on a sheet, its gid appears at the end of the URL:
1https://docs.google.com/spreadsheets/d/DOCUMENT_ID/edit#gid=THIS_IS_THE_SHEET_ID

 

Exporting a Specific Range (The Tricky Part!)

This is where the real power comes in, but also where you need to be precise. You use four parameters: r1, c1, r2, c2.

  • Indexing: Google Sheets uses 0-based indexing for these parameters. This means:
    • Row 1 is index 0, Row 7 is index 6.
    • Column A is index 0, Column B is index 1, Column G is index 6.
  • Range Definition:
    • r1: The 0-based index of the first row you want to include.
    • c1: The 0-based index of the first column you want to include.
    • r2: The 0-based index of the row AFTER the last row you want to include (it's an exclusive end).
    • c2: The 0-based index of the column AFTER the last column you want to include (also exclusive).

Example: Let's say you want to export the range B7:G18:

  • First cell B7: Row 7 is index 6 (r1=6), Column B is index 1 (c1=1).
  • Last cell G18: Row 18 is index 17. The row after is index 18 (r2=18). Column G is index 6. The column after is index 7 (c2=7). So, the range parameters for B7:G18 would be: &r1=6&c1=1&r2=18&c2=7

 

Customizing Your PDF Output

Beyond selecting the range, you can control the PDF's appearance using various parameters. Here are some common ones:

  • format=pdf: Specifies the export format as PDF.
  • size=6: Sets the paper size. Common values:
    • 0: US Letter
    • 6: A4 (Used in the example below)
    • 7: A5
    • 5: A3
  • portrait=true: true for Portrait orientation, false for Landscape.
  • fitw=true: "Fit to Width" - Scales content down to fit the page width if needed.
  • gridlines=false: true to show gridlines, false to hide them.
  • printtitle=false: true to include the spreadsheet's filename as a title, false to omit it.
  • sheetnames=false: true to include the sheet (tab) name, false to omit it.
  • pagenum=UNDEFINED: Controls page numbering. UNDEFINED hides page numbers. Other options like CENTER, LEFT, RIGHT can place numbers (often in the footer).
  • fzr=true: "Freeze Rows" - true repeats any frozen rows at the top of each PDF page.
  • top_margin=0.5, bottom_margin=0.25, left_margin=0.5, right_margin=0.5: Sets page margins in inches.
  • attachment=true: true tells the browser to treat the output as a file download. false might try to display the PDF inline in the browser.

 

Putting It All Together: Full URL Example

To export the range B7:G18 from the sheet with gid=YOUR_SHEET_ID in the document YOUR_DOCUMENT_ID as an A4 PDF, fitting to width, hiding gridlines/titles, and forcing download, the URL would look like this:

1https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_ID/export?format=pdf&size=6&portrait=true&fitw=true&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&fzr=true&attachment=true&gid=YOUR_SHEET_ID&r1=6&c1=1&r2=18&c2=7&top_margin=0.5&bottom_margin=0.25&left_margin=0.5&right_margin=0.5

(Remember to replace YOUR_DOCUMENT_ID and YOUR_SHEET_ID with your actual IDs!)

 

How Can You Use This?

  • Bookmarks: Create bookmarks in your browser for frequently needed exports.
  • Hyperlinks: Use the HYPERLINK() function inside another Google Sheet to build dynamic export links based on cell values.
  • Scripts & Apps: Integrate these URLs into Google Apps Script, web applications, or other tools to automate PDF generation.

This URL method offers a fantastic way to streamline repetitive PDF exports from Google Sheets, giving you precise control over the output. Give it a try!