当使用新行字符

时间:2016-08-25 03:50:54

标签: java itext

代码:

paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
paragraph.add(new Paragraph("        Prospective user has to see all the Excel Documents, save without renaming it,\n        fill the rates and save without renaming it  and then upload the same.\n"));

2 个答案:

答案 0 :(得分:0)

首先:doesn't work is not a problem description that a software developer should give when asking a question on an internet forum. That's a problem description most commonly employed by standard users that do not understand or care about how computers work.

你声称这不起作用:

paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
paragraph.add(new Paragraph("        Prospective user has to see all the Excel Documents, save without renaming it,\n        fill the rates and save without renaming it  and then upload the same.\n"));

如果假设您正在抱怨iText的正确行为,更具体地说,您可能会抱怨由换行符分隔的每个段落中的最后一行是不合理的。

这是预期的行为:阅读任何带有正当文本的书,你会发现这是正常的行为。每一行都合理的书籍,即使是段落的最后一行也是丑陋的,难以阅读。

尽管如此,您可以要求iText显示该行为。如果您想创建类似的丑陋输出,则需要使用ALIGN_JUSTIFIED_ALL而不是ALIGN_JUSTIFIED

paragraph.setAlignment(Element.ALIGN_JUSTIFIED_ALL);
paragraph.add(new Paragraph("        Prospective user has to see all the Excel Documents, save without renaming it,\n        fill the rates and save without renaming it  and then upload the same.\n"));

<强>更新

在评论中,你现在说:&#34;我想在以下情况下证明:段落之间的新行与行开头的空白处有大量数据。我不想证明段落的最后一行。&#34;

目前尚不清楚。而且:使用空格字符来添加额外的空白区域是一个坏主意。我想你想使用Separator,但你的问题是如此不明确,以至于无法以当前形式回答。

答案 1 :(得分:0)

事实证明(基于我之前回答中发布的评论),目标是以表格形式组织内容。使用空格不是实现这一目标的好方法。

使用PdfPTablePdfPCell对象解决了问题:

PdfPTable table = new PdfPTable(3);
PdfPCell cell13a = new PdfPCell(
    new Phrase("13"));
sectionII.addCell(cell13a);
PdfPCell cell13b = new PdfPCell(
    new Phrase("Last date and time of closing of online submission of application"));
sectionII.addCell(cell13b);
PdfPCell cell13c = new PdfPCell(
    new Phrase("(17:00 Hrs.) "));
cell13c.setHorizontalAlignment(Element.ALIGN_RIGHT);
sectionII.addCell(cell13c);