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.
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.
Most helpful comment
@pbogdan03 Yes, you gotta use v0.8.0.