Demo - Export to PDF
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.pdf.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.pdf.min.js"></script>
<div class="container">
<button id="btnExport" class="btn btn-default">
Export to PDF
</button>
<button id="btnCreateDoc" class="btn btn-default">
Create PDF Document
</button>
<div id="theGrid"></div>
</div>
CSS
.wj-flexgrid {
max-height: 250px;
margin: 12px 0;
}
body {
margin-bottom: 20px;
}
JavaScript
onload = function() {
// create some random data
var countries = 'United States of America (of North America),Germany,UK,Japan,Italy,Greece'.split(',');
var data = [];
for (var i = 0; i < 200; i++) {
data.push({
id: i,
country: countries[i % countries.length],
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
// show the data in a grid
var theGrid = new wijmo.grid.FlexGrid('#theGrid', {
autoGenerateColumns: false,
columns: [
{ binding: 'id', header: 'ID', width: 60 },
{ binding: 'country', header: 'Country', width: '*', wordWrap: true },
{ binding: 'sales', header: 'Sales', width: '2*', format: 'n2'},
{ binding: 'expenses', header: 'Expenses', width: '*', format: 'n2'}
],
itemsSource: data
});
theGrid.autoSizeRows();
// add a filter to show that it works while exporting
var f = new wijmo.grid.filter.FlexGridFilter(theGrid);
// export grid to PDF
document.getElementById('btnExport').addEventListener('click', function() {
wijmo.grid.pdf.FlexGridPdfConverter.export(theGrid, 'LearnWijmo.pdf', {
maxPages: 10,
scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth,
documentOptions: {
compress: true,
header: { declarative: { text: '\t&[Page] of &[Pages]' } },
footer: { declarative: { text: '\t&[Page] of &[Pages]' } },
info: { author: 'C1', title: 'Learn Wijmo' }
},
styles: {
cellStyle: { backgroundColor: '#ffffff', borderColor: '#c6c6c6' },
altCellStyle: { backgroundColor: '#f9f9f9' },
groupCellStyle: { backgroundColor: '#dddddd' },
headerCellStyle: { backgroundColor: '#eaeaea' }
}
});
});
// create a PDF document with the grid and some other content
document.getElementById('btnCreateDoc').addEventListener('click', function() {
// create the document
var doc = new wijmo.pdf.PdfDocument({
compress: true,
header: { declarative: { text: '\t&[Page]\\&[Pages]' }...