Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using continued with center and right alignment is broken #240

Open
alextarrell opened this issue Jun 5, 2014 · 13 comments
Open

Using continued with center and right alignment is broken #240

alextarrell opened this issue Jun 5, 2014 · 13 comments

Comments

@alextarrell
Copy link

Using continued will not remeasure the text position in order to account for new text being added.

doc.text('Normal Text ', {
    align: 'left',
    continued: true
}).text('Non-overlapping text');
doc.moveDown();
doc.text('Normal Text ', {
    align: 'center',
    continued: true
}).text('Overlapping text');
doc.moveDown();
doc.text('Normal Text ', {
    align: 'right',
    continued: true
}).text('Overlapping text');

Produces the following:
image

@devongovett
Copy link
Member

Yeah, and unfortunately there isn't much we can do about that easily. We would need to not add the last line of a continued section to the document so we could remeasure in the next part. This would involve tracking all sorts of things for the text style and would be a pain. Definitely not impossible, just difficult.

The continued option was always a bit of a hack. Really there should be a 2 pass layout system that first figures out where the text is going to go, and then actually adds it to the document. I see no other way around it if we want good looking rich text. For now, continued is a temporary solution that works for most uses: left aligned text.

@ryanwersal
Copy link
Contributor

I ran into this recently as well. @devongovett Mind if I take a stab at such a text layout system? Have you thought much about possible implementations? Or did you want to go a different direction entirely?

@toymachiner62
Copy link

I also need to be able to use align: right along with continued: true. My reason is that I need bold text followed by non-bold text all aligned right and this doesn't work:

const regular = 'Times-Roman'
const bold = 'Times-Bold'
doc.font(bold)
doc.text('Contact:', { align: 'right', continued: true })
doc.font(regular)
doc.text('privacy@example.com', { align: 'right' })

@viktordreval
Copy link

viktordreval commented Mar 6, 2019

Any updates regarding this issue?
I think continued is great feature. And it would be great if it will support align option.
For now the only option to alight a continued text I see is to split the text into rows and align each row individually.

@ninbit
Copy link

ninbit commented Apr 15, 2019

Any updates? I also need this feature since I try to use pdfkit with a right-to-left language. For now, I somehow hacked a bit for RTL language but I stuck in the continued option.

@ninbit
Copy link

ninbit commented Apr 15, 2019

For right aligned texts, I think it is enough to obtain the x position or the width of the last line of the first text. Then we moveUp() and write to that position. Hence the second text will be continued without the continuedoption.

So, is there a way to get the x position or the width of the last line?
Or is it possible to obtain the last line of any text which is written to pdf? It should be obtained when wrapping lines, I think.

@c0mradeuc
Copy link

For right aligned texts, I think it is enough to obtain the x position or the width of the last line of the first text. Then we moveUp() and write to that position. Hence the second text will be continued without the continuedoption.

So, is there a way to get the x position or the width of the last line?
Or is it possible to obtain the last line of any text which is written to pdf? It should be obtained when wrapping lines, I think.

Maybe you can calculate the width of the text according to the fontsize

@dragon74
Copy link

dragon74 commented Apr 1, 2020

I also also need to be able to use align: right along with continued: true. will it be supported?

@pastean
Copy link

pastean commented Jul 4, 2020

@dragon74 I posted a workaround in #54 check it out, hope it helps

@fernando-s97
Copy link

Any updates on that?

@NikolaiMe
Copy link

Hey all,

I created a package to solve this issue. Maybe it helps some of you!

textbox-for-pdfkit

@tttaisgt
Copy link

Are any things new? 😅

@hiba236
Copy link

hiba236 commented Jul 20, 2023

ented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests