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

Getting "toBuffer() Stream yields empty buffer" error for PDF Conversion #800

Open
rbjoshi opened this issue Mar 4, 2020 · 2 comments
Open

Comments

@rbjoshi
Copy link

rbjoshi commented Mar 4, 2020

I am getting the below error while converting to PDF:

Error: Stream yields empty buffer

Code is below:

      const readable = toStream(data.Body);
      gm(readable)
      .toBuffer('PDF', (err, buffer) => {
        if(err) {
          logger.error('attachment to pdf buffer', { fileName: doc.fileName })
          return rj(new Error(err)); 
        }

        docs.push({
          docType: doc.type == 2 ? 'Doc1' : (doc.type == 7 ? 'Doc2' : 'Other'),
          filename: doc.fileName.replace(/(\.jpe?g)|(\.png)/i, '.pdf'),
          type: 'application/pdf',
          content: buffer.toString('base64')
        })
        if(doc.type == 7) {
          // Push a second doc for the confirmation page
          docs.push({
            docType: 'CONF_PAGE',
            filename: doc.fileName.replace(/(\.jpe?g)|(\.png)/i, '.pdf'),
            type: 'application/pdf',
            content: buffer.toString('base64')
           })
        }

        rs(docs);
      });

I am getting the error on gm().toBuffer() line

error logs looks like this

Error: Stream yields empty buffer
at Socket. (C:\codebase\onboarding-api\node_modules\gm\lib\command.js:57:17)
at Socket.emit (events.js:203:15)
at Socket.EventEmitter.emit (domain.js:466:23)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

Need some insight here.

@mannu2612
Copy link

@rbjoshi Were you able to solve this?

@Bersaelor
Copy link

@rbjoshi when you use toBuffer underlying errors are silently swallowed. For example, any issue calling the imagemagick command line utility will not show.
In order to get those, you'll have to use .write(fileImg, (error) => { for testing.

I created an issue about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants