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

Completed Pdf Merge #915

Merged
merged 2 commits into from
Oct 11, 2024
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
1 change: 1 addition & 0 deletions projects/pdfTools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
7 changes: 7 additions & 0 deletions projects/pdfTools/commandsUsed.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize npm: npm init -y
install express: npm i express or npm install express
run server.js: node server.js
install nodemon for auto restart server.js: npm i -g nodemon
run server.js through nodemon: nodemon server.js
install multer: npm i multer (used for uploading files)
pdf merger : npm i pdf-merger-js
17 changes: 17 additions & 0 deletions projects/pdfTools/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const PDFMerger = require('pdf-merger-js');

var merger = new PDFMerger();

const mergePdfs = async (p1, p2) => {
await merger.add(p1); //merge all pages. parameter is the path to file and filename.
await merger.add(p2); // merge only page 2
// Time stamping
let d = new Date().getTime();
await merger.save(`public/${d}.pdf`); //save under given name and reset the internal document
return d;
// Export the merged PDF as a nodejs Buffer
// const mergedPdfBuffer = await merger.saveAsBuffer();
// fs.writeSync('merged.pdf', mergedPdfBuffer);
}

module.exports = {mergePdfs}
Loading
Loading