作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 pdf 文档,例如 25 页。如何在第10页和第11页之间添加一页空白页?
最佳答案
谷歌首次点击:
/*
* 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();
}
}
关于java - IText:如何在pdf中添加空白页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11185172/
我是一名优秀的程序员,十分优秀!