Drawing tables

This sample illustrates how to draw a simple table and split table rows across pages by using horizontal page breaks. Click the 'Export' button to view the table in the exported PDF document.

import 'bootstrap.css'; import './styles.css'; import * as pdf from '@grapecity/wijmo.pdf'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { document.querySelector('#btnExport').addEventListener('click', () => { let doc = new pdf.PdfDocument({ header: { height: 0 }, footer: { height: 0 }, ended: (sender, args) => pdf.saveBlob(args.blob, 'Document.pdf') }); // let colWidth = 100, rowHeight = 18, data = getData(50), dataKeyMap = ['id', 'product', 'country'], y = 0; // for (let i = 0; i < 50; i++) { for (let j = 0; j < dataKeyMap.length; j++) { let x = j * colWidth; // doc.paths .rect(x, y, colWidth, rowHeight) .stroke(); // doc.drawText(data[i][dataKeyMap[j]] + '', x + 2, y + 2, { height: rowHeight, width: colWidth }); } // y += rowHeight; // if (y >= doc.height) { y = 0; doc.addPage(); } } // doc.end(); }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Drawing tables</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <!-- Export button --> <button class="btn btn-default" id="btnExport">Export</button> </div> </body> </html> export function getData(count) { const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId] }; // // add the item to the list data.push(item); } // return data; } body { margin-bottom: 24px; } import 'bootstrap.css'; import './styles.css'; // import * as pdf from '@grapecity/wijmo.pdf'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { getData } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { export() { let doc = new pdf.PdfDocument({ header: { height: 0 }, footer: { height: 0 }, ended: (sender: pdf.PdfDocument, args: pdf.PdfDocumentEndedEventArgs) => pdf.saveBlob(args.blob, 'Document.pdf') }); // let colWidth = 100, rowHeight = 18, data = getData(50), dataKeyMap = ['id', 'product', 'country'], y = 0; // for (let i = 0; i < 50; i++) { for (let j = 0; j < dataKeyMap.length; j++) { let x = j * colWidth; // doc.paths .rect(x, y, colWidth, rowHeight) .stroke(); // doc.drawText(data[i][dataKeyMap[j]] + '', x + 2, y + 2, { height: rowHeight, width: colWidth }); } // y += rowHeight; // if (y >= doc.height) { y = 0; doc.addPage(); } } // doc.end(); } } // @NgModule({ imports: [BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Drawing tables</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <!-- Export button --> <button class="btn btn-default" (click)="export()">Export</button> </div> export function getData(count: number) { const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId] }; // // add the item to the list data.push(item); } // return data; } body { margin-bottom: 24px; } <template> <div class="container-fluid"> <!-- Export button --> <button class="btn btn-default" @click="exportPDF">Export</button> </div> </template> <script> import 'bootstrap.css'; import Vue from 'vue'; import * as pdf from '@grapecity/wijmo.pdf'; import { getData } from './data' // let App = Vue.extend({ name: 'app', methods: { exportPDF() { let doc = new pdf.PdfDocument({ header: { height: 0 }, footer: { height: 0 }, ended: (sender, args) => pdf.saveBlob(args.blob, 'Document.pdf') }); // let colWidth = 100, rowHeight = 18, data = getData(50), dataKeyMap = ['id', 'product', 'country'], y = 0; // for (let i = 0; i < 50; i++) { for (let j = 0; j < dataKeyMap.length; j++) { let x = j * colWidth; // doc.paths .rect(x, y, colWidth, rowHeight) .stroke(); // doc.drawText(data[i][dataKeyMap[j]] + '', x + 2, y + 2, { height: rowHeight, width: colWidth }); } // y += rowHeight; // if (y >= doc.height) { y = 0; doc.addPage(); } } // doc.end(); } } }) // new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> body { margin-bottom: 24px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Drawing tables</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> export function getData(count) { const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId] }; // // add the item to the list data.push(item); } // return data; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as pdf from "@grapecity/wijmo.pdf"; import { getData } from "./data"; class App extends React.Component { render() { return <div className="container-fluid"> <button className="btn btn-default" onClick={this.exportPDF.bind(this)}>Export</button> </div>; } exportPDF() { let doc = new pdf.PdfDocument({ header: { height: 0 }, footer: { height: 0 }, ended: (sender, args) => pdf.saveBlob(args.blob, 'Document.pdf') }); // let colWidth = 100, rowHeight = 18, data = getData(50), dataKeyMap = ['id', 'product', 'country'], y = 0; // for (let i = 0; i < 50; i++) { for (let j = 0; j < dataKeyMap.length; j++) { let x = j * colWidth; // doc.paths .rect(x, y, colWidth, rowHeight) .stroke(); // doc.drawText(data[i][dataKeyMap[j]] + '', x + 2, y + 2, { height: rowHeight, width: colWidth }); } // y += rowHeight; // if (y >= doc.height) { y = 0; doc.addPage(); } } // doc.end(); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Chart Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> body { margin-bottom: 24px; } export function getData(count) { const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId] }; // // add the item to the list data.push(item); } // return data; }