Smartsheet.Api.Internal.SheetResourcesImpl.GetSheetAsPDF C# (CSharp) Method

GetSheetAsPDF() public method

Get a sheet as a PDF file.

It mirrors To the following Smartsheet REST API method:
GET /sheets/{sheetId} with "application/pdf" Accept HTTP header

if any argument is null or empty string if there is any problem with the REST API request if there is any problem with the REST API authorization (access token) if the resource cannot be found if the REST API service is not available (possibly due To rate limiting) if there is any other error during the operation
public GetSheetAsPDF ( long sheetId, BinaryWriter outputStream, Api.Models.PaperSize paperSize ) : void
sheetId long the Id of the sheet
outputStream System.IO.BinaryWriter the output stream To which the PDF file will be written.
paperSize Api.Models.PaperSize the paper size
return void
        public virtual void GetSheetAsPDF(long sheetId, BinaryWriter outputStream, PaperSize? paperSize)
        {
            GetSheetAsFile(sheetId, paperSize, outputStream, "application/pdf");
        }

Usage Example

        public virtual void TestGetSheetAsPDF()
        {
            string file = "../../../TestSDK/resources/getPDF.pdf";

            server.setResponseBody(file);
            server.ContentType = "application/pdf";

            BinaryWriter output = new BinaryWriter(new MemoryStream());

            sheetResource.GetSheetAsPDF(1234L, output, null);

            Assert.NotNull(output, "Downloaded PDF is null.");
            Assert.True(output.BaseStream.Length > 0, "Downloaded PDF is empty.");
            Assert.AreEqual(107906, output.BaseStream.Length, "Downloaded PDF does not match the original size.");

            //test a larger PDF
            file = "../../../TestSDK/resources/large_sheet.pdf";
            server.setResponseBody(file);
            server.ContentType = "application/pdf";
            MemoryStream ms = new MemoryStream();

            output = new BinaryWriter(ms);
            sheetResource.GetSheetAsPDF(1234L, output, PaperSize.LEGAL);
            Assert.NotNull(output, "Downloaded PDF is null.");
            Assert.True(ms.ToArray().Length > 0, "Downloaded PDF is empty.");
            Assert.AreEqual(936995, ms.ToArray().Length, "Downloaded PDF does not match the original size.");
        }