# Saving to a PDF File

Enables to save the worksheet/workbook to PDF format with some additional benefits over PrintToPdf method

## Content

Spread allows you to save your worksheet/workbook in a PDF format by using the [SaveAs](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorkbook.SaveAs.html) 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**: If you are installing a product with the installer, you must add the **System.Memory** NuGet package to your reference when using this feature.

> !type=note
> **Note:**
> To save a worksheet in PDF format, make sure you have the following settings:
>
> * [ExcelCompatiblePrinting](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.IFeatures.ExcelCompatiblePrinting.html) property is set to true
> * [BorderCollapse](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.BorderCollapse.html) enum is set to Enhanced
> * **LegacyBehaviors.Style** is excluded from [LegacyBehaviors](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.LegacyBehaviors.html) enum

## Saving worksheet to PDF

The following code is used to save the worksheet to PDF.

```csharp
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);
```

```vbnet
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)
```

## Saving workbook to PDF

The following code is used to save the workbook to PDF.

```csharp
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);
```

```vbnet
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)
```

## Benefits of using SaveAs method

Saving the PDF using the SaveAs method has several additional benefits over [PrintToPDF](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.PrintInfo.PrintToPdf.html) 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:

```csharp
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);
```

```vbnet
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)
```

## See Also

[Saving to a Spread XML File](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-spreadfile)
[Saving to an Excel File](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-excelfile)
[Saving to a Text File](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-texttfile)
[Saving to an Image File](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-imagefile)
[Saving to an HTML File](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-htmlfile)
[Adding Custom Properties](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-add-custom-property)
[Saving to an HTML Table](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-htmltable)
[Saving Spreadsheet Data to Simple XML](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-usefiles/spwin-savefiles/spwin-save-dataxml)