# Export to PDF

## Content

SpreadJS supports PDF file export i.e. exporting a workbook to PDF format (files with .pdf extension) using the [savePDF](/spreadjs/api/classes/GC.Spread.Sheets.Workbook#savePDF) method of the [Workbook class](/spreadjs/api/classes/GC.Spread.Sheets.Workbook).
The following table lists the parameters of the [savePDF](/spreadjs/api/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:<ul><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></ul> |
| 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/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/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/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.x.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.print.x.x.x.min.js' type='text/javascript'></script>
<script src='.../spreadjs/plugins/gc.spread.sheets.pdf.x.x.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:** When exporting to PDF, you need to keep the following points in mind:
>
> * To export to PDF format, you need to refer to the following two modules:
>     * gc.spread.sheets.print.x.x.x.min.js
>     * gc.spread.sheets.pdf.x.x.x.min.js
>
>     Note that the Print plug-in must be loaded first.
>
>
> * Images whose source is taken from a URL or a specified path are not automatically encoded in base64 format. Therefore, if you use the file protocol scheme, the image may not be exported.