Pdfkit: LineWrapper swallows line of text

Created on 19 Jun 2017  路  7Comments  路  Source: foliojs/pdfkit

In certain situations the LineWrapper.wrap method called by the text mixin swallows entire lines. I have not fully understood what happens, but it seems a single additional emitLine solves the issue. I think buffer is overwritten with word before its previous contents have been emitted, since the actual emitLine call happens afterwards.

See: https://github.com/jtillmann/pdfkit/commit/80868c23b946bc98775ee38c49eb741e68129ec8

I have a hard time reproducing this and since the one case I just solved it for is confidential I can't share an example yet.

Most helpful comment

@pbogdan03 Yes, you gotta use v0.8.0.

All 7 comments

I ran into this issue today and can confirm that the fix https://github.com/jtillmann/pdfkit/commit/80868c23b946bc98775ee38c49eb741e68129ec8 works.

Here is an example which shows the issue:

const text = 'hello line\nbreak';
const width = doc.widthOfString('hello line');
doc.text(text, { width: width - 1 });

Output of the code is:

break

Expected output:

line
break

Yes, this indeed is a real issue.

I thought it was an issue with line wrapping, so gave width explicitly as recommended here. http://pdfkit.org/docs/text.html#line_wrapping_and_justification
But it is a bug in v0.8.3 and wasn't in v0.8.0.

Thanks

I'm the author of this horrible bug :(
The fix by @jtillmann is as it was before I tried to fix an issue with justification. There is a misaligned word in some cases but it is much better than a missing line!
If someone with more brain than me can check the issue #345 it would be great, but in the meantime it should be reverted.

Thanks a lot for clearing the air about this. Looking forward to the bug getting fixed.

@jtillmann I think you should make a pull request with your fix. It will increase the probability of having this bug fixed.

Is there any workaround until this is fixed?

@pbogdan03 Yes, you gotta use v0.8.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

durango picture durango  路  4Comments

tm2josep picture tm2josep  路  5Comments

edmelly picture edmelly  路  5Comments

nqgajanan picture nqgajanan  路  4Comments

stephen-last picture stephen-last  路  4Comments