Set up references and Using Statements to use iTextSharp
首先是需要引用的命名空间:
using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
namespace iTextTools
{
public class PdfExtractorUtility
{
}
}
方法一:从已有pdf中拷贝指定的页码范围到一个新的pdf文件中:
1、使用pdfCopyProvider.AddPage()方法
public void ExtractPages(string sourcePdfPath, string outputPdfPath,
int startPage, int endPage)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
try
{
reader = new PdfReader(sourcePdfPath);
sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage));
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create))