Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Back
PDFsharp Sample: Split Document
Modified on 2015/09/14 10:21
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|ProtectDocument-sample|PDFsharpSamples|TextLayout-sample} This sample shows how to convert a PDF document with n pages into n documents with one page each. ==PDF Output File== See the PDF files created by this sample: First page: {s:PdfLink|SplitDocument-sample%2fPortable%20Document%20Format%20-%20Page%201_tempfile.pdf|output.pdf} (31 kB){br} Second page: {s:PdfLink|SplitDocument-sample%2fPortable%20Document%20Format%20-%20Page%202_tempfile.pdf|output.pdf} (17 kB) {s:note} the sample creates six pages from the sample document, only two pages are provided here. ==Screen Shots== Here are two sample screen shots: {s:ImageThumbLink|Screen shot of page 1|SplitDocument-sample%2fSplitDocument1th.png|SplitDocument-sample%2fSplitDocument1.png} {s:ImageThumbLink|Screen shot of page 2|SplitDocument-sample%2fSplitDocument2th.png|SplitDocument-sample%2fSplitDocument2.png}{br} {s:note} the sample creates six pages from the sample document, only two pages are shown here. ==Source Code== This is the whole source code needed to create the PDF file: {s:beginCsharp} // Get a fresh copy of the sample PDF file const string filename = "Portable Document Format.pdf"; File.Copy(Path.Combine("../../../../../PDFs/", filename), Path.Combine(Directory.GetCurrentDirectory(), filename), true); // Open the file PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Import); 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}_tempfile.pdf", name, idx + 1)); } {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles
ScrewTurn Wiki version 3.0.5.600. Some of the icons created by
FamFamFam
.
Impressum - Privacy Policy, Data Protection Declaration, Legal Notice