Skip to content

Commit

Permalink
Add jsPDF plugin Javascript & a few tweeks in jspdf.js to make it work.
Browse files Browse the repository at this point in the history
  • Loading branch information
lifof committed Mar 14, 2013
1 parent 9b30ba2 commit 8cb62e2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jspdf.js
Expand Up @@ -489,6 +489,7 @@ function jsPDF(/** String */ orientation, /** String */ unit, /** String */ form
putResourceDictionary()
out('>>')
out('endobj')
events.publish('postPutResources')
}
, putFonts = function() {
for (var fontKey in fonts) {
Expand Down Expand Up @@ -644,6 +645,7 @@ function jsPDF(/** String */ orientation, /** String */ unit, /** String */ form
// @TODO: Add zoom and layout modes
out('/OpenAction [3 0 R /FitH null]')
out('/PageLayout /OneColumn')
events.publish('putCatalog')
}
, putTrailer = function () {
out('/Size ' + (objectNumber + 1))
Expand Down
50 changes: 50 additions & 0 deletions jspdf.plugin.javascript.js
@@ -0,0 +1,50 @@
/** ====================================================================
* jsPDF JavaScript plugin
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ====================================================================
*/

(function (jsPDFAPI) {
'use strict';
var jsNamesObj, jsJsObj, text;
jsPDFAPI.addJS = function (txt) {
text = txt;
this.internal.events.subscribe(
'postPutResources',
function (txt) {
jsNamesObj = this.internal.newObject();
this.internal.write('<< /Names [(EmbeddedJS) ' + (jsNamesObj + 1) + ' 0 R] >>', 'endobj');
jsJsObj = this.internal.newObject();
this.internal.write('<< /S /JavaScript /JS (', text, ') >>', 'endobj');
}
);
this.internal.events.subscribe(
'putCatalog',
function () {
if (jsNamesObj !== undefined && jsJsObj !== undefined) {
this.internal.write('/Names <</JavaScript ' + jsNamesObj + ' 0 R>>');
}
}
);
return this;
};
})(jsPDF.API);

0 comments on commit 8cb62e2

Please sign in to comment.