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 170 forks source link

node crashes segmentation fault core dumped #218

Open Selion05 opened 6 years ago

Selion05 commented 6 years ago

just tried to get it working in a docker container.

Dockerfile

FROM ubuntu:16.04

RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y nano curl build-essential
RUN curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh && rm nodesource_setup.sh
RUN apt-get install -y nodejs
RUN mkdir /app
WORKDIR app
RUN npm install -s express hummus
COPY app.js app.js

EXPOSE 8081

app.js

var express = require('express');
var app = express();

app.get('/test', (req, res) => res.send('It works!'))
app.get('/hummus', function(req, res){
        res.writeHead(200, {'Content-Type': 'application/pdf'});

        var hummus = require('hummus');

        var pdfWriter = hummus.createWriter(new hummus.PDFStreamForResponse(res));
        var page = pdfWriter.createPage(0,0,595,842);
        pdfWriter.startPageContentContext(page).writeText('Hello ' + (req.query.id ? req.query.id : 'World'),
                                                          0,400,
                                                          {
                                                            font:pdfWriter.getFontForFile('../tests/TestMaterials/fonts/arial.ttf'),
                                                            size:50,
                                                            colorspace:'gray',
                                                            color:0x00
                                                          });
        pdfWriter.writePage(page);
        pdfWriter.end();

        res.end();

        });

app.listen(3000);

building and running the contianer

docker build -t ubuntu-node .
docker container run -it -p 8081:3000 ubuntu-node bash
> node app.js

localhost:8081/test -> It works localhost:8081/hummus I get the error... Am I missing something?

chunyenHuang commented 6 years ago

Can you try again with

var path = require('path');
var arialFontPath = path.join(__dirname, '../tests/TestMaterials/fonts/arial.ttf');
...
font:pdfWriter.getFontForFile(arialFontPath),
...
Selion05 commented 6 years ago

still the segmentation fault

chunyenHuang commented 6 years ago

well, I copied your code and made the font path simpler.

font:pdfWriter.getFontForFile(path.join(__dirname, 'arial.ttf'))

It works for me. You may try the same thing or find another source for your arial font

As I know, segmentation fault is caused by unsolved font path, so you definitely want to try the some other path combination depends on how you run your codes.

This issue may be similar to your case: Location problem

Selion05 commented 6 years ago

ok jep you were right it was the missing font. i didn't notice that the sample required arial.ttf.

Anyway is there a more verbose log file or something simliar? Segmentation fault core dumped isn't helpful at all ;) Thanks!