# Export to PDF

## Content

SpreadJS supports PDF file export i.e. exporting a workbook (excel files with .xlsx extension) to PDF format (files with .pdf extension) via the [savePDF](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook#savePDF) method of the [Workbook class](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook).

The following table lists the parameters of the [savePDF](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook#savePDF) method:

| Parameter | Description |
| --------- | ----------- |
| successCallback | Call this function after export to pdf operation is successful. |
| errorCallback | Call this function when an error occurs. |
| options | You can choose from the following options while exporting to a PDF file:<ol><li>`options.creator` \- You can specify the name of the application \(for example Adobe Framemaker\) that created the original document from which it was converted\.</li><li>`options.title` \- You can specify the title of the document</li><li>`options.author` \- You can specify the name of the person who created that document</li><li>`options.keywords` \- You can specify the keywords associated with the document</li><li>`options.subject` \- You can specify the subject of the document\.</li></ol> |
| sheetIndex | You can export specific sheets in a workbook to PDF by specifying the sheet index of the sheet you want to export. If this argument is not given, all visible sheets will be exported by default. |

The Export to PDF operation uses `printInfo` object for page setting and provides support for all the printing features that are available in SpreadJS.

For more information on custom export of PDF files, see [Custom PDF Export](/spreadjs/docs/v17/excelimpexp/ExportingToPDF/CustomPDFExport).
While exporting to a PDF file, you can specify the font you want to embed in your PDF document. Users can embed both standard fonts (listed below) and the custom fonts (via registering a new font) for PDF export.

For more information on how to embed custom fonts while performing the Export to PDF operation, see [Use Custom Font for PDF Export](/spreadjs/docs/v17/excelimpexp/ExportingToPDF/UseCustomFontforPDFExport)

The following table lists the fourteen standard fonts that are supported in a PDF document:

| Font |  |
| ---- | --- |
| Courier | Courier<br>Courier-Bold<br>Courier-Oblique<br>Courier-BoldOblique |
| Times | Times-Roman<br>Times-Bold<br>Times-Italic<br>Times-BoldItalic |
| Helvetica | Helvetica<br>Helvetica-Bold<br>Helvetica-Oblique<br>Helvetica-BoldOblique |
| Symbol | Symbol |
| ZapfDingbats | ZapfDingbats |

## Using Code

This example shows how to use the [savePDF](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook#savePDF) method to export Excel files to PDF files. The exported files are saved with a .pdf extension.

The first section of the code sample lists the dependencies for executing the Export to PDF operation.

```HTML
<script src='.../spreadjs/gc.spread.sheets.all.x.xx.xxxxx.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.print.x.xx.xxxxx.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.pdf.x.xx.xxxxx.x.min.js' type='text/javascript'></script>
```

The second section of the code sample illustrates how the savePDF method can be used for exporting to PDF format.

```JavaScript
spread.savePDF(function (blob) {
    var fileName = $('#fileName').val() || 'download';
    saveAs(blob, fileName + '.pdf');
}, function (error) {
    console.log(error);
}, {
    title: 'Test Title',
    author: 'Test Author',
    subject: 'Test Subject',
    keywords: 'Test Keywords',
    creator: 'test Creator'
});
```

> **Note:** The following points should be kept in mind while exporting to PDF:
>
> 1. In order to export to an excel file, users need to reference the file: `gc.spread.sheets.pdf.\*.\*.\*.min.js`
> 2. Images are not base64 encoded. Hence, they may not be exported when a user makes use of file protocol schemes. It is necessary that users should use http or https protocol schemes while performing the export operation.