PDF merge

node v14.17.6
version: 1.0.0
endpointsharetweet
const PDFMerger = require("pdf-merger-js") const fs = require('fs') const fsPromises = require('fs').promises const fetch = require("node-fetch2") const url1 = 'https://www.thecampusqdl.com/uploads/files/pdf_sample_2.pdf' const url2 = 'http://fase.org.br/wp-content/uploads/2014/05/exemplo-de-pdf.pdf' exports.endpoint = async function(request, response) { response.setHeader("Content-Type", "application/pdf") response.setHeader("Content-Disposition", 'inline; filename=documento.pdf') const merge = new PDFMerger() const response1 = await fetch(url1) const response2 = await fetch(url2) const bufferFile1 = await response1.buffer() const bufferFile2 = await response2.buffer() merge.add(bufferFile1) merge.add(bufferFile2) const bufferMerged = await merge.saveAsBuffer() response.end(bufferMerged) }
Loading…

no comments

    sign in to comment