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

How to draw an arrow? #287

Open aathirag opened 6 years ago

aathirag commented 6 years ago

using x1,y1,x2,y2 how can I draw an arrowhead in x2,y2 position?

chunyenHuang commented 6 years ago

https://github.com/galkahana/HummusJS/wiki/Show-primitives#paths https://github.com/galkahana/HummusJS/blob/02730266893d288ac6a88148c8f624c41519236e/tests/HighLevelContentContext.js

You should be able to draw an arrow head line by the following code, however, the hard part of this is to calculate the arrow angle and offset.

    var pathStrokeOptions = {color:'DarkMagenta', width:1};
    // for demonstration, I use (0,0) and (0,100) as your (x1,y1) and (x2,y2)
    context
        .q()
        .J(1)
        .j(1)
        .drawPath(0, 0, 100, 0, pathStrokeOptions )
        .drawPath(95, 5, 100, 0, 95, -5, pathStrokeOptions )
        .Q();
aathirag commented 6 years ago

In my case x1,y1,x2,y2 is user-defined. The user will draw in vertical/horizontal or right/left direction.in this case how I can draw an arrowhead