Quantcast

\n in phrase doesn't generate a line break iText 1.4.5

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

\n in phrase doesn't generate a line break iText 1.4.5

Tim Juntunen-2
I am using iText 1.4.5.
I have a section of code where I want to have a line break at a particular point in a phrase. 



private String myPhrase = "Line one with spaces\nLine two should start on the next line";
.
.
.
Paragraph logoAndInfo4 = new Paragraph (new Phrase(
myPhrase,font));


However, when the PDF is created I get something like:

Line one with spaces\nLine two should start on the next line

Do I need to break myPhrase into 2 different phrases and explicitly add a line break to get a new line?

(I tried to substitute the iText 2.0.8 library in place of 1.4.5, but my code hung and I haven't debugged it further to find the reason.)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: \n in phrase doesn't generate a line break iText 1.4.5

info-2
Tim Juntunen wrote:
> I tried to substitute the iText 2.0.8 library in place of 1.4.5, but my
> code hung and I haven't debugged it further to find the reason.

It works in iText 2.0.8 (see attachment).
I haven't tested it with iText 1.4.5.
The new history files tell me that version dates from September 2006:
http://www.1t3xt.com/downloads/history.php?branch=history.10&node=14
I'm sure you want to do some more effort getting iText 2.0.8 to work,
to avoid this AND OTHER bugs that have been fixed since 2006.
--
This answer is provided by 1T3XT BVBA

import java.io.IOException;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;

public class PhraseTest {

        public static final void main(String[] args) {
                Document document = new Document();
                try {
                        PdfWriter.getInstance(document, new FileOutputStream("phrase_test.pdf"));
                        document.open();
                        String myPhrase = "Line one with spaces\nLine two should start on the next line";
                        Paragraph p = new Paragraph (new Phrase(myPhrase));
                        document.add(p);
                } catch (IOException e) {
                        e.printStackTrace();
                } catch (DocumentException e) {
                        e.printStackTrace();
                }
                document.close();
        }
}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

phrase_test.pdf (1K) Download Attachment
Loading...