Skip to content

Commit

Permalink
Split document sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyalakshmit committed Jun 26, 2023
1 parent 35db1d0 commit 09e887e
Showing 1 changed file with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
FileStream docStream = new FileStream(Path.GetFullPath(@"../../../Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream, true);

for (int i = 0; i < loadedDocument.PageCount; i++)
for (int i = 0; i < loadedDocument.Pages.Count; i++)
{

//Creates a new document.
Expand All @@ -18,28 +18,12 @@
//Imports the pages from the loaded document.
document.ImportPage(loadedDocument, i);

//Create a memory stream.
MemoryStream stream = new MemoryStream();

//Save the document to stream.
document.Save(stream);

stream.Position = 0;

//Close the documents.
//Create a File stream.
using (var outputFileStream = new FileStream("Output" + i + ".pdf", FileMode.Create, FileAccess.Write)) {
//Save the document to stream.
document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
loadedDocument.Close(true);

//Create a file stream.
FileStream fileStream = new FileStream("Output" + i + ".pdf", FileMode.Create, FileAccess.Write);

byte[] bytes = stream.ToArray();

//Write bytes to file.
fileStream.Write(bytes, 0, (int)bytes.Length);

//Dispose the streams.
stream.Dispose();
fileStream.Dispose();

}

0 comments on commit 09e887e

Please sign in to comment.