1

I am writing content to a PdfContentByte object directly using PdfContentByte.showTextAligned, I'd like to know how I can stop the text overflowing a given region when writing.

If possible it would be great if iText could also place an ellipsis character where the text does not fit.

I can't find any method on ColumnText that will help either. I do not wish the content to wrap when writing.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
Brett Ryan
  • 26,937
  • 30
  • 128
  • 163

1 Answers1

1

Use this:

int status = ColumnText.START_COLUMN;
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(rectangle);
status = ct.go();

Make sure that you define rectangle in a way so that only one line fits, use ColumnText.hasMoreText(status) to find out if you need to add an ellipsis character.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Tried this but data is automatically wrapping within rectangle. Is there any way we can fill one line and left out text on some other co-ordinate with appending some extra text to it. – Tanul Sep 13 '17 at 11:50
  • Yes, of course. That's the whole point of `ColumnText`. If the data is automatically wrapping, you have chosen a `Rectangle` that is too high. Reduce the height. You can check if there was extra text. If `ColumnText.hasMoreText(status)` returns `true`, you can define another `Rectangle` and run `ct.go()` to put (part of) the remaining text at a different location. – Bruno Lowagie Sep 13 '17 at 11:55
  • The text is taking total width of 408. And I've given ux:-316 and uy:- 1. Tried with uy:-0 as well. Still it is wrapping. – Tanul Sep 14 '17 at 08:16
  • Why are you talking about the width while you should be talking about the height? – Bruno Lowagie Sep 14 '17 at 08:17
  • Also: why are you "hijacking" a question dating from 2012 instead of posting a new question? And why are you still using iText 5 while you should be using iText 5? (The policy is no longer to provide voluntary support for iText 5; only customers are entitled to support for iText 5; if you're not a customer, the policy is only to answer questions about iText 7.) – Bruno Lowagie Sep 14 '17 at 08:19
  • Actually due to some issue stackoverflow had barred me from asking questions. That's why I've added the comment over here. Sorry if I done something wrong... – Tanul Sep 14 '17 at 08:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154419/discussion-between-tanul-and-bruno-lowagie). – Tanul Sep 14 '17 at 08:23
  • I don't waste my time on chat. I have a job. If you want my time, you can always contact the company I work for and hire me. (And Stack Overflow never bars people without a reason, so evidently you did something wrong. Why would I help someone who is doing wrong things?) – Bruno Lowagie Sep 14 '17 at 08:27
  • Sir, by mistake I've clicked the chat button. Please don't get upset.. However, I was able to handle my issue through an answer you've given on other post. Thanks Sir. Sorry once again... – Tanul Sep 14 '17 at 08:30
  • And stackoverflow have barred because once I've asked a question, and some guy put red mark on it without understanding the question which indirectly impacted me. I'm not doing any wrong thing. – Tanul Sep 14 '17 at 08:40
  • If you say so. Usually, Stack Overflow doesn't bar because of one person. For instance: a minimum of five votes from highly ranked people are needed to close a question. I can close questions as duplicates for those topics I earned a gold badge for (those are extremely hard to obtain). But even a reputation higher than 50,000 isn't sufficient to bar someone. Knowing all of this, my opinion is that you're not honest. You shouldn't criticize Stack Overflow if you want to get help on Stack Overflow. It's bad for your reputation and your karma. – Bruno Lowagie Sep 14 '17 at 08:47
  • I'm not criticizing anyone sir. However, you're a very great person for IT industries. I'll give complete regards to your opinion. Thanks for at least replying. Its an honor. Sorry if said anything wrong. – Tanul Sep 14 '17 at 08:59