使用Itext生成pdf文件 [英] Generating pdf file using Itext

查看:121
本文介绍了使用Itext生成pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用itext jar从jsp生成pdf文件。你能否告诉我如何在字符串之间保留空格或制表符。

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();
}
%>

生成的pdf中没有Hello和World之间的空格。如何输入该行。

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

谢谢
MRK

Thanks MRK

推荐答案

将空格字符转换为不间断空格:

Convert your space characters to non-breaking spaces:

document.add(new Paragraph("Hello    World".replace(' ', '\u00a0')));

这篇关于使用Itext生成pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆