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

How to set a left aligned string and a center aligned string in a single line? #1215

Open
playersun opened this issue Aug 31, 2024 · 2 comments
Labels

Comments

@playersun
Copy link

  • OS: [macOS]
  • Used font: SimHei.ttf
  • OpenPDF version: openpdf-1.3.43
  • JDK: 1.8
@playersun playersun added the bug label Aug 31, 2024
@StevenStreasick
Copy link
Contributor

You can use a PdfPTable to store two PdfPCells in the same row. One PDF can be set to left aligned, where the other string is set to center aligned. However, PdfPTable assigns a certain percentage of the width to each of its cells, meaning that the center aligned string will only be within the center of the assigned width. You can manually set the widths using a lot of math such that the second column, if left aligned, will appear to be globally centered in the page.

Alternatively, you can use the ColumnText class and set up two columns of text, with one left aligned and one middle aligned. The downside to this solution is that the columns have to be manually positioned.

@playersun
Copy link
Author

You can use a PdfPTable to store two PdfPCells in the same row. One PDF can be set to left aligned, where the other string is set to center aligned. However, PdfPTable assigns a certain percentage of the width to each of its cells, meaning that the center aligned string will only be within the center of the assigned width. You can manually set the widths using a lot of math such that the second column, if left aligned, will appear to be globally centered in the page.

Alternatively, you can use the ColumnText class and set up two columns of text, with one left aligned and one middle aligned. The downside to this solution is that the columns have to be manually positioned.

OK, Got it. Thanks a lot!

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

No branches or pull requests

2 participants