Skip to content

Commit dc91de0

Browse files
committed
Add x and y options to the plugin
1 parent 3954707 commit dc91de0

2 files changed

Lines changed: 34 additions & 23 deletions

File tree

examples/canvg_context2d/svg.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ <h1>SVG Logo</h1>
292292
<script type="text/javascript">
293293
var doc = new jsPDF()
294294
doc.svg(document.querySelector('.svg'), {
295-
x: 0,
296-
y: 0
295+
x: 10,
296+
y: 5
297297
})
298-
document.getElementById('result').setAttribute('src', doc.output('dataurlstring'))
298+
doc.rect(0, 0, 10, 5, 'F')
299+
doc.save('out')
300+
//document.getElementById('result').setAttribute('src', doc.output('dataurlstring'))
299301
</script>
300302

301303
</body>

plugins/svg.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
/**
2-
* jsPDF SVG Plugin
3-
*
4-
* Licensed under the MIT License.
5-
* http://opensource.org/licenses/mit-license
6-
*/
7-
8-
/**
9-
* Adds an SVG to the document
10-
*
11-
* @returns {jsPDF}
12-
* @name svg
13-
* @example
14-
* var doc = new jsPDF()
15-
* doc.svg(document.querySelector('.svg'))
16-
*/
17-
1+
/** @preserve
2+
jsPDF svg plugin
3+
Copyright (c) 2016 James Hall
4+
MIT license.
5+
*/
186
(function (jsPDFAPI) {
197
'use strict'
208

@@ -33,9 +21,28 @@
3321
configurable: true
3422
})
3523
}
36-
24+
/**
25+
* Adds an SVG to the document
26+
*
27+
* @returns {jsPDF}
28+
* @name svg
29+
* @example
30+
* var doc = new jsPDF()
31+
* doc.svg(document.querySelector('.svg'))
32+
*
33+
* // or to draw at a particular point on the page
34+
* doc.svg(document.querySelector('.svg'), { x: 10, y: 10 })
35+
*/
3736
jsPDFAPI.svg = function (element, options) {
38-
console.warn('Not implemented')
37+
if (typeof options === 'undefined') {
38+
options = {}
39+
}
40+
if (options.x === undefined) {
41+
options.x = 0
42+
}
43+
if (options.y === undefined) {
44+
options.y = 0
45+
}
3946
var svgContent = element.outerHTML
4047
var c = this.canvas
4148
var ctx = c.getContext('2d')
@@ -44,7 +51,9 @@
4451
ignoreMouse: true,
4552
ignoreAnimation: true,
4653
ignoreDimensions: true,
47-
useCORS: true
54+
useCORS: true,
55+
offsetX: options.x,
56+
offsetY: options.y
4857
})
4958
return this
5059
}

0 commit comments

Comments
 (0)