Spread allows you to save your worksheet/workbook in a PDF format by using the SaveAs method. The saved PDF displays a similar behavior as the exported PDF from Excel. Hence, making a consistency in printing and retaining the image quality.
To save a worksheet in PDF format, make sure you have the following settings:
The following code is used to save the worksheet to PDF.
C# |
Copy Code
|
---|---|
IWorksheet sheet = fpSpread1.AsWorkbook().ActiveSheet; // SaveAs method is used to save the worksheet in PDF format sheet.SaveAs("D:\\worksheet1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF); |
Visual Basic |
Copy Code
|
---|---|
Dim sheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet ' SaveAs method is used to save the worksheet in PDF format sheet.SaveAs("D:\worksheet1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF) |
The following code is used to save the workbook to PDF.
C# |
Copy Code
|
---|---|
IWorkbook book1= fpSpread1.AsWorkbook(); // SaveAs method is used to save the workbook in PDF format book1.SaveAs("D:\\workbook1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF); |
Visual Basic |
Copy Code
|
---|---|
Dim book1 As IWorkbook = FpSpread1.AsWorkbook() ' SaveAs method is used to save the workbook in PDF format book1.SaveAs("D:\workbook1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF) |
Saving the PDF using the SaveAs method has several additional benefits over PrintToPDF property. They are listed below:
The following code is used to save workbook with ISO standard support:
C# |
Copy Code
|
---|---|
GrapeCity.Spreadsheet.IO.Pdf.PdfExportContext pdfExportContext = new GrapeCity.Spreadsheet.IO.Pdf.PdfExportContext(); // Save the PDF in PDF/A-3U supported document pdfExportContext.ConformanceLevel = GrapeCity.Spreadsheet.IO.Pdf.PdfAConformanceLevel.PdfA3u; fpSpread1.AsWorkbook().SaveAs("D:\\ISObook1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF, null, pdfExportContext); |
Visual Basic |
Copy Code
|
---|---|
Dim pdfExportContext As GrapeCity.Spreadsheet.IO.Pdf.PdfExportContext = New GrapeCity.Spreadsheet.IO.Pdf.PdfExportContext() ' Save the PDF in PDF/A-3U supported document pdfExportContext.ConformanceLevel = GrapeCity.Spreadsheet.IO.Pdf.PdfAConformanceLevel.PdfA3u FpSpread1.AsWorkbook().SaveAs("D:\ISObook1.pdf", GrapeCity.Spreadsheet.IO.FileFormat.PDF, Nothing, pdfExportContext) |