dustin
Joined: 12 Jan 2007 Posts: 1
|
Posted: Fri Jan 12, 2007 5:43 pm Post subject: Getting error SplittingPDF into Mulitple PDFs |
|
|
I get this error in PdfSharp.pdf folder- PdfPages.cs- ImportExternalPage when I try to use the sample code for SplitDocument:
A PDF document must be opened with PdfDocumentOpenMode.Import to import pages from it.
I'm really not sure what I am doing wrong, since the code seems very straight forward. Here is the code I use that gets the error:
filename = "test.PDF";
File.Copy(Path.Combine(@"C:\PDFs\", filename),
Path.Combine(Directory.GetCurrentDirectory(), filename), true);
// Open the file
PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.ReadOnly);
string name = Path.GetFileNameWithoutExtension(filename);
for (int idx = 0; idx < inputDocument.PageCount; idx++)
{
// Create new document
PdfDocument outputDocument = new PdfDocument();
outputDocument.Version = inputDocument.Version;
outputDocument.Info.Title =
String.Format("Page {0} of {1}", idx + 1, inputDocument.Info.Title);
outputDocument.Info.Creator = inputDocument.Info.Creator;
// Add the page and save it
outputDocument.AddPage(inputDocument.Pages[idx]);
outputDocument.Save(String.Format("{0} - Page {1}.pdf", name, idx + 1));
}
Thanks in advance for any help. |
|