galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

Segmentation Fault while Creating Buffers in Dockerized App #320

Closed tjohnsonfs closed 5 years ago

tjohnsonfs commented 5 years ago

Hello, Based on #125, we have the following code that creates a single pdf from multiple pdfs. Running locally or deployed to Heroku, this code works as expected.

We have Docker containers built on Alpine linux that run this code and give a Segmentation Fault on the line that reads pdfWriter.appendPDFPagesFromPDF(pdfStream). I have also built the same container on a base of the node:8 Dockerfile, and it seems to work as expected.

Any help is appreciated!

const hummus = require('hummus')
const streams = require('memory-streams')

function pdfmerge (pdfBuffers) {
  return new Promise((resolve, reject) => {
    const writer = new streams.WritableStream()
    const pdfWriter = hummus.createWriter(new hummus.PDFStreamForResponse(writer))

    pdfBuffers.map(data => {
      const pdfStream = new hummus.PDFRStreamForBuffer(data)
      pdfWriter.appendPDFPagesFromPDF(pdfStream)
    })

    pdfWriter.end()

    return resolve(writer.toBuffer())
  })
}

module.exports = pdfmerge
galkahana commented 5 years ago

i'd start with assuming that the install is fine, and check the input data. try dumping the buffers to a file and then work with the file. if doesn't work...send yourself the file an open it in a viewer...to see that this is a valid PDF. If it's ok with a file...time to check PDFRStreamForBuffer.

etc.

tjohnsonfs commented 5 years ago

Thanks for the response!

We were able to solve this problem by including make, gcc, g++, and python in our Alpine container and running npm rebuild hummus --build-from-source.