Missing New line characters in the iText PDF

View: New views
5 Messages — Rating Filter:   Alert me  

Missing New line characters in the iText PDF

by creddyms :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello I have an application to enter the text in the text box.  When I enter text as multiple lines in the text box, when the pdf is generated everything appears in one line.  

This is Line One.
This is Line Two.

I need to preserve the new line character when the iText generates the PDF.

When  PDF is generated It is showing as :

This is Line One.This is Line Two.

Can any one help to how I can achieve this.

Thanks in advance.

-Reddy

Re: Missing New line characters in the iText PDF

by Mathias Nilsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just make sure \n is used.

Re: Missing New line characters in the iText PDF

by creddyms :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If i use \n in the text box.  It is printing as  \n instead of treating it as a new line.

First line \n Second Line.

Mathias Nilsson wrote:
Just make sure \n is used.

Re: Missing New line characters in the iText PDF

by Mathias Nilsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What sort of text box do you use? Html textarea, Swing JtextArea or .net?

Can you post some code on how you create the pdf and what the input are?

Re: Missing New line characters in the iText PDF

by creddyms :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am using Java/ Spring/jsp. Please see the code below.


I checked in the database, copied the content and pasted it on a text editor,  I see the new line char  are preserved in the database. The data I pasted now shows in multiple lines.  So.. I don't think it is a problem with the text box.


But when I use the same content and pass it on to the PDF generator.  I see the new line characters missing.  I mean it prints all lines back to back, instead of printing the individual lines as a sparate line.

Any help is greatly appreciated.

Thanks in advance!


===============================================================
Here is my  jsp code, using Spring.

     <tr>
      <td colspan="2" align="left">Enter Guest Comments:</td>
     </tr>
     <tr>
      <td colspan="3" align="left"><form:textarea id="comments" path="recognition.comments" rows="12" cols="95"/></td>
     </tr>
     <tr>
      <td colspan="3">
        <input class="button" id="previewButton" style="cursor:pointer;" type="button"  value="Preview/Print" onClick="handlePreviewSelected()"/> 
        <input class="button" id="saveButton" type="submit"  value="Submit"/>
         </td>
     </tr>
    </table>
    </form:form>
======================================================================


        Font pCommentsFont = FontFactory.getFont(aEraCmReader.getCommFontType(lAsset), aEraCmReader.getCommentsFontSize(lAsset), Font.BOLD, aEraCmReader.getCommFontColor(lAsset));
        p = new Paragraph("");
        p.setAlignment(Element.ALIGN_CENTER);
        p.add(new Chunk(pRecognition.getComments(), pCommentsFont));
        lDocument.add(p);

==============================================================



Mathias Nilsson wrote:
What sort of text box do you use? Html textarea, Swing JtextArea or .net?

Can you post some code on how you create the pdf and what the input are?