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

Stroke width less than 1 output as 0 in PDF #349

Open mattgaspar opened 5 years ago

mattgaspar commented 5 years ago

The high level drawing commands don't seem to work correctly when the stroke width is less than 1, a stroke width of 0 is always output in the resulting PDF.

For example when width is set to 0.5 the PDF that is generated has a stroke width of 0. pageContext.drawPath(x1, y1, x2, y2, { type: 'stroke', width: 0.5, color: 0x002B49 }); (drawSquare also has the same issue, I haven't tested any others)

When using the low level operators, the stroke comes out correctly. pageContext .q() .K(1.00, 0.80, 0.42, 0.45) .w(0.5) .m(x1, y1) .l(x2, y2) .S() .Q();

(Using hummusJS 1.0.90 on Windows 10, NodeJS 10.11)

galkahana commented 5 years ago

this:

var pdfWriter = require('hummus').createWriter('./halfPixelWidth.pdf');
var page = pdfWriter.createPage(0,0,595,842);
var cxt = pdfWriter.startPageContentContext(page);

var pathStrokeOptions = {color:'DarkMagenta', width:4};

// drawPath
// cxt.drawPath(75,540,110,440,149,540,188,440,223,540,pathStrokeOptions);

cxt.drawPath(75,540,110,440,149,540,188,440,223,540,
    {...pathStrokeOptions,
        width:0.5
    });

    pdfWriter.writePage(page);
    pdfWriter.end();    

creates this: halfPixelWidth.pdf

does it not do that for you?

galkahana commented 5 years ago

hmmm. looking at the unfiltered version (.createWriter('./halfPixelWidth.pdf',{compress:false}); i see that 0 w is emitted....that's obviously bad. i'll look into it.

galkahana commented 5 years ago

cheers. 1.0.91 should take care of this.