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

Images not working #7

Closed
einfallstoll opened this issue Apr 5, 2014 · 14 comments
Closed

Images not working #7

einfallstoll opened this issue Apr 5, 2014 · 14 comments

Comments

@einfallstoll
Copy link
Contributor

I'm really fighting with your missing documentation. I try to run the images.js-example, but it will give me the following error:

Fabios-MacBook-Pro:examples fabiopoloni$ node images.js 

/Users/fabiopoloni/Desktop/pdfmake/src/imageMeasure.js:11
        image = pdfKit.PDFImage.open(src);
                                ^
TypeError: Cannot call method 'open' of undefined
    at ImageMeasure.measureImage (/Users/fabiopoloni/Desktop/pdfmake/src/imageMeasure.js:11:27)
    at DocMeasure.measureImage (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:107:36)
    at /Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:57:30
    at StyleContextStack.auto (/Users/fabiopoloni/Desktop/pdfmake/src/styleContextStack.js:122:15)
    at DocMeasure.measureNode (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:40:25)
    at DocMeasure.measureVerticalContainer (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:139:19)
    at /Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:47:30
    at StyleContextStack.auto (/Users/fabiopoloni/Desktop/pdfmake/src/styleContextStack.js:122:15)
    at DocMeasure.measureNode (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:40:25)
    at DocMeasure.measureDocument (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:27:14)

I already tried downgrading pdfkit to version 0.2.7 which is declared in package.json but it won't work. Where's the problem?

@bpampuch
Copy link
Owner

bpampuch commented Apr 5, 2014

Hmm, it's kind of weird. Why did you even have to downgrade pdfkit? Running npm install should have downloaded the one from package.json.

Looking at your prompt, I assume you've downloaded sources and run the image.js example from the examples directory. Have you changed anything? If you have - could you include the file?

The docs will cover whole functionality by the end of next week (I'll do my best to finish it even earlier - maybe Wednesday)

@einfallstoll
Copy link
Contributor Author

Hi,

I did both, installed it using npm and git.

The package.json said version ~0.2.7 which was upgraded to 0.2.8. So I assumed first it could be a problem with the versions. But it's not.

I figured out that in imageMeasure.js is a small error. You're using pdfKit.PDFImage which is undefined. I forked your repository and made a really dirty solution, because I have to finish the project until monday and have no time to write something better or wait for a fix.

pdfmake is by the way a great piece of software!

  • Fabio

@bpampuch
Copy link
Owner

bpampuch commented Apr 5, 2014

Hey, there's plenty of time till monday :) I'll take a look at it ;) Hold on

@einfallstoll
Copy link
Contributor Author

You can have a look at my dirty workaround in my forked repository.

@bpampuch
Copy link
Owner

bpampuch commented Apr 5, 2014

Oh, I got it, pdfmake updates pdfkit in a few places. The npm version already contains these updates. To make it run from sources, you should call grunt at least once.

@einfallstoll
Copy link
Contributor Author

But the npm-version won't run the images.js?

@bpampuch
Copy link
Owner

bpampuch commented Apr 5, 2014

ooops, my mistake, sorry... I'll fix it in a second

@einfallstoll
Copy link
Contributor Author

Great I gonna give it a try this week ;)

You're a great programmer…

@bpampuch
Copy link
Owner

bpampuch commented Apr 5, 2014

thx ;)

@bpampuch
Copy link
Owner

bpampuch commented Apr 6, 2014

OK, it's fixed now, thanks for pointing it out.

@einfallstoll
Copy link
Contributor Author

Great! Thanks.

@bpampuch
Copy link
Owner

bpampuch commented Apr 6, 2014

I've also upgraded pdfkit to the newest version 0.5.2, which means you shouldn't be using write method anymore. Results are Node streams so make sure to update your code to:

var doc = printer.createPdfKitDocument(docDefinition);
doc.pipe(fs.createWriteStream('file.pdf');
doc.end();

@bpampuch
Copy link
Owner

bpampuch commented Apr 6, 2014

pdfkit 0.5.2 introduced another "bug" in browser-based pdfmake. If you're printing directly in the browser, wait for pdfmake 0.1.5. I'm working on it

@einfallstoll
Copy link
Contributor Author

I'm using it server-side :-)

var pdfDoc = printer.createPdfKitDocument(docDefinition);

pdfDoc.end();

var chunks = [];

pdfDoc.on('data', function(chunk) {
    debug('got pdf chunk', chunk.length);
    chunks.push(chunk);
});

pdfDoc.on('end', function() {
    debug('received all pdf chunks', chunks.length);
    callback(null, Buffer.concat(chunks));
});

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

2 participants