如何在PDF中插入空行? [英] How to insert blank lines in PDF?

查看:1862
本文介绍了如何在PDF中插入空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText创建PDF。我想在段落和表格之间插入空行。

I am creating a PDF using iText. I want to insert blank lines between paragraphs and tables.

我怎样才能实现这个目标?

How can I achieve this?

推荐答案

你可以触发一个通过在文档中插入 Chunk.NEWLINE 来换行。这是一个例子。

You can trigger a newline by inserting Chunk.NEWLINE into your document. Here's an example.

public static void main(String args[]) {
    try {
        // create a new document
        Document document = new Document( PageSize.A4, 20, 20, 20, 20 );
        PdfWriter.getInstance( document, new FileOutputStream( "HelloWorld.pdf" ) );

        document.open();

        document.add( new Paragraph( "Hello, World!" ) );
        document.add( new Paragraph( "Hello, World!" ) );

        // add a couple of blank lines
        document.add( Chunk.NEWLINE );
        document.add( Chunk.NEWLINE );

        // add one more line with text
        document.add( new Paragraph( "Hello, World!" ) );

        document.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

以下是显示部分PDF的屏幕截图上面的代码产生。

Below is a screen shot showing part of the PDF that the code above produces.

这篇关于如何在PDF中插入空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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