Skip to content

Commit

Permalink
Make this almost usable as npm module
Browse files Browse the repository at this point in the history
  • Loading branch information
skmp committed Nov 25, 2014
1 parent ee2aec2 commit b800717
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 20 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
node-msoffice-pdf
=================

Uses edge.js + a bit of C# code to export office documents
as pdfs, using Office remoting.

Depends on office 2013 + windows.

## Installation

npm install node-msoffice-pdf

## Usage

var msopdf = require('node-msoffice-pdf');

msopdf(null, function(office) {

/*
There's a queue on the background thread on C#, so adding things is non-blocking.
*/
office.word({input: "infile.doc", output: "outfile.pdf"}, function(error, pdf) {
if (error) {
/*
Sometimes things go wrong, re-trying usually gets the job done
Could not get remoting to repiably not crash on my laptop
*/
console.log("Woops", error);
} else {
console.log("Saved to", pdf);
}
});
office.excel({input: "infile.xlsx", output: "outfile.pdf"}, function(error, pdf) {
if (error) {
console.log("Woops", error);
} else {
console.log("Saved to", pdf);
}
});
office.powerPoint({input: "infile.pptx", output: "outfile.pdf"}, function(error, pdf) {
if (error) {
console.log("Woops", error);
} else {
console.log("Saved to", pdf);
}
});
/*
Word/PowerPoint/Excel remain open (for faster batch conversion)
To clean them up, and to wait for the queue to finish processing
*/
office.close(null, function(error) {
if (error) {
console.log("Finished & closed");
} else {
console.log("Saved to", pdf);
}
});
});

## Contributing

Github for issues & PR, MIT license, yada yada

## Release History

* 0.0.2 (Mostly?) working prototype
12 changes: 12 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var edge = require('edge');

module.exports = edge.func({
source: 'office.cs',
references: [
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.Word\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.Word.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.Excel\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.Excel.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.PowerPoint\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.PowerPoint.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Office\\15.0.0.0__71e9bce111e9429c\\Office.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Vbe.Interop\\15.0.0.0__71e9bce111e9429c\\Microsoft.Vbe.Interop.dll'
],
});
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.0.1",
"description": "Saves docs as pdfs",
"author": "Stefanos Kornilios Mitsis Poiitidis ([email protected])",
"main": "lib.js",
"scripts": {
"test": "node testrunner.js"
},
"repository": {
"type": "git",
"url": "https://github.com/skmp/node-msoffice-pdf"
Expand All @@ -12,8 +16,10 @@
"pdf"
],
"dependecies": {
"edge" : "*",
"node-uuid" : "*"
"edge" : "*"
},
"devDependencies": {
"node-uuid" : "*"
}
"license": "MIT"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 9 additions & 18 deletions app.js → testrunner.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
var edge = require('edge');
var mso_pdf = require('./lib');
var uuid = require('node-uuid');

var Office = edge.func({
source: 'office.cs',
references: [
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.Word\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.Word.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.Excel\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.Excel.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Office.Interop.PowerPoint\\15.0.0.0__71e9bce111e9429c\\Microsoft.Office.Interop.PowerPoint.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Office\\15.0.0.0__71e9bce111e9429c\\Office.dll',
'C:\\Windows\\assembly\\GAC_MSIL\\Microsoft.Vbe.Interop\\15.0.0.0__71e9bce111e9429c\\Microsoft.Vbe.Interop.dll'
],
});


var okay = 0, errors = 0;

Office(null, function (error, office) {
mso_pdf(null, function (error, office) {
if (error) {
console.log("Failed to open word");
throw error;
console.log("Failed to init");
return;
}

for (var i = 0; i< 45; i++) {
office.word({
input: "tests\\test.docx",
input: "testcases\\test.docx",
output: "output.doc." + uuid.v4() + ".pdf"
}, function (error, pdf) {
if (error) {
Expand All @@ -36,7 +27,7 @@ Office(null, function (error, office) {
});

office.excel({
input: "tests\\test.xlsx",
input: "testcases\\test.xlsx",
output: "output.xls." + uuid.v4() + ".pdf"
}, function (error, pdf) {
if (error) {
Expand All @@ -50,7 +41,7 @@ Office(null, function (error, office) {
});

office.powerPoint({
input: "tests\\test.pptx",
input: "testcases\\test.pptx",
output: "output.ppt." + uuid.v4() + ".pdf"
}, function (error, pdf) {
if (error) {
Expand All @@ -69,4 +60,4 @@ Office(null, function (error, office) {
office.close(null, function() {
console.log("Office finished & closed, ", okay, errors, errors*100/(okay+errors));
});
})
})

0 comments on commit b800717

Please sign in to comment.