Skip to content

Commit

Permalink
Add Data URI output support to jsPDF rather than just in the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hall committed May 2, 2009
1 parent ed71a90 commit fc03b45
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
48 changes: 24 additions & 24 deletions examples/basic.htm
Expand Up @@ -52,10 +52,8 @@ <h2>Simple Two-page Text Document</h2>
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;</pre>
// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo1()">Run Code</a>

<h2>Different font sizes</h2>
Expand All @@ -67,10 +65,8 @@ <h2>Different font sizes</h2>
doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;</pre>
// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo2()">Run Code</a>


Expand All @@ -88,10 +84,8 @@ <h2>Adding metadata</h2>
creator: 'MEEE'
});

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;</pre>
// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo3()">Run Code</a>


Expand All @@ -105,10 +99,8 @@ <h2>Adding metadata</h2>
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
// Output as Data URI
doc.output('datauri');
}

function demo2() {
Expand All @@ -120,10 +112,8 @@ <h2>Adding metadata</h2>
doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
// Output as Data URI
doc.output('datauri');
}

function demo3() {
Expand All @@ -140,12 +130,22 @@ <h2>Adding metadata</h2>
creator: 'MEEE'
});

// Making Data URI
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
// Output as Data URI
doc.output('datauri');
}

function demo4() {
doc = new jsPDF();
doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');

// Output as Data URI
doc.output('datauri');
}

</script>

Expand Down
10 changes: 8 additions & 2 deletions jspdf.js
Expand Up @@ -280,9 +280,15 @@ var jsPDF = function(){
addImage: function(imageData, format, x, y, w, h) {

},
output: function() {
output: function(type, options) {
endDocument();
return buffer;
if(type == undefined) {
return buffer;
}
if(type == 'datauri') {
document.location.href = 'data:application/pdf;base64,' + Base64.encode(buffer);
}
// @TODO: Add different output options
},
setFontSize: function(size) {
fontSize = size;
Expand Down

0 comments on commit fc03b45

Please sign in to comment.