Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf-maker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf-maker - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test.js

59

index.js

@@ -6,4 +6,4 @@ var phantom = require("node-phantom-simple");

var fs = require('fs');
var _session;
function pdfMaker(template, data, pdfPath, option) {

@@ -29,3 +29,3 @@

generatePdf(html, pdfPath, option);
createSession(html, pdfPath, option);

@@ -57,3 +57,3 @@ });

var html = ejs.render(file, data);
generatePdf(html, pdfPath, option);
createSession(html, pdfPath, option);
});

@@ -66,6 +66,21 @@

function generatePdf(html, pdfPath, option) {
phantom.create({
path: phantomjs.path
}, function (err, session) {
function createSession(html, pdfPath, option) {
if (_session) {
createPage(_session, html, pdfPath, option);
} else {
phantom.create({
path: phantomjs.path
}, function (err, session) {
if (err) {
throw err;
}
_session = session;
createPage(session, html, pdfPath, option)
});
}
}
function createPage (session, html, pdfPath, option) {
session.createPage(function (err, page) {
if (err) {

@@ -75,27 +90,21 @@ throw err;

session.createPage(function (err, page) {
_.forEach(option, function (val, key) {
page.set(key, val);
});
page.set('content', html, function (err) {
if (err) {
throw err;
}
});
_.forEach(option, function (val, key) {
page.set(key, val);
});
page.set('content', html, function (err) {
if (err) {
page.onLoadFinished = function (status) {
page.render(pdfPath, function (error) {
page.close();
page = null;
if (error) {
throw err;
}
});
page.onLoadFinished = function (status) {
page.render(pdfPath, function (error) {
page.close();
page = null;
if (error) {
throw err;
}
});
};
})
};
});

@@ -102,0 +111,0 @@ }

{
"name": "pdf-maker",
"version": "0.0.1",
"version": "0.0.2",
"description": "easy pdf generation using phantom.js",

@@ -5,0 +5,0 @@ "main": "index.js",

# pdf-maker
An easy way to generate pdf files from ejs templates or html files
#Usage
```
##Install
```js
npm i --save pdf-maker
```
#For generating pdf from ejs templates
##Usage
```
var pdfMaker = require('pdf-maker');
##For generating pdf from ejs templates
var template = 'path/to/ejsTemplate.ejs';
var data = {
name: 'node.js'
```js
var pdfMaker = require('pdf-maker');
var template = 'path/to/ejsTemplate.ejs';
var data = {
name: 'node.js'
};
var pdfPath = '/path/of/pdf/file.pdf';
var option = {
{
paperSize: {
format: 'A4',
orientation: 'portrait',
border: '1.8cm'
}
};
var pdfPath = '/path/of/pdf/file.pdf';
var option = {
{
paperSize: {
format: 'A4',
orientation: 'portrait',
border: '1.8cm'
}
};
};
};
pdfMaker(template, data, pdfPath, option);
pdfMaker(template, data, pdfPath, option);
```

@@ -38,25 +41,25 @@

#For generating pdf from html files.
##For generating pdf from html files.
```
var pdfMaker = require('pdf-maker');
```js
var pdfMaker = require('pdf-maker');
var template = 'path/to/htmlFile.html';
var pdfPath = '/path/of/pdf/file.pdf';
var option = {
{
paperSize: {
format: 'A4',
orientation: 'portrait',
border: '1.8cm'
}
};
var template = 'path/to/htmlFile.html';
var pdfPath = '/path/of/pdf/file.pdf';
var option = {
{
paperSize: {
format: 'A4',
orientation: 'portrait',
border: '1.8cm'
}
};
};
pdfMaker(template, pdfPath, option);
pdfMaker(template, pdfPath, option);
```
#Roadmap
##Roadmap
Adding test cases.
Removing external dependencies.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc