2

I am trying to generate pdf file from jsp using itext jar. Could you please tell me how to retain the space or tab between strings as it is.

<%
response.setContentType("application/pdf");
String disHeader = "Attachment; Filename=\"example.pdf\"";
response.setHeader("Content-Disposition", disHeader);
Document document = new Document();
try{
    PdfWriter.getInstance(document, response.getOutputStream());

            document.open();
        document.add(new Paragraph("Hello    World"));
        document.add(new Paragraph("Hello World")); 
        document.close();
        }catch(DocumentException e){
e.printStackTrace();
}
%>

The space between "Hello" and "World" is not there in the generated pdf. How can i get the line as it is entered.

Thanks MRK

MRK
  • 573
  • 2
  • 8
  • 21

1 Answers1

0

Convert your space characters to non-breaking spaces:

document.add(new Paragraph("Hello    World".replace(' ', '\u00a0')));
James Allman
  • 40,573
  • 11
  • 57
  • 70
  • Thanks for the inputs. I have data with tab seperated. I would like to retain the tab as it is. i.e suppose if hello and world is tab seperated, i would like to see tab seperated even after writing to pdf. Could you please let me know is there any way to retain tab charater as it is. – MRK Dec 26 '11 at 09:33