Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2012 14:57
Show Gist options
  • Select an option

  • Save anonymous/4169590 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4169590 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Nov 29, 2012.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    function spreadsheetToPDF(key) {

    var oauthConfig = UrlFetchApp.addOAuthService("spreadsheets");
    var scope = "https://spreadsheets.google.com/feeds"

    oauthConfig.setConsumerKey("anonymous");
    oauthConfig.setConsumerSecret("anonymous");
    oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
    oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");
    oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");

    var requestData = {
    "oAuthServiceName": "spreadsheets",
    "oAuthUseToken": "always",
    };

    var name = DocsList.getFileById(key).getName()+".pdf";

    var pdf = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&exportFormat=pdf&gid=1&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1", requestData).getBlob().setName(name);

    return pdf;
    }