[]
        
(Showing Draft Content)

Custom PDF Export

The savePDF method of the Workbook class can be used to perform the Export to PDF operation while working with spreadsheets.


In SpreadJS, users can perform custom PDF export according to the print settings specified in the workbook using the printInfo object. For each sheet, users can set detailed options by specifying the sheet printInfo options.


The following code sample shows how to use the printInfo object to set detailed options for custom PDF export.


var sheet = SpreadJS[0];
var printInfo = sheet.printInfo();
printInfo.showGridLine(false);
printInfo.showRowHeader(GC.Spread.Sheets.Print.PrintVisibilityType.show);
printInfo.showColumnHeader(GC.Spread.Sheets.Print.PrintVisibilityType.show);


Users can also export spreadsheets to PDF files in black and white by using the blackAndWhite property of printInfo object.


The following code sample shows how to use the blackAndWhite property to export PDF files in black and white.


// initializing Spread
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
// get the activesheet
var activeSheet = spread.getSheet(0);

var dataArray = [
    ["", '2012', '2013', '2014', '2015', '2016', '2017'],
    ["Chrome", 0.3782, 0.4663, 0.4966, 0.5689, 0.6230, 0.6360],
    ["FireFox", 0.2284, 0.2030, 0.1801, 0.1560, 0.1531, 0.1304],
    ["IE", 0.3214, 0.2491, 0.2455, 0.1652, 0.1073, 0.0834],
];
activeSheet.setArray(0, 0, dataArray);

var chart = activeSheet.charts.add('line', GC.Spread.Sheets.Charts.ChartType.bar, 0, 100, 400, 300, 'A1:D4')
var legend = chart.legend();
legend.visible = true;
chart.legend(legend);
chart.title({ text: "Bar Chart" });

// print to PDF in black & white
var printInfo = new GC.Spread.Sheets.Print.PrintInfo();
printInfo.blackAndWhite(true);
printInfo.savePDF = true;
activeSheet.printInfo(printInfo);
spread.print(0);