从多页PDF文档的一页创建新的单页PDF文档 [英] Create new single-page-PDF document from one page of a multipage PDF document

查看:110
本文介绍了从多页PDF文档的一页创建新的单页PDF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2页的PDF文档.我需要阅读本文档的第一页,并使用阅读的内容创建一个新的PDF文档.我将如何使用iText做到这一点?到目前为止,由于我真的不知道如何开始,所以我什么也不能尝试.最好的方法是什么?

I have a PDF document which has 2 pages. I need to read the first page of this document and create a new PDF document with the read content. How would I do this using iText? So far I couldn't try anything as I don't really know how to begin. What is the best way?

推荐答案

您可以使用iText PdfCopy .

PdfReader reader = new PdfReader(inFilename);
int n = reader.getNumberOfPages();
if (n > 1) {
    Document doc = new Document();
    PdfCopy copy= new PdfCopy(doc, new FileOutputStream(outFilename));
    doc.open();
    PdfImportedPage page = copy.getImportedPage(reader, 1);
    copy.addPage(page);
    doc.close();
}
reader.close();

这篇关于从多页PDF文档的一页创建新的单页PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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