itext 添加空格_IText:如何在pdf中添加空白页?

I have pdf document, for example 25 pages. How to add one blank page beetwen page 10 and 11 ?

解决方案

First hit on google:

/*

* This class is part of the book "iText in Action - 2nd Edition"

* written by Bruno Lowagie (ISBN: 9781935182610)

* For more info, go to: http://itextpdf.com/examples/

* This example only works with the AGPL version of iText.

*/

package part1.chapter05;

import java.io.FileOutputStream;

import java.io.IOException;

import com.itextpdf.text.Document;

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.Paragraph;

import com.itextpdf.text.pdf.PdfWriter;

public class NewPage {

/** Path to the resulting PDF file. */

public static final String RESULT

= "results/part1/chapter05/new_page.pdf";

/**

* Main method creating the PDF.

* @param args no arguments needed

* @throws IOException

* @throws DocumentException

*/

public static void main(String[] args) throws IOException, DocumentException {

// step 1

Document document = new Document();

// step 2

PdfWriter writer

= PdfWriter.getInstance(document, new FileOutputStream(RESULT));

// step 3

document.open();

// step 4

document.add(new Paragraph("This page will NOT be followed by a blank page!"));

document.newPage();

// we don't add anything to this page: newPage() will be ignored

document.newPage();

document.add(new Paragraph("This page will be followed by a blank page!"));

document.newPage();

writer.setPageEmpty(false);

document.newPage();

document.add(new Paragraph("The previous page was a blank page!"));

// step 5

document.close();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iTextPDF,可以通过使用HTML的特殊字符实体来插入空格。例如,使用` `来表示一个非断行空格。您可以在HTML代码直接插入这个实体字符,然后将整个HTML转换为PDF。另外,您还可以使用CSS样式来设置空格的宽度和间距。具体的方法和代码示例可以参考iTextPDF的官方文档和示例网站。如果您遇到静态HTML转PDF文显示、换行问题或字体问题,您可以参考一些博文和文章,其提供了关于这些问题的解决方案和示例代码。如果您想要了解更多关于iTextPDF的详细用法和示例,可以查看官方文档和示例网站。在使用iTextPDF时,您还可以使用`PdfWriter`类的`getInstance`方法来创建一个`PdfWriter`对象,并指定输出文件的路径。希望这些信息对您有所帮助。如果您还有其他问题,请随时提问。 http://itextpdf.com/examples/ https://blog.csdn.net/qq_38616723/article/details/125188407?spm=1001.2014.3001.5502 PdfWriter.getInstance(document, new FileOutputStream(RESULT))<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [IText:如何在pdf添加空白页?](https://blog.csdn.net/weixin_36272416/article/details/118904762)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [itext 将html转pdf文显示换行以及字体问题](https://download.csdn.net/download/qq_38616723/85585479)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值