Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional output type #147

Merged
merged 2 commits into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Quickly and easily create PowerPoint presentations with a few simple JavaScript
- [Saving a Presentation](#saving-a-presentation)
- [Client Browser](#client-browser)
- [Node.js](#nodejs-1)
- [Specific output type](#specific-output-type)
- [Presentations: Adding Objects](#presentations-adding-objects)
- [Adding Charts](#adding-charts)
- [Chart Types](#chart-types)
Expand Down Expand Up @@ -287,7 +288,17 @@ pptx.save( 'Node_Demo', saveCallback );
pptx.save( 'http', streamCallback );
```

Saving multiple Presentations:
### Specific output type
When a save callback function is specified (no matter whether on a client or in Node), an extra parametr can be passed – `outputType`.
This parameter accepts any value of [the JSzip supported formats](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html). For example:

```javascript
pptx.save( 'whatever', function(content) {
console.log(content);
}, 'base64');
```

Saving multiple Presentations:
* In order to generate a new, unique Presentation just create a new instance of the library then add objects and save as normal.

```javascript
Expand Down
14 changes: 10 additions & 4 deletions dist/pptxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ var PptxGenJS = function(){
var DEF_SLIDE_MARGIN_IN = [0.5, 0.5, 0.5, 0.5]; // TRBL-style
var DEF_CHART_GRIDLINE = { color: "888888", style: "solid", size: 1 };

/** @see https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html */
var ALLOWED_OUTPUT_TYPES = ['base64', 'binarystring', 'uint8array', 'arraybuffer', 'blob', 'nodebuffer'];

// A: Create internal pptx object
var gObjPptx = {};

Expand Down Expand Up @@ -158,7 +161,7 @@ var PptxGenJS = function(){
/**
* DESC: Export the .pptx file
*/
function doExportPresentation(callback) {
function doExportPresentation(callback, outputType) {
var arrChartPromises = [];
var intSlideNum = 0, intRels = 0;

Expand Down Expand Up @@ -422,7 +425,10 @@ var PptxGenJS = function(){
Promise.all( arrChartPromises )
.then(function(arrResults){
var strExportName = ((gObjPptx.fileName.toLowerCase().indexOf('.ppt') > -1) ? gObjPptx.fileName : gObjPptx.fileName+gObjPptx.fileExtn);
if ( NODEJS ) {
if ( outputType && ALLOWED_OUTPUT_TYPES.indexOf(outputType) >= 0) {
zip.generateAsync({ type: outputType }).then(callback);
}
else if ( NODEJS ) {
if ( callback ) {
if ( strExportName.indexOf('http') == 0 ) {
zip.generateAsync({type:'nodebuffer'}).then(function(content){ callback(content); });
Expand Down Expand Up @@ -2830,7 +2836,7 @@ var PptxGenJS = function(){
* Export the Presentation to an .pptx file
* @param {string} [inStrExportName] - Filename to use for the export
*/
this.save = function save(inStrExportName, callback) {
this.save = function save(inStrExportName, callback, outputType) {
var intRels = 0, arrRelsDone = [];

// STEP 1: Set export title (if any)
Expand Down Expand Up @@ -2864,7 +2870,7 @@ var PptxGenJS = function(){
});

// STEP 3: Export now if there's no images to encode (otherwise, last async imgConvert call above will call exportFile)
if ( intRels == 0 ) doExportPresentation(callback);
if ( intRels == 0 ) doExportPresentation(callback, outputType);
};

/**
Expand Down