[]
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.
!type=note
Note:
To save a worksheet in PDF format, make sure you have the following settings:
ExcelCompatiblePrinting property is set to true
BorderCollapse enum is set to Enhanced
LegacyBehaviors.Style is excluded from LegacyBehaviors enum
The following code is used to save the worksheet to PDF.
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);
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.
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);
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:
Supports enhanced border which is compatible with Excel
Supports Excel-like number format
Provides support for gradient and pattern fill
Supports printing of enhanced shapes
Supports ISO standard
The following code is used to save workbook with ISO standard support:
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);
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)