What I want to do is export a Google sheet as a PDF without it displaying the gridlines. I see code samples online of how to access that parameter when using a url like this:
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
"?format=pdf&"+
"size=0&"+
"fzr=true&"+
"portrait=false&"+
"fitw=true&"+
"gridlines=false&"+
"printtitle=true&"+
"sheetnames=true&"+
"pagenum=CENTER&"+
"attachment=true";
But I am using the following code which does not utilitize a url:
private static void DownloadfileFromGDrive(DriveService service, string fileId, string filePath)
{
var request = service.Files.Export(fileId, "application/pdf");
using (var memoryStream = new MemoryStream())
{
request.MediaDownloader.ProgressChanged += (IDownloadProgress progress) =>
{
switch (progress.Status)
{
case DownloadStatus.Downloading:
Debug.WriteLine(progress.BytesDownloaded);
break;
case DownloadStatus.Completed:
Debug.WriteLine("Download Complete");
break;
case DownloadStatus.Failed:
Debug.WriteLine("Download Failed");
break;
}
};
request.Download(memoryStream);
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
fileStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length);
};
}
}
How can I access those parameters from my code?
How about this answer?
When the query parameter for exporting as the PDF format is used, unfortunately, service.Files.Export(fileId, "application/pdf") cannot be used for this situation. In this case, it is required to download the PDF file using the access token. The endpoint for this situation is as follows.
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
"?format=pdf&"+
"size=0&"+
"fzr=true&"+
"portrait=false&"+
"fitw=true&"+
"gridlines=false&"+
"printtitle=true&"+
"sheetnames=true&"+
"pagenum=CENTER&"+
"attachment=true&"+
"access_token=###"; // Added
If this was not the direction you want, I apologize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With