@param orientation One of "portrait" or "landscape" (or shortcuts "p" (Default), "l")
@param unit Measurement unit to be used when coordinates are specified. One of "pt" (points), "mm" (Default), "cm", "in"
@param format One of 'a0', 'a1', 'a2', 'a3', 'a4' (Default) etc to 'a10', 'b0' to 'b10', 'c0' to 'c10', 'letter', 'government-letter', 'legal', 'junior-legal', 'ledger' or 'tabloid'
Adds (and transfers the focus to) new page to the PDF document.
@function
@returns {jsPDF}
@methodOf jsPDF#
@name addPage
*/
API.addPage=function(){
_addPage();
returnthis;
};
/**
Adds text to page. Supports adding multiline text when 'text' argument is an Array of Strings.
@function
@param {String|Array} text String or array of strings to be added to the page. Each line is shifted one line down per font, spacing settings declared before this call.
@param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
@param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
@param {Object} flags Collection of settings signalling how the text must be encoded. Defaults are sane. If you think you want to pass some flags, you likely can read the source.
@returns {jsPDF}
@methodOf jsPDF#
@name text
*/
API.text=function(text,x,y,flags){
/**
* Inserts something like this into PDF
BT
/F1 16 Tf % Font name + size
16 TL % How many units down for next line in multiline text
0 g % color
28.35 813.54 Td % position
(line one) Tj
T* (line two) Tj
T* (line three) Tj
ET
*/
varundef,_first,_second,_third,newtext,str,i;
// Pre-August-2012 the order of arguments was function(x, y, text, flags)
// in effort to make all calls have similar signature like
// function(data, coordinates... , miscellaneous)
// this method had its args flipped.
// code below allows backward compatibility with old arg order.
if(typeoftext==='number'){
_first=y;
_second=text;
_third=x;
text=_first;
x=_second;
y=_third;
}
// If there are any newlines in text, we assume
// the user wanted to print multiple lines, so break the
// text up into an array. If the text is already an array,
// we assume the user knows what they are doing.
if(typeoftext==='string'&&text.match(/[\n\r]/)){
text=text.split(/\r\n|\r|\n/g);
}
if(typeofflags==='undefined'){
flags={'noBOM':true,'autoencode':true};
}else{
if(flags.noBOM===undef){
flags.noBOM=true;
}
if(flags.autoencode===undef){
flags.autoencode=true;
}
}
if(typeoftext==='string'){
str=pdfEscape(text,flags);
}elseif(textinstanceofArray){/* Array */
// we don't want to destroy original text array, so cloning it
newtext=text.concat();
// we do array.join('text that must not be PDFescaped")
// thus, pdfEscape each component separately
for(i=newtext.length-1;i!==-1;i--){
newtext[i]=pdfEscape(newtext[i],flags);
}
str=newtext.join(") Tj\nT* (");
}else{
thrownewError('Type of text must be string or Array. "'+text+'" is not recognized.');
}
// Using "'" ("go next line and render text" mark) would save space but would complicate our rendering code, templates
// BT .. ET does NOT have default settings for Tf. You must state that explicitely every time for BT .. ET
// if you want text transformation matrix (+ multiline) to work reliably (which reads sizes of things from font declarations)
// Thus, there is NO useful, *reliable* concept of "default" font for a page.
// The fact that "default" (reuse font used before) font worked before in basic cases is an accident
// - readers dealing smartly with brokenness of jsPDF's markup.
out(
'BT\n/'+
activeFontKey+''+activeFontSize+' Tf\n'+// font face, style, size
(activeFontSize*lineHeightProportion)+' TL\n'+// line spacing
textColor+
'\n'+f2(x*k)+''+f2((pageHeight-y)*k)+' Td\n('+
str+
') Tj\nET'
);
returnthis;
};
API.line=function(x1,y1,x2,y2){
out(
f2(x1*k)+''+f2((pageHeight-y1)*k)+' m '+
f2(x2*k)+''+f2((pageHeight-y2)*k)+' l S'
);
returnthis;
};
/**
Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates.
All data points in `lines` are relative to last line origin.
`x`, `y` become x1,y1 for first line / curve in the set.
For lines you only need to specify [x2, y2] - (ending point) vector against x1, y1 starting point.
For bezier curves you need to specify [x2,y2,x3,y3,x4,y4] - vectors to control points 1, 2, ending point. All vectors are against the start of the curve - x1,y1.
@example .lines([[2,2],[-2,2],[1,1,2,2,3,3],[2,1]], 212,110, 10) // line, line, bezier curve, line
@param {Array} lines Array of *vector* shifts as pairs (lines) or sextets (cubic bezier curves).
@param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
@param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
@param {Number} scale (Defaults to [1.0,1.0]) x,y Scaling factor for all vectors. Elements can be any floating number Sub-one makes drawing smaller. Over-one grows the drawing. Negative flips the direction.
@param {String} style One of 'S' (the default), 'F', 'FD' or 'DF'. 'S' draws just the curve. 'F' fills the region defined by the curves. 'DF' or 'FD' draws the curves and fills the region.
@param {Boolean} closed If true, the path is closed with a straight line from the end of the last curve to the starting point.
// or they can attach an array with [callback, runonce_flag]
// that's what the "apply" magic is for below.
eventname=newEvents[i][0];
handler_and_args=newEvents[i][1];
events.subscribe.apply(
events,
[eventname].concat(
typeofhandler_and_args==='function'?
[handler_and_args]:
handler_and_args
)
);
}
}(events,jsPDF.API.events));
}else{
API[plugin]=jsPDF.API[plugin];
}
}
}
/////////////////////////////////////////
// continuing initilisation of jsPDF Document object
/////////////////////////////////////////
// Add the first page automatically
addFonts();
activeFontKey='F1';
_addPage();
events.publish('initialized');
returnAPI;
}
/**
jsPDF.API is a STATIC property of jsPDF class.
jsPDF.API is an object you can add methods and properties to.
The methods / properties you add will show up in new jsPDF objects.
One property is prepopulated. It is the 'events' Object. Plugin authors can add topics, callbacks to this object. These will be reassigned to all new instances of jsPDF.
Examples:
jsPDF.API.events['initialized'] = function(){ 'this' is API object }
jsPDF.API.events['addFont'] = function(added_font_object){ 'this' is API object }
@static
@public
@memberOf jsPDF
@name API
@example
jsPDF.API.mymethod = function(){
// 'this' will be ref to internal API object. see jsPDF source
// , so you can refer to built-in methods like so: