galkahana / HummusJS

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

getImageDimensions() doesn't work with buffer as a stream #354

Closed silexboy closed 5 years ago

silexboy commented 5 years ago

Hi. I'm trying to merge PDF and image files from S3 to a single PDF document using PDFRStreamForBuffer() and memory-streams package for the writer.

        const writer = new streams.WritableStream();
        const pdfWriter = hummus.createWriter(new hummus.PDFStreamForResponse(writer), {
           compress: false,
           log: '...'
        });

    const {Body: data} = await s3.getObject(...).promise();
        ...

    if (type === 'pdf') {
        pdfWriter.appendPDFPagesFromPDF(new hummus.PDFRStreamForBuffer(data)); // OK
    }
    else if (['jpg', 'jpeg', 'png'].includes(type)) {
        const stream = new hummus.PDFRStreamForBuffer(data);
        const dimensions = pdfWriter.getImageDimensions(stream);  // NOT OK
        ...

As you see, the similarly created stream is good because appendPDFPagesFromPDF() works good. The problem is that getImageDimensions() doesn't work with such stream (and works well with the same image as local file, so the image is also ok).

I would be happy if somebody advice what's wrong here.

diegoolavarria commented 5 years ago

@silexboy do you manage to do this task? I have to do exactly the same and I'm stuck with trying to add the images to the final pdf document

goatandsheep commented 5 years ago

and createImageXObjectFromJPG doesn't accept buffer either

goatandsheep commented 5 years ago

I've placed a bounty on this issue

willy2dg commented 5 years ago

@goatandsheep Could be enough by creating a getStreamImageDimensions method or allowing getImageDimensions to accept a stream ?

goatandsheep commented 5 years ago

@willy2dg I do want createImageXObjectFromJPG to accept buffer, but the bounty is just for getImageDimensions so yes.

willy2dg commented 5 years ago

Ok @goatandsheep , I will be checking it . Anyways createImageXObjectFromJPG seems to be accepting a stream as input.

willy2dg commented 5 years ago

@goatandsheep I sent a PR. The steps to run it are the following :

goatandsheep commented 5 years ago

Weird: npm install --build-from-source gave me 165 warnings

willy2dg commented 5 years ago

I got warning too, but they was there before my changes.

willy2dg commented 5 years ago

@galkahana is this able to be merged ? @goatandsheep can we close the issue ?

goatandsheep commented 5 years ago

@willy2dg I want the PR to be merged before we can close the issue. @galkahana I setup a ticket to figure out what to do re Travis issues (see link in PR)

goatandsheep commented 5 years ago

Hi @silexboy can we close the issue? The PR is green and will be merged as soon as @galkahana sees it. @willy2dg deserves the bounty.

willy2dg commented 5 years ago

The only activity in the @silexboy account is to open this issue, so I doubt it responds. @galkahana could you close this ?

galkahana commented 5 years ago

Is this ok?

willy2dg commented 5 years ago

Yes, thanks @galkahana . @goatandsheep I sent a bounty claim, please accept it when possible.

galkahana commented 5 years ago

Merged the pr too

galkahana commented 5 years ago

published as 106