Linebreak in properties file

L

Lord Zoltar

I have a .properties file with some strings that I need to print in a
PDF (I'm using iText). I need to add line breaks to some of the
strings so that they appear on the report as a 2 or 3 line string. I
tried adding \n and \r to the string at the location I needed the line
break, but it didn't seem to work. Is there any way to do this in the
properties file?
 
R

RedGrittyBrick

Lord said:
I have a .properties file with some strings that I need to print in a
PDF (I'm using iText). I need to add line breaks to some of the
strings so that they appear on the report as a 2 or 3 line string. I
tried adding \n and \r to the string at the location I needed the line
break, but it didn't seem to work. Is there any way to do this in the
properties file?


Can't you split the string at the "\n" and add each piece to the
Document as separate paragraphs?
 
L

Lord Zoltar

Can't you split the string at the "\n" and add each piece to the
Document as separate paragraphs?

Maybe... It would mean re-writing parts of the PDF generator to create
a newline chunk for every "\n" in the properties string.
I was hoping for a simpler solution, lke just adding \n to the string,
but I think that \n gets discarded when the properties file is read.
 
B

Bent C Dalager

I have a .properties file with some strings that I need to print in a
PDF (I'm using iText). I need to add line breaks to some of the
strings so that they appear on the report as a 2 or 3 line string. I
tried adding \n and \r to the string at the location I needed the line
break, but it didn't seem to work. Is there any way to do this in the
properties file?

It might depend on how you load the properties file. When I use
Properties.load(InputStream), it interprets \n as linefeed.

Properties.load(Reader) should act much the same way on 1.6:

http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)

Cheers,
Bent D
 
L

Lord Zoltar

It might depend on how you load the properties file. When I use
Properties.load(InputStream), it interprets \n as linefeed.

Properties.load(Reader) should act much the same way on 1.6:

http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load(...)

I didn't have access to the part of this application that loads the
properties file, but it turns ou that the \n WAS a part of the string
that was read - iText was not creating a newline in its output when
the string that was passed to it contained \n.
Sooo... it looks like I'm re-writing part of my PDF generator.
 
K

Karl

Lord Zoltar said:
I didn't have access to the part of this application that loads the
properties file, but it turns ou that the \n WAS a part of the string
that was read - iText was not creating a newline in its output when
the string that was passed to it contained \n.
Sooo... it looks like I'm re-writing part of my PDF generator.

Have you considered using one of the optional (or mandatory) break
characters provided in Unicode (BPH, SHY, NBSP, etc.)? These characters give
the client formatters the option of inserting line breaks at certain points
in the line. The resulting string might provide enough hints to be "one size
fits all".

That said, there seems to be confusion among formatter implementations about
the exact semantics of such characters, as seen here:
http://www.cs.tut.fi/~jkorpela/shy.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top