Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[nodejs] Merge PDFs using pdf-lib

https://github.com/Hopding/pdf-lib

const { PDFDocument } = require('pdf-lib')

// files = [{ fileName: 'test1.pdf, content: arraybuffer },{ fileName: 'test2.pdf, content: arraybuffer }]

mergePdfs: async function (files) {
        try {
            const mergedPdf = await PDFDocument.create()

            for (let file of files) {
                const pdf = await PDFDocument.load(file.content)
                const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices())
                copiedPages.forEach((page) => mergedPdf.addPage(page))
            }

            const mergedPdfFile = await mergedPdf.save()
            const buffer = Buffer.from(mergedPdfFile)
            return await buffer.toString('base64') // return as buffer or base64 encoded file
        } catch (err) {
            console.error(err.message)
        }
}

[Git] Branch Commands

https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

https://git-scm.com/book/en/v2/Git-Branching-Branch-Management

# create branch, switch to it and commit changes
git checkout -b hotfix
git commit -a -m 'Commit changes for fix'

# go back to main branch
git checkout main

# merge branch changes to main
git merge hotfix

# delete branch after merging, as it is not needed anymore
git branch -d hotfix

# check on which branch your are
git status

# list all branches including last commit on each branch
git branch -vv

# check which branches are already merged and which are not
git branch --merged
git branch --no-merged

# rename branche locally
git branch --move bad-branch-name corrected-branch-name

# push new name to github/gitlab
git push --set-upstream origin corrected-branch-name

# displays local and remote branches
git branch --all

# delete remote branch
git push origin --delete bad-branch-name

# push branch to remote 
git push origin hotfix