Spread.Sheets Documentation
Exporting to PDF
Spread.Sheets Documentation > Developer's Guide > Managing Data > Exporting to PDF

Spread.Sheets supports PDF file export i.e. exporting a workbook (excel files with .xlsx extension) to PDF format (files with .pdf extension) via the savePDF method of the Workbook class.

The following table lists the parameters of the 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:

  1. options.creator - You can specify the name of the application (for example : Adobe Framemaker) that created the original document from which it was converted.
  2. options.title - You can specify the title of the document
  3. options.author - You can specify the name of the person who created that document
  4. options.keywords - You can specify the keywords associated with the document
  5. options.subject - You can specify the subject of the document.
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 Spread.Sheets.

For more information on custom export of PDF files, see Custom PDF Export.

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.

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

 

Courier
Courier
Courier-Bold
Courier-Oblique
Courier-BoldOblique
Times
Times-Roman
Times-Bold
Times-Italic
Times-BoldItalic

Helvetica

Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Symbol Symbol
ZapfDingbats ZapfDingbats

 

Using Code

This example shows how to use the savePDF method to export Excel files to PDF files. The exported files are saved with a .pdf extension.

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

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

JavaScript
Copy Code
<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>
        
JavaScript
Copy Code

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: 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.