From 98ae7317b865604eda6639fc43890afcb1adde94 Mon Sep 17 00:00:00 2001 From: Ben Gribaudo Date: Wed, 5 Mar 2014 13:37:12 -0600 Subject: [PATCH] Hooking svgElementToPdf into jsPDF as a plug-in. With this change, code like this becomes possible: var pdf = new jsPDF(); pdf.addSVG(svgData, 25, 50, options); In comparison, currently something along the lines of the below is required: var pdf = new jsPDF(); svgElementToPdf(svgData, pdf, options); The method name "addSVG" conflicts with https://github.com/MrRio/jsPDF/blob/master/jspdf.plugin.sillysvgrenderer.js. This isn't a problem so long as we presume that the user will only use one SVG rendering plugin at a time. --- jspdf.plugin.svgToPdf.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jspdf.plugin.svgToPdf.js b/jspdf.plugin.svgToPdf.js index 54dc56001..21185d43d 100644 --- a/jspdf.plugin.svgToPdf.js +++ b/jspdf.plugin.svgToPdf.js @@ -666,4 +666,19 @@ var svgElementToPdf = function(element, pdf, options) { 2 * numbs[numbs.length - 1] - numbs[numbs.length - 3]]; } return previous_element.point - } \ No newline at end of file + } + +(function(jsPDFAPI) { +'use strict'; + + jsPDFAPI.addSVG = function(element, x, y, options) { + 'use strict' + + options = (typeof(options) == 'undefined' ? {} : options); + options.x_offset = x; + options.y_offset = y; + + svgElementToPdf(element, this, options); + return this; + }; +})(jsPDF.API);