hjkhjkjhkhjkgjghjhgjhgjghjhghjghjhgjjnbvnvbnvk
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
b4h4ej4a6kj6
/
public_html
/
mahetechnologies.co.uk
/
workshop
/
admin
/
js
/
jsPDF-master
/
docs
/
Upload FileeE
HOME
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>modules/cell.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav > <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="GState.html">GState</a></li><li><a href="jsPDF.html">jsPDF</a><ul class='methods'><li data-type='method'><a href="jsPDF.html#addFont">addFont</a></li><li data-type='method'><a href="jsPDF.html#addGState">addGState</a></li><li data-type='method'><a href="jsPDF.html#addPage">addPage</a></li><li data-type='method'><a href="jsPDF.html#addPattern">addPattern</a></li><li data-type='method'><a href="jsPDF.html#beginFormObject">beginFormObject</a></li><li data-type='method'><a href="jsPDF.html#circle">circle</a></li><li data-type='method'><a href="jsPDF.html#clip">clip</a></li><li data-type='method'><a href="jsPDF.html#clipEvenOdd">clipEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#close">close</a></li><li data-type='method'><a href="jsPDF.html#comment">comment</a></li><li data-type='method'><a href="jsPDF.html#curveTo">curveTo</a></li><li data-type='method'><a href="jsPDF.html#deletePage">deletePage</a></li><li data-type='method'><a href="jsPDF.html#discardPath">discardPath</a></li><li data-type='method'><a href="jsPDF.html#doFormObject">doFormObject</a></li><li data-type='method'><a href="jsPDF.html#ellipse">ellipse</a></li><li data-type='method'><a href="jsPDF.html#endFormObject">endFormObject</a></li><li data-type='method'><a href="jsPDF.html#fill">fill</a></li><li data-type='method'><a href="jsPDF.html#fillEvenOdd">fillEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#fillStroke">fillStroke</a></li><li data-type='method'><a href="jsPDF.html#fillStrokeEvenOdd">fillStrokeEvenOdd</a></li><li data-type='method'><a href="jsPDF.html#getCharSpace">getCharSpace</a></li><li data-type='method'><a href="jsPDF.html#getCreationDate">getCreationDate</a></li><li data-type='method'><a href="jsPDF.html#getDrawColor">getDrawColor</a></li><li data-type='method'><a href="jsPDF.html#getFileId">getFileId</a></li><li data-type='method'><a href="jsPDF.html#getFillColor">getFillColor</a></li><li data-type='method'><a href="jsPDF.html#getFont">getFont</a></li><li data-type='method'><a href="jsPDF.html#getFontList">getFontList</a></li><li data-type='method'><a href="jsPDF.html#getFontSize">getFontSize</a></li><li data-type='method'><a href="jsPDF.html#getFormObject">getFormObject</a></li><li data-type='method'><a href="jsPDF.html#getLineHeightFactor">getLineHeightFactor</a></li><li data-type='method'><a href="jsPDF.html#getLineWidth">getLineWidth</a></li><li data-type='method'><a href="jsPDF.html#getR2L">getR2L</a></li><li data-type='method'><a href="jsPDF.html#getTextColor">getTextColor</a></li><li data-type='method'><a href="jsPDF.html#insertPage">insertPage</a></li><li data-type='method'><a href="jsPDF.html#line">line</a></li><li data-type='method'><a href="jsPDF.html#lines">lines</a></li><li data-type='method'><a href="jsPDF.html#lineTo">lineTo</a></li><li data-type='method'><a href="jsPDF.html#movePage">movePage</a></li><li data-type='method'><a href="jsPDF.html#moveTo">moveTo</a></li><li data-type='method'><a href="jsPDF.html#output">output</a></li><li data-type='method'><a href="jsPDF.html#path">path</a></li><li data-type='method'><a href="jsPDF.html#rect">rect</a></li><li data-type='method'><a href="jsPDF.html#restoreGraphicsState">restoreGraphicsState</a></li><li data-type='method'><a href="jsPDF.html#roundedRect">roundedRect</a></li><li data-type='method'><a href="jsPDF.html#save">save</a></li><li data-type='method'><a href="jsPDF.html#saveGraphicsState">saveGraphicsState</a></li><li data-type='method'><a href="jsPDF.html#setCharSpace">setCharSpace</a></li><li data-type='method'><a href="jsPDF.html#setCreationDate">setCreationDate</a></li><li data-type='method'><a href="jsPDF.html#setCurrentTransformationMatrix">setCurrentTransformationMatrix</a></li><li data-type='method'><a href="jsPDF.html#setDisplayMode">setDisplayMode</a></li><li data-type='method'><a href="jsPDF.html#setDocumentProperties">setDocumentProperties</a></li><li data-type='method'><a href="jsPDF.html#setDrawColor">setDrawColor</a></li><li data-type='method'><a href="jsPDF.html#setFileId">setFileId</a></li><li data-type='method'><a href="jsPDF.html#setFillColor">setFillColor</a></li><li data-type='method'><a href="jsPDF.html#setFont">setFont</a></li><li data-type='method'><a href="jsPDF.html#setFontSize">setFontSize</a></li><li data-type='method'><a href="jsPDF.html#setGState">setGState</a></li><li data-type='method'><a href="jsPDF.html#setLineCap">setLineCap</a></li><li data-type='method'><a href="jsPDF.html#setLineDashPattern">setLineDashPattern</a></li><li data-type='method'><a href="jsPDF.html#setLineHeightFactor">setLineHeightFactor</a></li><li data-type='method'><a href="jsPDF.html#setLineJoin">setLineJoin</a></li><li data-type='method'><a href="jsPDF.html#setLineMiterLimit">setLineMiterLimit</a></li><li data-type='method'><a href="jsPDF.html#setLineWidth">setLineWidth</a></li><li data-type='method'><a href="jsPDF.html#setPage">setPage</a></li><li data-type='method'><a href="jsPDF.html#setPrecision">setPrecision</a></li><li data-type='method'><a href="jsPDF.html#setR2L">setR2L</a></li><li data-type='method'><a href="jsPDF.html#setTextColor">setTextColor</a></li><li data-type='method'><a href="jsPDF.html#stroke">stroke</a></li><li data-type='method'><a href="jsPDF.html#text">text</a></li><li data-type='method'><a href="jsPDF.html#triangle">triangle</a></li><li data-type='method'><a href="jsPDF.html#~addGState">addGState</a></li><li data-type='method'><a href="jsPDF.html#~addPattern">addPattern</a></li><li data-type='method'><a href="jsPDF.html#~hasHotfix">hasHotfix</a></li><li data-type='method'><a href="jsPDF.html#~Point">Point</a></li><li data-type='method'><a href="jsPDF.html#~Rectangle">Rectangle</a></li><li data-type='method'><a href="jsPDF.html#~RenderTarget">RenderTarget</a></li></ul></li><li><a href="jsPDF-API.GState.html">GState</a></li><li><a href="jsPDF-API.ShadingPattern.html">ShadingPattern</a></li><li><a href="jsPDF-API.TilingPattern.html">TilingPattern</a></li><li><a href="Matrix.html">Matrix</a><ul class='methods'><li data-type='method'><a href="Matrix.html#applyToPoint">applyToPoint</a></li><li data-type='method'><a href="Matrix.html#applyToRectangle">applyToRectangle</a></li><li data-type='method'><a href="Matrix.html#clone">clone</a></li><li data-type='method'><a href="Matrix.html#decompose">decompose</a></li><li data-type='method'><a href="Matrix.html#inversed">inversed</a></li><li data-type='method'><a href="Matrix.html#join">join</a></li><li data-type='method'><a href="Matrix.html#multiply">multiply</a></li><li data-type='method'><a href="Matrix.html#toString">toString</a></li></ul></li><li><a href="module-AcroForm-AcroFormButton.html">AcroFormButton</a></li><li><a href="module-AcroForm-AcroFormCheckBox.html">AcroFormCheckBox</a></li><li><a href="module-AcroForm-AcroFormChoiceField.html">AcroFormChoiceField</a></li><li><a href="module-AcroForm-AcroFormComboBox.html">AcroFormComboBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormComboBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormEditBox.html">AcroFormEditBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormEditBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormField.html">AcroFormField</a></li><li><a href="module-AcroForm-AcroFormListBox.html">AcroFormListBox</a><ul class='methods'><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#addOption">addOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#getOptions">getOptions</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#removeOption">removeOption</a></li><li data-type='method'><a href="module-AcroForm-AcroFormListBox.html#setOptions">setOptions</a></li></ul></li><li><a href="module-AcroForm-AcroFormPasswordField.html">AcroFormPasswordField</a></li><li><a href="module-AcroForm-AcroFormPDFObject.html">AcroFormPDFObject</a></li><li><a href="module-AcroForm-AcroFormPushButton.html">AcroFormPushButton</a></li><li><a href="module-AcroForm-AcroFormRadioButton.html">AcroFormRadioButton</a></li><li><a href="module-AcroForm-AcroFormTextField.html">AcroFormTextField</a></li><li><a href="module-canvas-Canvas.html">Canvas</a></li></ul><h3>Modules</h3><ul><li><a href="module-AcroForm.html">AcroForm</a><ul class='methods'><li data-type='method'><a href="module-AcroForm.html#addField">addField</a></li><li data-type='method'><a href="module-AcroForm.html#~AcroFormDictionaryCallback">AcroFormDictionaryCallback</a></li><li data-type='method'><a href="module-AcroForm.html#~calculateFontSpace">calculateFontSpace</a></li><li data-type='method'><a href="module-AcroForm.html#~createAnnotationReference">createAnnotationReference</a></li><li data-type='method'><a href="module-AcroForm.html#~createFieldCallback">createFieldCallback</a></li></ul></li><li><a href="module-addImage.html">addImage</a><ul class='methods'><li data-type='method'><a href="module-addImage.html#~addImage">addImage</a></li><li data-type='method'><a href="module-addImage.html#~arrayBufferToBinaryString">arrayBufferToBinaryString</a></li><li data-type='method'><a href="module-addImage.html#~binaryStringToUint8Array">binaryStringToUint8Array</a></li><li data-type='method'><a href="module-addImage.html#~convertBase64ToBinaryString">convertBase64ToBinaryString</a></li><li data-type='method'><a href="module-addImage.html#~extractImageFromDataUrl">extractImageFromDataUrl</a></li><li data-type='method'><a href="module-addImage.html#~getImageFileTypeByImageData">getImageFileTypeByImageData</a></li><li data-type='method'><a href="module-addImage.html#~getImageProperties">getImageProperties</a></li><li data-type='method'><a href="module-addImage.html#~isArrayBuffer">isArrayBuffer</a></li><li data-type='method'><a href="module-addImage.html#~isArrayBufferView">isArrayBufferView</a></li><li data-type='method'><a href="module-addImage.html#~sHashCode">sHashCode</a></li><li data-type='method'><a href="module-addImage.html#~supportsArrayBuffer">supportsArrayBuffer</a></li><li data-type='method'><a href="module-addImage.html#~validateStringAsBase64">validateStringAsBase64</a></li></ul></li><li><a href="module-annotations.html">annotations</a><ul class='methods'><li data-type='method'><a href="module-annotations.html#~createAnnotation">createAnnotation</a></li><li data-type='method'><a href="module-annotations.html#~getTextWidth">getTextWidth</a></li><li data-type='method'><a href="module-annotations.html#~link">link</a></li><li data-type='method'><a href="module-annotations.html#~textWithLink">textWithLink</a></li></ul></li><li><a href="module-arabic.html">arabic</a><ul class='methods'><li data-type='method'><a href="module-arabic.html#~processArabic">processArabic</a></li></ul></li><li><a href="module-autoprint.html">autoprint</a><ul class='methods'><li data-type='method'><a href="module-autoprint.html#~autoPrint">autoPrint</a></li></ul></li><li><a href="module-bmp_support.html">bmp_support</a></li><li><a href="module-canvas.html">canvas</a><ul class='methods'><li data-type='method'><a href="module-canvas.html#~getContext">getContext</a></li><li data-type='method'><a href="module-canvas.html#~toDataURL">toDataURL</a></li></ul></li><li><a href="module-cell.html">cell</a><ul class='methods'><li data-type='method'><a href="module-cell.html#~cell">cell</a></li><li data-type='method'><a href="module-cell.html#~cellAddPage">cellAddPage</a></li><li data-type='method'><a href="module-cell.html#~getTextDimensions">getTextDimensions</a></li><li data-type='method'><a href="module-cell.html#~printHeaderRow">printHeaderRow</a></li><li data-type='method'><a href="module-cell.html#~setHeaderFunction">setHeaderFunction</a></li><li data-type='method'><a href="module-cell.html#~setTableHeaderRow">setTableHeaderRow</a></li><li data-type='method'><a href="module-cell.html#~table">table</a></li></ul></li><li><a href="module-context2d.html">context2d</a><ul class='methods'><li data-type='method'><a href="module-context2d.html#~arc">arc</a></li><li data-type='method'><a href="module-context2d.html#~arcTo">arcTo</a></li><li data-type='method'><a href="module-context2d.html#~beginPath">beginPath</a></li><li data-type='method'><a href="module-context2d.html#~bezierCurveTo">bezierCurveTo</a></li><li data-type='method'><a href="module-context2d.html#~clearRect">clearRect</a></li><li data-type='method'><a href="module-context2d.html#~clip">clip</a></li><li data-type='method'><a href="module-context2d.html#~closePath">closePath</a></li><li data-type='method'><a href="module-context2d.html#~createArc">createArc</a></li><li data-type='method'><a href="module-context2d.html#~fillRect">fillRect</a></li><li data-type='method'><a href="module-context2d.html#~fillText">fillText</a></li><li data-type='method'><a href="module-context2d.html#~getLineDash">getLineDash</a></li><li data-type='method'><a href="module-context2d.html#~lineTo">lineTo</a></li><li data-type='method'><a href="module-context2d.html#~measureText">measureText</a></li><li data-type='method'><a href="module-context2d.html#~moveTo">moveTo</a></li><li data-type='method'><a href="module-context2d.html#~quadraticCurveTo">quadraticCurveTo</a></li><li data-type='method'><a href="module-context2d.html#~rect">rect</a></li><li data-type='method'><a href="module-context2d.html#~restore">restore</a></li><li data-type='method'><a href="module-context2d.html#~rotate">rotate</a></li><li data-type='method'><a href="module-context2d.html#~save">save</a></li><li data-type='method'><a href="module-context2d.html#~scale">scale</a></li><li data-type='method'><a href="module-context2d.html#~setLineDash">setLineDash</a></li><li data-type='method'><a href="module-context2d.html#~setTransform">setTransform</a></li><li data-type='method'><a href="module-context2d.html#~stroke">stroke</a></li><li data-type='method'><a href="module-context2d.html#~strokeRect">strokeRect</a></li><li data-type='method'><a href="module-context2d.html#~strokeText">strokeText</a></li><li data-type='method'><a href="module-context2d.html#~toDataURL">toDataURL</a></li><li data-type='method'><a href="module-context2d.html#~transform">transform</a></li><li data-type='method'><a href="module-context2d.html#~translate">translate</a></li></ul></li><li><a href="module-fileloading.html">fileloading</a><ul class='methods'><li data-type='method'><a href="module-fileloading.html#~loadFile">loadFile</a></li><li data-type='method'><a href="module-fileloading.html#~loadImageFile">loadImageFile</a></li></ul></li><li><a href="module-gif_support.html">gif_support</a></li><li><a href="module-html.html">html</a><ul class='methods'><li data-type='method'><a href="module-html.html#~html">html</a></li></ul></li><li><a href="module-javascript.html">javascript</a><ul class='methods'><li data-type='method'><a href="module-javascript.html#~addJS">addJS</a></li></ul></li><li><a href="module-jpeg_support.html">jpeg_support</a></li><li><a href="module-outline.html">outline</a></li><li><a href="module-png_support.html">png_support</a></li><li><a href="module-rgba_support.html">rgba_support</a></li><li><a href="module-setLanguage.html">setLanguage</a><ul class='methods'><li data-type='method'><a href="module-setLanguage.html#~setLanguage">setLanguage</a></li></ul></li><li><a href="module-split_text_to_size.html">split_text_to_size</a><ul class='methods'><li data-type='method'><a href="module-split_text_to_size.html#~getCharWidthsArray">getCharWidthsArray</a></li><li data-type='method'><a href="module-split_text_to_size.html#~getStringUnitWidth">getStringUnitWidth</a></li><li data-type='method'><a href="module-split_text_to_size.html#~splitTextToSize">splitTextToSize</a></li></ul></li><li><a href="module-standard_fonts_metrics.html">standard_fonts_metrics</a></li><li><a href="module-svg.html">svg</a><ul class='methods'><li data-type='method'><a href="module-svg.html#~addSvgAsImage">addSvgAsImage</a></li></ul></li><li><a href="module-total_pages.html">total_pages</a><ul class='methods'><li data-type='method'><a href="module-total_pages.html#~putTotalPages">putTotalPages</a></li></ul></li><li><a href="module-ttfsupport.html">ttfsupport</a></li><li><a href="module-utf8.html">utf8</a></li><li><a href="module-vFS.html">vFS</a><ul class='methods'><li data-type='method'><a href="module-vFS.html#~addFileToVFS">addFileToVFS</a></li><li data-type='method'><a href="module-vFS.html#~existsFileInVFS">existsFileInVFS</a></li><li data-type='method'><a href="module-vFS.html#~getFileFromVFS">getFileFromVFS</a></li></ul></li><li><a href="module-viewerpreferences.html">viewerpreferences</a><ul class='methods'><li data-type='method'><a href="module-viewerpreferences.html#~viewerPreferences">viewerPreferences</a></li></ul></li><li><a href="module-webp_support.html">webp_support</a></li><li><a href="module-xmp_metadata.html">xmp_metadata</a><ul class='methods'><li data-type='method'><a href="module-xmp_metadata.html#~addMetadata">addMetadata</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#constructor">constructor</a></li><li><a href="global.html#encryptor">encryptor</a></li><li><a href="global.html#hexToBytes">hexToBytes</a></li><li><a href="global.html#lsbFirstWord">lsbFirstWord</a></li><li><a href="global.html#mapArrayBufferViews">mapArrayBufferViews</a></li><li><a href="global.html#md5cycle">md5cycle</a></li><li><a href="global.html#processOwnerPassword">processOwnerPassword</a></li><li><a href="global.html#rc4">rc4</a></li><li><a href="global.html#repeat">repeat</a></li><li><a href="global.html#RGBColor">RGBColor</a></li><li><a href="global.html#SetsoptionsforBidiconversion">Sets options for Bidi conversion</a></li><li><a href="global.html#toHexString">toHexString</a></li><li><a href="global.html#toPDFName">toPDFName</a></li></ul> </nav> <div id="main"> <h1 class="page-title">modules/cell.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * @license * ==================================================================== * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br * 2013 Lee Driscoll, https://github.com/lsdriscoll * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria * 2014 James Hall, james@parall.ax * 2014 Diego Casorran, https://github.com/diegocr * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ==================================================================== */ import { jsPDF } from "../jspdf.js"; /** * @name cell * @module */ (function(jsPDFAPI) { "use strict"; var NO_MARGINS = { left: 0, top: 0, bottom: 0, right: 0 }; var px2pt = (0.264583 * 72) / 25.4; var printingHeaderRow = false; var _initialize = function() { if (typeof this.internal.__cell__ === "undefined") { this.internal.__cell__ = {}; this.internal.__cell__.padding = 3; this.internal.__cell__.headerFunction = undefined; this.internal.__cell__.margins = Object.assign({}, NO_MARGINS); this.internal.__cell__.margins.width = this.getPageWidth(); _reset.call(this); } }; var _reset = function() { this.internal.__cell__.lastCell = new Cell(); this.internal.__cell__.pages = 1; }; var Cell = function() { var _x = arguments[0]; Object.defineProperty(this, "x", { enumerable: true, get: function() { return _x; }, set: function(value) { _x = value; } }); var _y = arguments[1]; Object.defineProperty(this, "y", { enumerable: true, get: function() { return _y; }, set: function(value) { _y = value; } }); var _width = arguments[2]; Object.defineProperty(this, "width", { enumerable: true, get: function() { return _width; }, set: function(value) { _width = value; } }); var _height = arguments[3]; Object.defineProperty(this, "height", { enumerable: true, get: function() { return _height; }, set: function(value) { _height = value; } }); var _text = arguments[4]; Object.defineProperty(this, "text", { enumerable: true, get: function() { return _text; }, set: function(value) { _text = value; } }); var _lineNumber = arguments[5]; Object.defineProperty(this, "lineNumber", { enumerable: true, get: function() { return _lineNumber; }, set: function(value) { _lineNumber = value; } }); var _align = arguments[6]; Object.defineProperty(this, "align", { enumerable: true, get: function() { return _align; }, set: function(value) { _align = value; } }); return this; }; Cell.prototype.clone = function() { return new Cell( this.x, this.y, this.width, this.height, this.text, this.lineNumber, this.align ); }; Cell.prototype.toArray = function() { return [ this.x, this.y, this.width, this.height, this.text, this.lineNumber, this.align ]; }; /** * @name setHeaderFunction * @function * @param {function} func */ jsPDFAPI.setHeaderFunction = function(func) { _initialize.call(this); this.internal.__cell__.headerFunction = typeof func === "function" ? func : undefined; return this; }; /** * @name getTextDimensions * @function * @param {string} txt * @returns {Object} dimensions */ jsPDFAPI.getTextDimensions = function(text, options) { _initialize.call(this); options = options || {}; var fontSize = options.fontSize || this.getFontSize(); var font = options.font || this.getFont(); var scaleFactor = options.scaleFactor || this.internal.scaleFactor; var width = 0; var amountOfLines = 0; var height = 0; var tempWidth = 0; var scope = this; if (!Array.isArray(text) && typeof text !== "string") { if (typeof text === "number") { text = String(text); } else { throw new Error( "getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings." ); } } const maxWidth = options.maxWidth; if (maxWidth > 0) { if (typeof text === "string") { text = this.splitTextToSize(text, maxWidth); } else if (Object.prototype.toString.call(text) === "[object Array]") { text = text.reduce(function(acc, textLine) { return acc.concat(scope.splitTextToSize(textLine, maxWidth)); }, []); } } else { // Without the else clause, it will not work if you do not pass along maxWidth text = Array.isArray(text) ? text : [text]; } for (var i = 0; i < text.length; i++) { tempWidth = this.getStringUnitWidth(text[i], { font: font }) * fontSize; if (width < tempWidth) { width = tempWidth; } } if (width !== 0) { amountOfLines = text.length; } width = width / scaleFactor; height = Math.max( (amountOfLines * fontSize * this.getLineHeightFactor() - fontSize * (this.getLineHeightFactor() - 1)) / scaleFactor, 0 ); return { w: width, h: height }; }; /** * @name cellAddPage * @function */ jsPDFAPI.cellAddPage = function() { _initialize.call(this); this.addPage(); var margins = this.internal.__cell__.margins || NO_MARGINS; this.internal.__cell__.lastCell = new Cell( margins.left, margins.top, undefined, undefined ); this.internal.__cell__.pages += 1; return this; }; /** * @name cell * @function * @param {number} x * @param {number} y * @param {number} width * @param {number} height * @param {string} text * @param {number} lineNumber lineNumber * @param {string} align * @return {jsPDF} jsPDF-instance */ var cell = (jsPDFAPI.cell = function() { var currentCell; if (arguments[0] instanceof Cell) { currentCell = arguments[0]; } else { currentCell = new Cell( arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5] ); } _initialize.call(this); var lastCell = this.internal.__cell__.lastCell; var padding = this.internal.__cell__.padding; var margins = this.internal.__cell__.margins || NO_MARGINS; var tableHeaderRow = this.internal.__cell__.tableHeaderRow; var printHeaders = this.internal.__cell__.printHeaders; // If this is not the first cell, we must change its position if (typeof lastCell.lineNumber !== "undefined") { if (lastCell.lineNumber === currentCell.lineNumber) { //Same line currentCell.x = (lastCell.x || 0) + (lastCell.width || 0); currentCell.y = lastCell.y || 0; } else { //New line if ( lastCell.y + lastCell.height + currentCell.height + margins.bottom > this.getPageHeight() ) { this.cellAddPage(); currentCell.y = margins.top; if (printHeaders && tableHeaderRow) { this.printHeaderRow(currentCell.lineNumber, true); currentCell.y += tableHeaderRow[0].height; } } else { currentCell.y = lastCell.y + lastCell.height || currentCell.y; } } } if (typeof currentCell.text[0] !== "undefined") { this.rect( currentCell.x, currentCell.y, currentCell.width, currentCell.height, printingHeaderRow === true ? "FD" : undefined ); if (currentCell.align === "right") { this.text( currentCell.text, currentCell.x + currentCell.width - padding, currentCell.y + padding, { align: "right", baseline: "top" } ); } else if (currentCell.align === "center") { this.text( currentCell.text, currentCell.x + currentCell.width / 2, currentCell.y + padding, { align: "center", baseline: "top", maxWidth: currentCell.width - padding - padding } ); } else { this.text( currentCell.text, currentCell.x + padding, currentCell.y + padding, { align: "left", baseline: "top", maxWidth: currentCell.width - padding - padding } ); } } this.internal.__cell__.lastCell = currentCell; return this; }); /** * Create a table from a set of data. * @name table * @function * @param {Integer} [x] : left-position for top-left corner of table * @param {Integer} [y] top-position for top-left corner of table * @param {Object[]} [data] An array of objects containing key-value pairs corresponding to a row of data. * @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost * @param {Object} [config.printHeaders] True to print column headers at the top of every page * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value * @param {Object} [config.margins] margin values for left, top, bottom, and width * @param {Object} [config.fontSize] Integer fontSize to use (optional) * @param {Object} [config.padding] cell-padding in pt to use (optional) * @param {Object} [config.headerBackgroundColor] default is #c8c8c8 (optional) * @param {Object} [config.headerTextColor] default is #000 (optional) * @param {Object} [config.rowStart] callback to handle before print each row (optional) * @param {Object} [config.cellStart] callback to handle before print each cell (optional) * @returns {jsPDF} jsPDF-instance */ jsPDFAPI.table = function(x, y, data, headers, config) { _initialize.call(this); if (!data) { throw new Error("No data for PDF table."); } config = config || {}; var headerNames = [], headerLabels = [], headerAligns = [], i, columnMatrix = {}, columnWidths = {}, column, columnMinWidths = [], j, tableHeaderConfigs = [], //set up defaults. If a value is provided in config, defaults will be overwritten: autoSize = config.autoSize || false, printHeaders = config.printHeaders === false ? false : true, fontSize = config.css && typeof config.css["font-size"] !== "undefined" ? config.css["font-size"] * 16 : config.fontSize || 12, margins = config.margins || Object.assign({ width: this.getPageWidth() }, NO_MARGINS), padding = typeof config.padding === "number" ? config.padding : 3, headerBackgroundColor = config.headerBackgroundColor || "#c8c8c8", headerTextColor = config.headerTextColor || "#000"; _reset.call(this); this.internal.__cell__.printHeaders = printHeaders; this.internal.__cell__.margins = margins; this.internal.__cell__.table_font_size = fontSize; this.internal.__cell__.padding = padding; this.internal.__cell__.headerBackgroundColor = headerBackgroundColor; this.internal.__cell__.headerTextColor = headerTextColor; this.setFontSize(fontSize); // Set header values if (headers === undefined || headers === null) { // No headers defined so we derive from data headerNames = Object.keys(data[0]); headerLabels = headerNames; headerAligns = headerNames.map(function() { return "left"; }); } else if (Array.isArray(headers) && typeof headers[0] === "object") { headerNames = headers.map(function(header) { return header.name; }); headerLabels = headers.map(function(header) { return header.prompt || header.name || ""; }); headerAligns = headers.map(function(header) { return header.align || "left"; }); // Split header configs into names and prompts for (i = 0; i < headers.length; i += 1) { columnWidths[headers[i].name] = headers[i].width * px2pt; } } else if (Array.isArray(headers) && typeof headers[0] === "string") { headerNames = headers; headerLabels = headerNames; headerAligns = headerNames.map(function() { return "left"; }); } if ( autoSize || (Array.isArray(headers) && typeof headers[0] === "string") ) { var headerName; for (i = 0; i < headerNames.length; i += 1) { headerName = headerNames[i]; // Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]} columnMatrix[headerName] = data.map(function(rec) { return rec[headerName]; }); // get header width this.setFont(undefined, "bold"); columnMinWidths.push( this.getTextDimensions(headerLabels[i], { fontSize: this.internal.__cell__.table_font_size, scaleFactor: this.internal.scaleFactor }).w ); column = columnMatrix[headerName]; // get cell widths this.setFont(undefined, "normal"); for (j = 0; j < column.length; j += 1) { columnMinWidths.push( this.getTextDimensions(column[j], { fontSize: this.internal.__cell__.table_font_size, scaleFactor: this.internal.scaleFactor }).w ); } // get final column width columnWidths[headerName] = Math.max.apply(null, columnMinWidths) + padding + padding; //have to reset columnMinWidths = []; } } // -- Construct the table if (printHeaders) { var row = {}; for (i = 0; i < headerNames.length; i += 1) { row[headerNames[i]] = {}; row[headerNames[i]].text = headerLabels[i]; row[headerNames[i]].align = headerAligns[i]; } var rowHeight = calculateLineHeight.call(this, row, columnWidths); // Construct the header row tableHeaderConfigs = headerNames.map(function(value) { return new Cell( x, y, columnWidths[value], rowHeight, row[value].text, undefined, row[value].align ); }); // Store the table header config this.setTableHeaderRow(tableHeaderConfigs); // Print the header for the start of the table this.printHeaderRow(1, false); } // Construct the data rows var align = headers.reduce(function(pv, cv) { pv[cv.name] = cv.align; return pv; }, {}); for (i = 0; i < data.length; i += 1) { if ("rowStart" in config && config.rowStart instanceof Function) { config.rowStart( { row: i, data: data[i] }, this ); } var lineHeight = calculateLineHeight.call(this, data[i], columnWidths); for (j = 0; j < headerNames.length; j += 1) { var cellData = data[i][headerNames[j]]; if ("cellStart" in config && config.cellStart instanceof Function) { config.cellStart( { row: i, col: j, data: cellData }, this ); } cell.call( this, new Cell( x, y, columnWidths[headerNames[j]], lineHeight, cellData, i + 2, align[headerNames[j]] ) ); } } this.internal.__cell__.table_x = x; this.internal.__cell__.table_y = y; return this; }; /** * Calculate the height for containing the highest column * * @name calculateLineHeight * @function * @param {Object[]} model is the line of data we want to calculate the height of * @param {Integer[]} columnWidths is size of each column * @returns {number} lineHeight * @private */ var calculateLineHeight = function calculateLineHeight(model, columnWidths) { var padding = this.internal.__cell__.padding; var fontSize = this.internal.__cell__.table_font_size; var scaleFactor = this.internal.scaleFactor; return Object.keys(model) .map(function(key) { var value = model[key]; return this.splitTextToSize( value.hasOwnProperty("text") ? value.text : value, columnWidths[key] - padding - padding ); }, this) .map(function(value) { return ( (this.getLineHeightFactor() * value.length * fontSize) / scaleFactor + padding + padding ); }, this) .reduce(function(pv, cv) { return Math.max(pv, cv); }, 0); }; /** * Store the config for outputting a table header * * @name setTableHeaderRow * @function * @param {Object[]} config * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell * except the lineNumber parameter is excluded */ jsPDFAPI.setTableHeaderRow = function(config) { _initialize.call(this); this.internal.__cell__.tableHeaderRow = config; }; /** * Output the store header row * * @name printHeaderRow * @function * @param {number} lineNumber The line number to output the header at * @param {boolean} new_page */ jsPDFAPI.printHeaderRow = function(lineNumber, new_page) { _initialize.call(this); if (!this.internal.__cell__.tableHeaderRow) { throw new Error("Property tableHeaderRow does not exist."); } var tableHeaderCell; printingHeaderRow = true; if (typeof this.internal.__cell__.headerFunction === "function") { var position = this.internal.__cell__.headerFunction( this, this.internal.__cell__.pages ); this.internal.__cell__.lastCell = new Cell( position[0], position[1], position[2], position[3], undefined, -1 ); } this.setFont(undefined, "bold"); var tempHeaderConf = []; for (var i = 0; i < this.internal.__cell__.tableHeaderRow.length; i += 1) { tableHeaderCell = this.internal.__cell__.tableHeaderRow[i].clone(); if (new_page) { tableHeaderCell.y = this.internal.__cell__.margins.top || 0; tempHeaderConf.push(tableHeaderCell); } tableHeaderCell.lineNumber = lineNumber; var currentTextColor = this.getTextColor(); this.setTextColor(this.internal.__cell__.headerTextColor); this.setFillColor(this.internal.__cell__.headerBackgroundColor); cell.call(this, tableHeaderCell); this.setTextColor(currentTextColor); } if (tempHeaderConf.length > 0) { this.setTableHeaderRow(tempHeaderConf); } this.setFont(undefined, "normal"); printingHeaderRow = false; }; })(jsPDF.API); </code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a> on Fri Jan 28 2022 16:38:20 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/polyfill.js"></script> <script src="scripts/linenumber.js"></script> </body> </html>