Pdfkit: Can't seem to rotate text

Created on 1 Mar 2016  路  4Comments  路  Source: foliojs/pdfkit

      vectorDoc
        .rotate(90, {origin: [650, 45]})
        .fillColor(is_express ? 'red' : 'black')
        .font('OpenSans-Light')
        .fontSize(12)
        .text('hello', 650, 53)

Seems to make my script fail, I've even tried setting rotation to 89.9, tried this as well:

      vectorDoc
        .save()
        .rotate(90, {origin: [650, 45]})
        .fillColor(is_express ? 'red' : 'black')
        .font('OpenSans-Light')
        .fontSize(12)
        .text('hello', 650, 53)
        .restore()

I've tried removing the font/fontSize options but nothing seems to work. Using the latest npm version with pdftk 2.01 a Handy Tool for Manipulating PDF Documents

Most helpful comment

The best way to write rotated text is to rotate pdf around certain point, then write it normally and rotate the pdf document back.
Code example:

doc.rotate(angle, { origin: [x,y] };
doc.text( 'TEST', x, y);
doc.rotate(angle * (-1), { origin: [x,y] };

This way you don't need to calculate new position.

All 4 comments

Up

So, after some researches, I decided to open this StackOverflow question, and @olance gave me a really helpful answer, that lead me to fix my issue, so if you want to rotate text, you may want to read it.

http://stackoverflow.com/questions/41469801/is-there-any-trick-to-rotate-text-in-pdfkit

This is essentially what I ended up doing, completely forgot about this issue though, thanks for updating me and this issue. Hopefully it'll help others in the future :+1:

The best way to write rotated text is to rotate pdf around certain point, then write it normally and rotate the pdf document back.
Code example:

doc.rotate(angle, { origin: [x,y] };
doc.text( 'TEST', x, y);
doc.rotate(angle * (-1), { origin: [x,y] };

This way you don't need to calculate new position.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vovkvlad picture vovkvlad  路  5Comments

nqgajanan picture nqgajanan  路  4Comments

cam-intel picture cam-intel  路  6Comments

liubin picture liubin  路  4Comments

leore picture leore  路  3Comments