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

Update pdf2svg.js #8461

Closed
wants to merge 4 commits into from
Closed
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
24 changes: 11 additions & 13 deletions examples/node/pdf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ var data = new Uint8Array(fs.readFileSync(pdfPath));
// Dumps svg outputs to a folder called svgdump
function writeToFile(svgdump, pageNum) {
var name = getFileNameFromPath(pdfPath);
fs.mkdir('./svgdump/', function(err) {
if (!err || err.code === 'EEXIST') {
fs.writeFile('./svgdump/' + name + "-" + pageNum + '.svg', svgdump,
function(err) {
if (err) {
console.log('Error: ' + err);
} else {
console.log('Page: ' + pageNum);
}
});
}
});
if (!fs.existsSync('./svgdump/')) {
fs.mkdirSync('./svgdump/');
}

try {
fs.writeFileSync('./svgdump/' + name + '-' + pageNum + '.svg', svgdump, 'utf-8');
console.log('Page: ' + pageNum);
} catch(err) {
console.log('Error: ' + err);
}
}

// Get filename from the path
Expand Down Expand Up @@ -70,7 +68,7 @@ pdfjsLib.getDocument({
writeToFile(svgDump, pageNum);
});
});
})
});
};

for (var i = 1; i <= numPages; i++) {
Expand Down