0

I have a Frame and use a BlockComposer to write multiple lines of text into the Frame. The text of the lines is determined by user input so I don't know in advance how many characters they will contain.

How can I know if all of the lines will fit into the frame or if they would overflow the height of the frame?

The example below is written in Scala which uses pdfclown java:

var frame = new Rectangle2D.Double(
  0, 0,
  availableWidth,
  availableHeight
)

for (line <- lines) {
    blockComposer.begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Top)
    blockComposer.showText(line)
    blockComposer.showBreak()
    blockComposer.end() 
}   
user3346601
  • 1,019
  • 1
  • 11
  • 18

1 Answers1

0

BlockComposer.showText is documented as:

/**
  Shows text.
  <p>Default line alignment is applied.</p>

  @param text Text to show.
  @return Last shown character index.
*/
public int showText(String text)

Thus, if your line might not fit into the current composer area, you have to show it like this (in Java):

int charsWritten;
while ((charsWritten = blockComposer.showText(line)) < line.length())
{
    line = line.substring(charsWritten);
    ... finish current blockComposer here,
    ... start a new one (on a new page if need be)
}
mkl
  • 90,588
  • 15
  • 125
  • 265