IText:如何在pdf中添加空白页? [英] IText: How to add blank page inside pdf?
本文介绍了IText:如何在pdf中添加空白页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有pdf文档,例如25页。如何在第10页和第11页添加一个空白页?
I have pdf document, for example 25 pages. How to add one blank page beetwen page 10 and 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();
}
}
这篇关于IText:如何在pdf中添加空白页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文