Google Sheets to PDF: URL Query Parameters Explained
Anupam Samanta
-
2/21/2025
Table of Contents
Google Sheets provides a flexible way to export your spreadsheets as PDFs by appending URL query parameters. These parameters let you control everything from the export format to page layout, margins, gridlines, and even specific cell ranges. In this guide, we’ll explain every field in detail, including all possible values, so you can fully customize your PDF export.
Overview of the Export URL
The base URL for exporting a Google Sheet as a PDF looks like this: https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/export?PARAMETERS
- SPREADSHEET_ID: The unique identifier of your Google Sheet.
- PARAMETERS: A series of query parameters that control the PDF output.
Below is a detailed explanation of each available parameter.
Detailed Explanation of URL Parameters
-
Export Format
- Parameter:
&format=pdf - Description: Specifies the file format for the export.
- Possible Values: Only
pdfis supported for PDF export.
- Parameter:
-
Sheet ID
- Parameter:
&gid=1732160294 - Description: Identifies the specific sheet (tab) within your spreadsheet to export.
- Possible Values: Any valid sheet ID, which you can find in your URL when viewing the sheet.
- Parameter:
-
Paper Size
- Parameter:
&size=a4 - Description: Determines the paper size for the PDF.
- Possible Values:
A3A4A5B4B5lettertabloidlegalstatementexecutivefolio
- Parameter:
-
Page Orientation
- Parameter:
&portrait=false - Description: Sets the page orientation.
- Possible Values:
true– Portraitfalse– Landscape
- Parameter:
-
Scale
- Parameter:
&scale=1 - Description: Adjusts the scaling of the spreadsheet content in the PDF.
- Possible Values:
1– Normal (100%)2– Fit to width3– Fit to height4– Fit to page
- Parameter:
-
Margins
All four margins must be explicitly set (in inches):
-
&top_margin=0.00
Top margin. -
&bottom_margin=0.00
Bottom margin. -
&left_margin=0.00
Left margin. -
&right_margin=0.00
Right margin.
-
-
Gridlines
- Parameter:
&gridlines=false - Description: Controls whether gridlines are included in the PDF.
- Possible Values:
true– Show gridlinesfalse– Hide gridlines
- Parameter:
-
Print Notes
- Parameter:
&printnotes=false - Description: Determines if comments/notes are printed.
- Possible Values:
true– Include notesfalse– Exclude notes
- Parameter:
-
Print Title
- Parameter:
&printtitle=false - Description: Controls whether the title is printed on the PDF.
- Possible Values:
true– Show titlefalse– Hide title
- Parameter:
-
Sheet Names
- Parameter:
&sheetnames=false - Description: Decides if the sheet name should be printed on the PDF.
- Possible Values:
true– Show sheet namesfalse– Hide sheet names
- Parameter:
-
Page Order
- Parameter:
&pageorder=2 - Description: Sets the order in which pages are printed.
- Possible Values:
1– Down, then over2– Over, then down
- Parameter:
-
Horizontal Alignment
- Parameter:
&horizontal_alignment=CENTER - Description: Specifies how content is aligned horizontally on the page.
- Possible Values:
LEFTCENTERRIGHT
- Parameter:
-
Vertical Alignment
- Parameter:
&vertical_alignment=TOP - Description: Specifies how content is aligned vertically on the page.
- Possible Values:
TOPMIDDLEBOTTOM
- Parameter:
-
Page Numbering
- Parameter:
&pagenum=UNDEFINED - Description: Controls the appearance of page numbers on the PDF.
- Possible Values:
CENTER– Page numbers centeredUNDEFINED– No page numbers displayed
- Parameter:
-
Frozen Rows and Columns
- Frozen Rows:
&fzr=false- Description: Determines whether frozen rows are printed.
- Possible Values:
trueorfalse
- Frozen Columns:
&fzc=false- Description: Determines whether frozen columns are printed.
- Possible Values:
trueorfalse
- Frozen Rows:
-
Attachment
- Parameter:
&attachment=false - Description: Controls file delivery.
- Possible Values:
true– Forces the file to be downloaded.false– Opens the file in the browser.
- Parameter:
-
Print Range (Row & Column Selection)
- Starting Row:
&r1=0- Description: Specifies the starting row (zero-indexed; row 1 is 0, row 7 is 6).
- Starting Column:
&c1=0- Description: Specifies the starting column (zero-indexed).
- Ending Row:
&r2=5- Description: Specifies the ending row.
- Ending Column:
&c2=5- Description: Specifies the ending column.
- Starting Row:
JavaScript Example: Constructing the Export URL
Below is an example of how to construct the complete export URL in JavaScript, incorporating all the parameters:
const spreadsheetId = "id_of_your_spreadsheet";
const gid = "1732160294";
const size = "a4";
const portrait = "false";
const scale = "1";
const top_margin = "0.00";
const bottom_margin = "0.00";
const left_margin = "0.00";
const right_margin = "0.00";
const gridlines = "false";
const printnotes = "false";
const printtitle = "false";
const sheetnames = "false";
const pageorder = "2";
const horizontal_alignment = "CENTER";
const vertical_alignment = "TOP";
const pagenum = "UNDEFINED";
const fzr = "false";
const fzc = "false";
const attachment = "false";
const r1 = "0";
const c1 = "0";
const r2 = "5";
const c2 = "5";
const url =
`https://docs.google.com/spreadsheets/d/${spreadsheetId}/export?format=pdf` +
`&gid=${gid}` +
`&size=${size}` +
`&portrait=${portrait}` +
`&scale=${scale}` +
`&top_margin=${top_margin}` +
`&bottom_margin=${bottom_margin}` +
`&left_margin=${left_margin}` +
`&right_margin=${right_margin}` +
`&gridlines=${gridlines}` +
`&printnotes=${printnotes}` +
`&printtitle=${printtitle}` +
`&sheetnames=${sheetnames}` +
`&pageorder=${pageorder}` +
`&horizontal_alignment=${horizontal_alignment}` +
`&vertical_alignment=${vertical_alignment}` +
`&pagenum=${pagenum}` +
`&fzr=${fzr}` +
`&fzc=${fzc}` +
`&attachment=${attachment}` +
`&r1=${r1}` +
`&c1=${c1}` +
`&r2=${r2}` +
`&c2=${c2}`;
console.log(url);
This code dynamically builds a URL for exporting a Google Sheet as a PDF with all the customizations specified by the parameters.
Conclusion
Using URL query parameters for Google Sheets PDF export gives you full control over the final output. Whether you need to adjust the paper size, margins, orientation, or print a specific range, these parameters let you tailor the PDF to your exact needs. With the detailed explanations and JavaScript example provided, you should now be equipped to create and modify export URLs for your Google Sheets, making automated report generation and document sharing a breeze.