@@ -23,31 +23,25 @@ Refer to the following code example to split a PDF into individual pages.
2323
2424{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs " %}
2525
26- //Due to platform limitations, Essential<sup >® ; </sup > PDF supports splitting a PDF file into individual pages only in Windows Forms, WPF, ASP.NET, and ASP.NET MVC platforms. However this can be achieved by using the following code snippet.
26+ using Syncfusion.Pdf;
27+ using Syncfusion.Pdf.Parsing;
2728
2829//Load the PDF document
29- FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
30- PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream, true);
31- for (int i = 0; i < loadedDocument.Pages.Count; i++)
32- {
33- //Creates a new document.
34- PdfDocument document = new PdfDocument();
35- //Imports the pages from the loaded document.
36- document.ImportPage(loadedDocument, i);
37-
38- //Create a File stream.
39- using (var outputFileStream = new FileStream("Output" + i + ".pdf", FileMode.Create, FileAccess.Write)) {
40- //Save the document to stream.
41- document.Save(outputFileStream);
42- }
43- //Close the document.
44- document.Close(true);
45- }
30+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
31+ //Set a output path
32+ const string destinationFilePattern = "Output" + "{0}.pdf";
33+ //Split the pages into separate documents
34+ loadedDocument.Split(destinationFilePattern);
35+ //Close the document
36+ loadedDocument.Close(true);
4637
4738{% endhighlight %}
4839
4940{% highlight c# tabtitle="C# [ Windows-specific] " %}
5041
42+ using Syncfusion.Pdf;
43+ using Syncfusion.Pdf.Parsing;
44+
5145//Load the PDF document
5246PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
5347//Set a output path
@@ -61,6 +55,9 @@ loadedDocument.Close(true);
6155
6256{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
6357
58+ Imports Syncfusion.Pdf
59+ Imports Syncfusion.Pdf.Parsing
60+
6461'Load the PDF document
6562Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
6663'Set a output path
@@ -85,30 +82,24 @@ Refer to the following code example to split a range of pages.
8582{% tabs %}
8683{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Split%20PDFs/Split-a-Range-of-Pages/.NET/Split-a-Range-of-Pages/Program.cs " %}
8784
88- {% raw %}
85+ using Syncfusion.Pdf.Parsing;
8986
90- //Load the existing PDF file.
91- PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream("Input.pdf", FileMode.Open));
92- //Subscribe to the document split event.
93- loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent;
94- void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args)
95- {
96- //Save the resulting document.
97- FileStream outputStream = new FileStream(Guid.NewGuid().ToString() + ".pdf", FileMode.CreateNew);
98- args.PdfDocumentData.CopyTo(outputStream);
99- outputStream.Close();
100- }
101- //Spit the document by ranges.
102- loadDocument.SplitByRanges(new int[ ,] { { 0, 5 }, { 5, 10 } });
103-
104- //Close the document.
105- loadDocument.Close(true);
87+ //Create the values.
88+ int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
89+ //Load the PDF document
90+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
91+ //Set a output path
92+ const string destinationFilePattern = "Output" + "{0}.pdf";
93+ //Split the pages into fixed number
94+ loadedDocument.SplitByRanges(destinationFilePattern, values);
95+ //close the document
96+ loadedDocument.Close(true);
10697
107- {% endraw %}
10898{% endhighlight %}
10999
110100{% highlight c# tabtitle="C# [ Windows-specific] " %}
111- {% raw %}
101+
102+ using Syncfusion.Pdf.Parsing;
112103
113104//Create the values.
114105int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
@@ -121,11 +112,11 @@ loadedDocument.SplitByRanges(destinationFilePattern, values);
121112//close the document
122113loadedDocument.Close(true);
123114
124- {% endraw %}
125115{% endhighlight %}
126116
127117{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
128- {% raw %}
118+
119+ Imports Syncfusion.Pdf.Parsing
129120
130121'Create the values.
131122Dim values As Integer(,) = New Integer(,) {{2, 5},{8, 10}}
@@ -138,7 +129,6 @@ loadedDocument.SplitByRanges(destinationFilePattern, values)
138129'Close the document.
139130loadedDocument.Close(True)
140131
141- {% endraw %}
142132{% endhighlight %}
143133
144134{% endtabs %}
@@ -154,27 +144,24 @@ Refer to the following code example to split by a fixed number of pages.
154144
155145{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Split%20PDFs/Split-by-FixedNumber/.NET/Split-by-FixedNumber/Program.cs " %}
156146
157- //Load the existing PDF file.
158- PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream("Input.pdf", FileMode.Open));
159- //Subscribe to the document split event.
160- loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent;
161- void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args)
162- {
163- //Save the resulting document.
164- FileStream outputStream = new FileStream(Guid.NewGuid().ToString() + ".pdf", FileMode.CreateNew);
165- args.PdfDocumentData.CopyTo(outputStream);
166- outputStream.Close();
167- }
168- //Spit the document by a fixed number.
169- loadDocument.SplitByFixedNumber(2);
147+ using Syncfusion.Pdf.Parsing;
170148
171- //Close the document.
172- loadDocument.Close(true);
149+ //Load the PDF document
150+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
151+ //Set a output path
152+ const string destinationFilePattern = "Output" + "{0}.pdf";
153+ //Split the pages into fixed number
154+ loadedDocument.SplitByFixedNumber(destinationFilePattern, 4);
155+
156+ //close the document
157+ loadedDocument.Close(true);
173158
174159{% endhighlight %}
175160
176161{% highlight c# tabtitle="C# [ Windows-specific] " %}
177162
163+ using Syncfusion.Pdf.Parsing;
164+
178165//Load the PDF document
179166PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
180167//Set a output path
@@ -189,6 +176,8 @@ loadedDocument.Close(true);
189176
190177{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
191178
179+ Imports Syncfusion.Pdf.Parsing
180+
192181'Load the PDF document.
193182Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
194183'Set a output path
@@ -214,9 +203,12 @@ Refer to the following code example to split a PDF using bookmarks.
214203
215204{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Split%20PDFs/Split-PDF-based-Bookmarks/.NET/Split-PDF-based-Bookmarks/Program.cs " %}
216205
206+ using Syncfusion.Pdf.Interactive;
207+ using Syncfusion.Pdf.Parsing;
208+ using Syncfusion.Pdf;
209+
217210// Load the PDF document
218- using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
219- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
211+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
220212{
221213 PdfBookmarkBase bookmarks = loadedDocument.Bookmarks;
222214 // Iterate all the bookmarks and their page ranges
@@ -236,11 +228,8 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
236228 }
237229 // Import the pages to the new PDF document
238230 document.ImportPageRange(loadedDocument, bookmark.Destination.PageIndex, endIndex);
239- //Save the document as stream
240- using (MemoryStream stream = new MemoryStream())
241- {
242- document.Save(stream);
243- }
231+ //Save the document
232+ document.Save("Output.pdf");
244233 }
245234 }
246235 }
@@ -251,6 +240,10 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
251240
252241{% highlight c# tabtitle="C# [ Windows-specific] " %}
253242
243+ using Syncfusion.Pdf.Interactive;
244+ using Syncfusion.Pdf.Parsing;
245+ using Syncfusion.Pdf;
246+
254247// Load the PDF document
255248using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
256249{
@@ -272,7 +265,7 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
272265 }
273266 // Import the pages to the new PDF document
274267 document.ImportPageRange(loadedDocument, bookmark.Destination.PageIndex, endIndex);
275- //Save the document as stream
268+ //Save the document
276269 document.Save("Output.pdf");
277270 }
278271 }
@@ -284,6 +277,10 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
284277
285278{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
286279
280+ Imports Syncfusion.Pdf
281+ Imports Syncfusion.Pdf.Parsing
282+ Imports Syncfusion.Pdf.Interactive
283+
287284Using loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
288285Dim bookmarks As PdfBookmarkBase = loadedDocument.Bookmarks
289286For Each bookmark As PdfBookmark In bookmarks
@@ -315,33 +312,31 @@ The Syncfusion<sup>®</sup> PDF library enables the splitting of PDF document
315312{% tabs %}
316313
317314{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Split%20PDFs/Remove-Unused-Resources-when-Splitting-PDF-Documents/.NET/Remove-Unused-Resources-when-Splitting-PDF-Documents/Program.cs " %}
318- {% raw %}
319315
320- //Load the existing PDF file.
321- PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream("Input.pdf", FileMode.Open));
322- //Subscribe to the document split event.
323- loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent;
324- void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args)
325- {
326- //Save the resulting document.
327- FileStream outputStream = new FileStream(Guid.NewGuid().ToString() + ".pdf", FileMode.CreateNew);
328- args.PdfDocumentData.CopyTo(outputStream);
329- outputStream.Close();
330- }
316+ using Syncfusion.Pdf;
317+ using Syncfusion.Pdf.Parsing;
318+
319+ //Create the values.
320+ int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
321+ //Load the PDF document.
322+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
323+ //Set an output file pattern.
324+ const string destinationFilePattern = "Output{0}.pdf";
331325//Create the split options object.
332326PdfSplitOptions splitOptions = new PdfSplitOptions();
333327//Enable the removal of unused resources property.
334328splitOptions.RemoveUnusedResources = true;
335329//Split the document by ranges.
336- loadDocument .SplitByRanges(new int [ , ] { { 0, 5 }, { 5, 10 } } , splitOptions);
330+ loadedDocument .SplitByRanges(destinationFilePattern, values , splitOptions);
337331//Close the document.
338- loadDocument .Close(true);
332+ loadedDocument .Close(true);
339333
340- {% endraw %}
341334{% endhighlight %}
342335
343336{% highlight c# tabtitle="C# [ Windows-specific] " %}
344- {% raw %}
337+
338+ using Syncfusion.Pdf;
339+ using Syncfusion.Pdf.Parsing;
345340
346341//Create the values.
347342int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
@@ -358,11 +353,12 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions);
358353//Close the document.
359354loadedDocument.Close(true);
360355
361- {% endraw %}
362356{% endhighlight %}
363357
364358{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
365- {% raw %}
359+
360+ Imports Syncfusion.Pdf
361+ Imports Syncfusion.Pdf.Parsing
366362
367363'Create the values.
368364Dim values As Integer(,) = New Integer(,) {{2, 5},{8, 10}}
@@ -380,7 +376,6 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions)
380376'Close the document.
381377loadedDocument.Close(True)
382378
383- {% endraw %}
384379{% endhighlight %}
385380
386381{% endtabs %}
@@ -395,34 +390,32 @@ The Syncfusion<sup>®</sup> PDF library enables the splitting of PDF document
395390{% tabs %}
396391
397392{% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Split%20PDFs/Import-tagged-structure-when-splitting-PDF-documents/.NET/Import-tagged-structure-when-splitting-PDF-documents/Program.cs " %}
398- {% raw %}
399393
400- //Load an existing PDF file.
401- PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream("Input.pdf", FileMode.Open));
402- //Subscribe to the document split event.
403- loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent;
404- void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args)
405- {
406- //Save the resulting document.
407- FileStream outputStream = new FileStream(Guid.NewGuid().ToString() + ".pdf", FileMode.CreateNew);
408- args.PdfDocumentData.CopyTo(outputStream);
409- outputStream.Close();
410- }
394+ using Syncfusion.Pdf;
395+ using Syncfusion.Pdf.Parsing;
396+
397+ //Create the values.
398+ int[ ,] values = new int[ ,] { { 0, 1 }, { 1, 2 } };
399+ //Load the PDF document.
400+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
401+ //Set an output file pattern.
402+ const string destinationFilePattern = "Output{0}.pdf";
411403//Create the split options object.
412404PdfSplitOptions splitOptions = new PdfSplitOptions();
413405//Enable the Split tags property.
414406splitOptions.SplitTags = true;
415407//Split the document by ranges.
416- loadDocument .SplitByRanges(new int [ , ] { { 0, 1 }, { 1, 2 } } , splitOptions);
408+ loadedDocument .SplitByRanges(destinationFilePattern, values , splitOptions);
417409
418410//Close the document.
419- loadDocument .Close(true);
411+ loadedDocument .Close(true);
420412
421- {% endraw %}
422413{% endhighlight %}
423414
424415{% highlight c# tabtitle="C# [ Windows-specific] " %}
425- {% raw %}
416+
417+ using Syncfusion.Pdf;
418+ using Syncfusion.Pdf.Parsing;
426419
427420//Create the values.
428421int[ ,] values = new int[ ,] { { 0, 1 }, { 1, 2 } };
@@ -440,11 +433,12 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions);
440433//Close the document.
441434loadedDocument.Close(true);
442435
443- {% endraw %}
444436{% endhighlight %}
445437
446438{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
447- {% raw %}
439+
440+ Imports Syncfusion.Pdf
441+ Imports Syncfusion.Pdf.Parsing
448442
449443'Create the values.
450444Dim values As Integer(,) = New Integer(,) {{0, 1},{1, 2}}
@@ -462,7 +456,6 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions)
462456'Close the document.
463457loadedDocument.Close(True)
464458
465- {% endraw %}
466459{% endhighlight %}
467460
468461{% endtabs %}
0 commit comments