私はpdfのすべてのページを別々のpdfファイルに変換しようとしています。私は6つのPDFファイルを作成するために6の範囲を与えました。PDFの各ページをC#で複数のpdfファイルに分割する方法(iTextSharpを使用)?
using System;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Windows.Forms;
using System.IO;
namespace Learning.SpitPdfApp {
public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
}
private void SplitPdfButton_Click(object sender, EventArgs e) {
MainForm objMainForm = new MainForm();
objMainForm.ExtractPage(SourceTextBox.Text, DestinationTextBox.Text);
}
public void ExtractPage(string sourcePath, string outputPath) {
int startPage = 1;
PdfReader objReader = new PdfReader(sourcePath+".pdf");
int endPage = 6;
Document objDocument = new Document(objReader.GetPageSizeWithRotation(startPage));
objDocument.Open();
for (int index = startPage; index <= endPage; index++) {
PdfCopy pdfCopyProvider = new PdfCopy(objDocument, new FileStream(outputPath+""+index+".pdf", FileMode.Create));
PdfImportedPage importedPage = pdfCopyProvider.GetImportedPage(objReader, index);
pdfCopyProvider.AddPage(importedPage);
}
objDocument.Close();
objReader.Close();
MessageBox.Show(@"Splitting successful!");
}
}
}
しかし、それはnull参照ポインタ例外を投げています。私は、私が引き起こした問題を理解することができません。
ご協力いただければ幸いです。 ありがとうございます。
? – petric