Export Native Google Docs Documents with the Google Drive SDK

Google Drive SDK launched around three months back until now allowed applications to manage files that users have uploaded to Drive and to integrate deeply in the Google Drive UI. Staring today, the SDK now "allow developers to export native Google documents (such as Google Spreadsheets, Presentations, Documents, and Drawings) through the Google Drive API," […]

Google Drive SDK launched around three months back until now allowed applications to manage files that users have uploaded to Drive and to integrate deeply in the Google Drive UI. Staring today, the SDK now "allow developers to export native Google documents (such as Google Spreadsheets, Presentations, Documents, and Drawings) through the Google Drive API," informs Google.

In additon, all native Google documents can now be opened directly from within the Google Drive UI using third-party applications.

"For all Drive-installable applications, you can enable this feature by checking the Allow users to open files that can be converted to a format that this app can open option in the Google APIs Console under Drive SDK > Import. Once the feature is enabled, the application will show up under the "Open with" menu in the Google Drive Web UI for the file formats you support," Google explains.

Enabling import feature for native Google Docs types in Google Drive SDK

How it works? Google explaining says, "If your application supports opening one of the possible export formats for the Google document, users will be able to open that Google document with your application." So for instance, "if your application is configured to open PDF files, then because Google Documents are exportable to PDF, users will be able to use your application to open those documents as shown in the picture below.

opening google documents within google drive sdk

When opening "a native Google Document with your application from the Drive UI, we will pass the following JSON Object in the state URL parameter of the OAuth 2.0 redirect request that is forwarding the user to your website. Then you can use the file ID contained in the JSON object to query the Drive API and fetch the file's metadata. These URLs - one for each supported export format - are listed under the attribute exportLinks. You can query any of these export URLs using an authorized request to download the Google document in your prefered export format," Google explained.

Check out the Google Drive SDK documentation to learn more.

Below is a full list of supported export formats along with their associated MIME types:

Google Documents:

  • Text File (TXT) - text/plain
  • Portable Document Format (PDF) - application/pdf
  • OpenDocument Text Document (ODT) - application/vnd.oasis.opendocument.text
  • Microsoft Word (DOC) - application/msword
  • Hypertext Markup Language (HTML) - text/html
  • Rich Text Format File (RTF) - application/rtf

Google Spreadsheets:

  • Portable Document Format (PDF) - application/pdf
  • Microsoft Excel Spreadsheet (XLS) - application/vnd.ms-excel
  • OpenDocument Spreadsheet (ODS) - application/x-vnd.oasis.opendocument.spreadsheet

Google Presentations:

  • Text File (TXT) - text/plain
  • Portable Document Format (PDF) - application/pdf
  • Microsoft Office Open XML Format Presentation (PPTX) - application/vnd.openxmlformats-officedocument.presentationml.presentation

Google Drawings:

  • Scalable Vector Graphics (SVG) - image/svg+xml
  • JPEG Images (JPEG) - image/jpeg
  • Portable Network Graphics (PNG) - image/png
  • Portable Document Format (PDF) - application/pdf