Drawing graphics

This sample shows how to draw graphics on a page. Click the 'Export' button to view the exported PDF document.

For more information, see the Drawing Graphics topic in Documentation.

import 'bootstrap.css'; import './styles.css'; import * as wijmo from '@grapecity/wijmo'; import * as pdf from '@grapecity/wijmo.pdf'; // 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') }); // sample1(doc); sample2(doc); sample3(doc); sample4(doc); sample5(doc); // doc.end(); }); } // // const a = 100, // sample area's size. c1 = new wijmo.Color('#3173c0'), c2 = new wijmo.Color('#e69500'); // function sample1(doc) { doc.drawText('Draw a series of lines with different styles: '); // let y = doc.y + doc.lineHeight(); // // default document's pen (black color) doc.paths .moveTo(0, y) .lineTo(a, y) .stroke(); // // color doc.paths .moveTo(0, y + 20) .lineTo(a, y + 20) .stroke(c1); // // color, line width = 3 doc.paths .moveTo(0, y + 40) .lineTo(a, y + 40) .stroke(new pdf.PdfPen(c1, 3)); // // opacity color, line width = 3 doc.paths .moveTo(0, y + 60) .lineTo(a, y + 60) .stroke(new pdf.PdfPen(wijmo.Color.fromRgba(c1.r, c1.g, c1.b, 0.2), 3)); // // color, dash pattern, line width = 3 doc.paths .moveTo(0, y + 80) .lineTo(a, y + 80) .stroke(new pdf.PdfPen(c1, 3, new pdf.PdfDashPattern(5))); // doc.y = y + a + doc.lineHeight(); } // function sample2(doc) { doc.drawText('Draw a rectangle covered with a filled curved path:'); // let y = doc.y + doc.lineHeight(); // doc.paths .rect(0, y, a, a) .stroke(c1); // doc.paths .moveTo(0, y) .bezierCurveTo(a / 2, y, a / 2, a + y, a, a + y) .lineTo(0, a + y) .lineTo(0, y) .fill(c2); // doc.y = y + a + doc.lineHeight(); } // function sample3(doc) { doc.drawText('Draw a rectangle, inscribe a circle into it, fill the circle with an opaque color and stroke it using a dashed line:'); // let y = doc.y + doc.lineHeight(); // doc.paths .rect(0, y, a, a) .fill(c1); // doc.paths .circle(a / 2, y + a / 2, a / 2) .fillAndStroke(wijmo.Color.fromRgba(c2.r, c2.g, c2.b, 0.3), new pdf.PdfPen(c2, 2, new pdf.PdfDashPattern(5))); // doc.y = y + a + doc.lineHeight(); } // function sample4(doc) { doc.drawText('Draw a simple pattern clipped by a circular clipping path:'); // let y = doc.y + doc.lineHeight(), a0 = 10; // doc.saveState(); // // clipping path doc.paths .circle(a / 2, y + a / 2, a / 2) .clip(); // // draw pattern for (let i = 0; i < 10; i++) { doc.paths .rect(0, y + i * a0, a, a0) .fill(i % 2 ? c1 : c2); } // doc.restoreState(); // doc.y = y + a + doc.lineHeight(); } // function sample5(doc) { doc.drawText('Draw a series of rectangles and rotate every rectangle by 15 degrees to the previous:'); // let y = doc.y + doc.lineHeight(), sqrt2 = Math.sqrt(2), degrees = 15, samples = 90 / degrees; // doc.saveState(); // for (let i = 0; i < samples; i++) { doc .rotate(degrees, new wijmo.Point(a / 2, y + a / 2)) .paths // draw rectangle as if it is inscribed into a circle with the radius of a/ 2 .rect((a - a / sqrt2) / 2, y + ((a - a / sqrt2) / 2), a / sqrt2, a / sqrt2) .fill(wijmo.Color.interpolate(c1, c2, i * (1 / (samples - 1)))); } // doc.restoreState(); // doc.y = y + a + doc.lineHeight(); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Drawing Graphics</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>
body { margin-bottom: 24px; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'jszip': 'npm:jszip/dist/jszip.js', '@grapecity/wijmo': 'npm:@grapecity/wijmo/index.js', '@grapecity/wijmo.input': 'npm:@grapecity/wijmo.input/index.js', '@grapecity/wijmo.styles': 'npm:@grapecity/wijmo.styles', '@grapecity/wijmo.cultures': 'npm:@grapecity/wijmo.cultures', '@grapecity/wijmo.chart': 'npm:@grapecity/wijmo.chart/index.js', '@grapecity/wijmo.chart.analytics': 'npm:@grapecity/wijmo.chart.analytics/index.js', '@grapecity/wijmo.chart.animation': 'npm:@grapecity/wijmo.chart.animation/index.js', '@grapecity/wijmo.chart.annotation': 'npm:@grapecity/wijmo.chart.annotation/index.js', '@grapecity/wijmo.chart.finance': 'npm:@grapecity/wijmo.chart.finance/index.js', '@grapecity/wijmo.chart.finance.analytics': 'npm:@grapecity/wijmo.chart.finance.analytics/index.js', '@grapecity/wijmo.chart.hierarchical': 'npm:@grapecity/wijmo.chart.hierarchical/index.js', '@grapecity/wijmo.chart.interaction': 'npm:@grapecity/wijmo.chart.interaction/index.js', '@grapecity/wijmo.chart.radar': 'npm:@grapecity/wijmo.chart.radar/index.js', '@grapecity/wijmo.chart.render': 'npm:@grapecity/wijmo.chart.render/index.js', '@grapecity/wijmo.chart.webgl': 'npm:@grapecity/wijmo.chart.webgl/index.js', '@grapecity/wijmo.gauge': 'npm:@grapecity/wijmo.gauge/index.js', '@grapecity/wijmo.grid': 'npm:@grapecity/wijmo.grid/index.js', '@grapecity/wijmo.grid.detail': 'npm:@grapecity/wijmo.grid.detail/index.js', '@grapecity/wijmo.grid.filter': 'npm:@grapecity/wijmo.grid.filter/index.js', '@grapecity/wijmo.grid.search': 'npm:@grapecity/wijmo.grid.search/index.js', '@grapecity/wijmo.grid.grouppanel': 'npm:@grapecity/wijmo.grid.grouppanel/index.js', '@grapecity/wijmo.grid.multirow': 'npm:@grapecity/wijmo.grid.multirow/index.js', '@grapecity/wijmo.grid.transposed': 'npm:@grapecity/wijmo.grid.transposed/index.js', '@grapecity/wijmo.grid.transposedmultirow': 'npm:@grapecity/wijmo.grid.transposedmultirow/index.js', '@grapecity/wijmo.grid.pdf': 'npm:@grapecity/wijmo.grid.pdf/index.js', '@grapecity/wijmo.grid.sheet': 'npm:@grapecity/wijmo.grid.sheet/index.js', '@grapecity/wijmo.grid.xlsx': 'npm:@grapecity/wijmo.grid.xlsx/index.js', '@grapecity/wijmo.grid.selector': 'npm:@grapecity/wijmo.grid.selector/index.js', '@grapecity/wijmo.grid.cellmaker': 'npm:@grapecity/wijmo.grid.cellmaker/index.js', '@grapecity/wijmo.nav': 'npm:@grapecity/wijmo.nav/index.js', '@grapecity/wijmo.odata': 'npm:@grapecity/wijmo.odata/index.js', '@grapecity/wijmo.olap': 'npm:@grapecity/wijmo.olap/index.js', '@grapecity/wijmo.pdf': 'npm:@grapecity/wijmo.pdf/index.js', '@grapecity/wijmo.pdf.security': 'npm:@grapecity/wijmo.pdf.security/index.js', '@grapecity/wijmo.viewer': 'npm:@grapecity/wijmo.viewer/index.js', '@grapecity/wijmo.xlsx': 'npm:@grapecity/wijmo.xlsx/index.js', '@grapecity/wijmo.undo': 'npm:@grapecity/wijmo.undo/index.js', '@grapecity/wijmo.interop.grid': 'npm:@grapecity/wijmo.interop.grid/index.js', '@grapecity/wijmo.touch': 'npm:@grapecity/wijmo.touch/index.js', '@grapecity/wijmo.cloud': 'npm:@grapecity/wijmo.cloud/index.js', '@grapecity/wijmo.barcode': 'npm:@grapecity/wijmo.barcode/index.js', '@grapecity/wijmo.barcode.common': 'npm:@grapecity/wijmo.barcode.common/index.js', '@grapecity/wijmo.barcode.composite': 'npm:@grapecity/wijmo.barcode.composite/index.js', '@grapecity/wijmo.barcode.specialized': 'npm:@grapecity/wijmo.barcode.specialized/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);