使用iTextSharp的从多页PDF制作1页PDF文件 [英] Making 1 page pdfs from a multipage pdf using itextsharp

查看:401
本文介绍了使用iTextSharp的从多页PDF制作1页PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我要制作成几个1页PDF文件如在原有的PDF每一页,现在自己的PDF文档的PDF文件。我试图做到这一点使用iTextSharp的,但我有一些困难,甚至开始。

我要对这个错误的方式?任何人都知道我怎么会去这样做?

由于一吨!

解决方案

 使用(的FileStream FS =新的FileStream(argPdfFileName,FileMode.Create))
{
  文档DOC =新的文件(argReader.GetPageSize(argPdfPageNumber));
  PdfCopy复制=新PdfCopy(DOC,FS);
  doc.Open();
  PdfImportedPage页= copy.GetImportedPage(argReader,argPdfPageNumber);
  copy.AddPage(页);
  doc.Close();
}
 

斩了这一点,一些工作code。 argReader是PdfReader实例指向的源文件。 argPdfPageNumber是有问题的页面编号。 基本上你只需要创建一个新的PDF。导入源页放入,然后将其添加到文档并保存。

I have a pdf that I want to make into several 1 page pdfs where each page in the original pdf is now its own pdf document. I am trying to do this using itextsharp, but am having some difficulty even getting started.

Am I going about this the wrong way? Anyone know how I would go about doing this?

Thanks a ton!

解决方案

using (FileStream fs = new FileStream(argPdfFileName, FileMode.Create))
{
  Document doc = new Document(argReader.GetPageSize(argPdfPageNumber));
  PdfCopy copy = new PdfCopy(doc, fs);
  doc.Open();
  PdfImportedPage page = copy.GetImportedPage(argReader, argPdfPageNumber);
  copy.AddPage(page);
  doc.Close();
}

Chopped this out of some working code. argReader is a PdfReader instance pointing at the source document. argPdfPageNumber is the pagenumber in question. Basically you just create a new pdf. Import the source page into it and then add it to the document and save.

这篇关于使用iTextSharp的从多页PDF制作1页PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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