Skip to content

Commit d7cb062

Browse files
committed
Added setPage() function - closes #108
1 parent 4c9c0ec commit d7cb062

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jspdf.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ var jsPDF = (function(global) {
177177
k, // Scale factor
178178
tmp,
179179
page = 0,
180+
currentPage,
180181
pages = [],
181182
pagedim = {},
182183
content = [],
@@ -210,7 +211,7 @@ var jsPDF = (function(global) {
210211
out = function(string) {
211212
if (outToPages) {
212213
/* set by beginPage */
213-
pages[page].push(string);
214+
pages[currentPage].push(string);
214215
} else {
215216
// +1 for '\n' that will be used to join 'content'
216217
content_length += string.length + 1;
@@ -644,6 +645,7 @@ var jsPDF = (function(global) {
644645
width : (pageWidth = Number(width) || pageWidth),
645646
height : (pageHeight = Number(height) || pageHeight)
646647
};
648+
_setPage(page);
647649
},
648650
_addPage = function() {
649651
beginPage.apply(this, arguments);
@@ -660,6 +662,13 @@ var jsPDF = (function(global) {
660662
}
661663
events.publish('addPage', { pageNumber : page });
662664
},
665+
_setPage = function(n) {
666+
if (n > 0 && n <= page) {
667+
currentPage = n;
668+
pageWidth = pagedim[n].width;
669+
pageHeight = pagedim[n].height;
670+
}
671+
},
663672
/**
664673
* Returns a document-specific font key - a label assigned to a
665674
* font name + font type combination at the time the font was added
@@ -914,6 +923,10 @@ var jsPDF = (function(global) {
914923
_addPage.apply(this, arguments);
915924
return this;
916925
};
926+
API.setPage = function() {
927+
_setPage.apply(this, arguments);
928+
return this;
929+
};
917930

918931
/**
919932
* Adds text to page. Supports adding multiline text when 'text' argument is an Array of Strings.

0 commit comments

Comments
 (0)