Skip to content

Commit aed3044

Browse files
committed
Possible to add filled rectangles
1 parent 4896947 commit aed3044

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

examples/basic.htm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ <h2>Example of user input</h2>
157157
doc.output('datauri');</pre>
158158
<a href="javascript:demo6()">Run Code</a>
159159

160+
<h2>Draw example: rectangles / squares</h2>
161+
<pre>var doc = new jsPDF();
162+
163+
doc.rect(20, 20, 10, 10); // empty square
164+
165+
doc.rect(40, 20, 10, 10, 'F'); // filled square
166+
167+
doc.setDrawColor(255,0,0);
168+
doc.rect(60, 20, 10, 10); // empty red square
169+
170+
doc.setDrawColor(255,0,0);
171+
doc.rect(80, 20, 10, 10, 'FD'); // filled square with red borders
172+
173+
doc.setDrawColor(0);
174+
doc.setFillColor(255,0,0);
175+
doc.rect(100, 20, 10, 10, 'F'); // filled red square
176+
177+
doc.setDrawColor(0);
178+
doc.setFillColor(255,0,0);
179+
doc.rect(120, 20, 10, 10, 'FD'); // filled red square with black borders
180+
181+
// Output as Data URI
182+
doc.output('datauri');</pre>
183+
<a href="javascript:demo7()">Run Code</a>
160184

161185

162186
<script type="text/javascript">
@@ -275,6 +299,31 @@ <h2>Example of user input</h2>
275299

276300
}
277301

302+
function demo7() {
303+
var doc = new jsPDF();
304+
305+
doc.rect(20, 20, 10, 10); // empty square
306+
307+
doc.rect(40, 20, 10, 10, 'F'); // filled square
308+
309+
doc.setDrawColor(255,0,0);
310+
doc.rect(60, 20, 10, 10); // empty red square
311+
312+
doc.setDrawColor(255,0,0);
313+
doc.rect(80, 20, 10, 10, 'FD'); // filled square with red borders
314+
315+
doc.setDrawColor(0);
316+
doc.setFillColor(255,0,0);
317+
doc.rect(100, 20, 10, 10, 'F'); // filled red square
318+
319+
doc.setDrawColor(0);
320+
doc.setFillColor(255,0,0);
321+
doc.rect(120, 20, 10, 10, 'FD'); // filled red square with black borders
322+
323+
// Output as Data URI
324+
doc.output('datauri');
325+
}
326+
278327
</script>
279328

280329

jspdf.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ var jsPDF = function(orientation, unit, format){
428428
return _jsPDF;
429429
},
430430
setDrawColor: function(r,g,b) {
431+
var color;
432+
if ((r===0 && g===0 && b===0) || (typeof g === 'undefined')) {
433+
color = sprintf('%.3f G', r/255);
434+
} else {
435+
color = sprintf('%.3f %.3f %.3f RG', r/255, g/255, b/255);
436+
}
437+
out(color);
438+
return _jsPDF;
439+
},
440+
setFillColor: function(r,g,b) {
431441
var color;
432442
if ((r===0 && g===0 && b===0) || (typeof g === 'undefined')) {
433443
color = sprintf('%.3f g', r/255);

0 commit comments

Comments
 (0)