本文介绍了如何在iText7中调整段落之间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iText7中,我需要在以页面为中心的文档顶部创建5行文本.我发现执行此操作的最简单方法是:

In iText7 I need to create 5 lines of text at the top of a document that are centered to the page. The easiest way I found to do this is:

doc.add(new Paragraph("text of line 1").SetTextAlignment(TextAlignment.CENTER));
doc.add(new Paragraph("text of line 2").SetTextAlignment(TextAlignment.CENTER));

等但是,每行之间的空间比我想要的要大.您可以在段落中设置行距,但是如何在文档的段落之间设置行距?还是我从头开始是完全错误的方式?

etc.However there is a larger amount of space between each of the lines than I want. Within a paragraph you can set line leading, but how do I set leading between paragraphs in a document? Or am I doing this the complete wrong way to begin with?

推荐答案

段落有2种方法来处理所谓的前导.

Paragraph has 2 methods for handling what is known as the leading.

Paragraph o1 = new Paragraph("");
o1.setMultipliedLeading(1.0f);

乘以行距是指您指定将行距与字体高度相比要多大的一个因素.

Multiplied leading is when you specify a factor of how big the leading will be compared to the height of the font.

您也可以将其设置为明智的文件:

You can also set it document wise:

document.setProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, 1.2f));

这篇关于如何在iText7中调整段落之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:31