Skip to content

Commit

Permalink
Versão inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoargh committed May 18, 2015
1 parent 4015f6c commit a2b808d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# webdanfe
Gerador de DANFE em pdf utilizando o webservice do Webdanfe

### Instalação

`npm install webdanfe --save`

### Utilização

```javascript
var webdanfe = require('webdanfe'),
fs = require('fs'),
xml = fs.readFileSync('arquivoXmlDaNotaFiscl-procNfe.xml').toString();

webdanfe.gerarDanfe(xml, function(err, pdf) {
if(err) {
throw err;
}

fs.writeFileSync('danfe.pdf', pdf, {
encoding: 'binary'
});
});
```
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var request = require('request');

function gerarDanfe(xml, callback) {
var req = request.defaults({ jar: true });

req({
method: 'POST',
url: 'https://www.webdanfe.com.br/danfe/GeraDanfe.php',
headers: {
'accept-encoding': 'gzip, deflate',
'cache-control': 'no-cache',
'Referer': 'http://webdanfe.com.br/danfe/index.html',
},
followAllRedirects: true,
encoding: 'binary',
formData: {
arquivoXml: {
value: xml,
options: {
filename: 'arquivo.xml',
contentType: 'text/xml'
}
}
}
}, function(err, res, body) {
if(err) {
return callback(err);
}

callback(null, body);
});
};

module.exports.gerarDanfe = gerarDanfe;
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "webdanfe",
"version": "1.0.0",
"description": "Gerador de DANFE em pdf utilizando o webservice do Webdanfe",
"main": "index.js",
"scripts": {
"test": "exit 0;"
},
"repository": {
"type": "git",
"url": "https://github.com/renatoargh/webdanfe.git"
},
"keywords": [
"danfe",
"pdf",
"webdanfe",
"nfe",
"nota",
"fiscal",
"eletronica"
],
"author": "Renato Gama <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/renatoargh/webdanfe/issues"
},
"homepage": "https://github.com/renatoargh/webdanfe",
"dependencies": {
"request": "^2.55.0"
}
}

0 comments on commit a2b808d

Please sign in to comment.