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

Corrupt target PDF embedding source PDF #205

Closed Bastian1975 closed 6 years ago

Bastian1975 commented 6 years ago

I get a corrupt PDF with the errors

galkahana commented 6 years ago

i'm gonna need some more details of what you are trying to do. how are you trying to embed? maybe the PDF file as sample? script sample would be nice. then I can figure out what's wrong.

Bastian1975 commented 6 years ago

Sent you the PDF via mail, this is my sample-code:

var express = require('express'); var app = express(); var hummus = require('hummus'); var pdfWriter = hummus.createWriter("/tmp/targetPDF.pdf"); var pdfpage = pdfWriter.createPage(0,0,892,1417); var cxt = pdfWriter.startPageContentContext(pdfpage); cxt.drawImage(448,643,"/tmp/test.pdf"); pdfWriter.writePage(pdfpage); pdfWriter.end();

galkahana commented 6 years ago

seems like this works:

function createFormAndPlace() {
    var pdfWriter = hummus.createWriter('./helloFormAndPlace.pdf',{log:'./helloDrawImage.log'})
    var pdfpage = pdfWriter.createPage(0,0,892,1417);
    var cxt = pdfWriter.startPageContentContext(pdfpage);
    var formIDs = pdfWriter.createFormXObjectsFromPDF("./test.pdf",
        hummus.ePDFPageBoxMediaBox);    
    cxt.q()
        .cm(1,0,0,1,448,643)
        .doXObject(pdfpage.getResourcesDictionary().addFormXObjectMapping(formIDs[0]))
        .Q()
    pdfWriter.writePage(pdfpage);
    pdfWriter.end();
}

supposed to do the same thing. i'll check why... but in the meantime you can use it instead of drawImage

galkahana commented 6 years ago

Reporting back. I have found the issue causing drawImage to fail in this case, and fixed it. You should be able to see the correction with 1.0.83 build of hummus.

Bastian1975 commented 6 years ago

Thanks, working great now