@@ -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
@@ -87,29 +84,28 @@ Refer to the following code example to split a range of pages.
8784
8885{% raw %}
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 } });
87+ using Syncfusion.Pdf.Parsing;
10388
104- //Close the document.
105- loadDocument.Close(true);
89+ //Create the values.
90+ int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
91+ //Load the PDF document
92+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
93+ //Set a output path
94+ const string destinationFilePattern = "Output" + "{0}.pdf";
95+ //Split the pages into fixed number
96+ loadedDocument.SplitByRanges(destinationFilePattern, values);
97+ //close the document
98+ loadedDocument.Close(true);
10699
107100{% endraw %}
108101{% endhighlight %}
109102
110103{% highlight c# tabtitle="C# [ Windows-specific] " %}
104+
111105{% raw %}
112106
107+ using Syncfusion.Pdf.Parsing;
108+
113109//Create the values.
114110int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
115111//Load the PDF document
@@ -127,6 +123,8 @@ loadedDocument.Close(true);
127123{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
128124{% raw %}
129125
126+ Imports Syncfusion.Pdf.Parsing
127+
130128'Create the values.
131129Dim values As Integer(,) = New Integer(,) {{2, 5},{8, 10}}
132130'Load the PDF document.
@@ -137,7 +135,6 @@ Const destinationFilePattern As String = "Output" + "{0}.pdf"
137135loadedDocument.SplitByRanges(destinationFilePattern, values)
138136'Close the document.
139137loadedDocument.Close(True)
140-
141138{% endraw %}
142139{% endhighlight %}
143140
@@ -154,27 +151,24 @@ Refer to the following code example to split by a fixed number of pages.
154151
155152{% 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 " %}
156153
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);
154+ using Syncfusion.Pdf.Parsing;
170155
171- //Close the document.
172- loadDocument.Close(true);
156+ //Load the PDF document
157+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
158+ //Set a output path
159+ const string destinationFilePattern = "Output" + "{0}.pdf";
160+ //Split the pages into fixed number
161+ loadedDocument.SplitByFixedNumber(destinationFilePattern, 4);
162+
163+ //close the document
164+ loadedDocument.Close(true);
173165
174166{% endhighlight %}
175167
176168{% highlight c# tabtitle="C# [ Windows-specific] " %}
177169
170+ using Syncfusion.Pdf.Parsing;
171+
178172//Load the PDF document
179173PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
180174//Set a output path
@@ -189,6 +183,8 @@ loadedDocument.Close(true);
189183
190184{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
191185
186+ Imports Syncfusion.Pdf.Parsing
187+
192188'Load the PDF document.
193189Dim loadedDocument As New PdfLoadedDocument("Input.pdf")
194190'Set a output path
@@ -214,9 +210,12 @@ Refer to the following code example to split a PDF using bookmarks.
214210
215211{% 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 " %}
216212
213+ using Syncfusion.Pdf.Interactive;
214+ using Syncfusion.Pdf.Parsing;
215+ using Syncfusion.Pdf;
216+
217217// Load the PDF document
218- using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
219- using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
218+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
220219{
221220 PdfBookmarkBase bookmarks = loadedDocument.Bookmarks;
222221 // Iterate all the bookmarks and their page ranges
@@ -236,11 +235,8 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
236235 }
237236 // Import the pages to the new PDF document
238237 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- }
238+ //Save the document
239+ document.Save("Output.pdf");
244240 }
245241 }
246242 }
@@ -251,6 +247,10 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
251247
252248{% highlight c# tabtitle="C# [ Windows-specific] " %}
253249
250+ using Syncfusion.Pdf.Interactive;
251+ using Syncfusion.Pdf.Parsing;
252+ using Syncfusion.Pdf;
253+
254254// Load the PDF document
255255using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
256256{
@@ -272,7 +272,7 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
272272 }
273273 // Import the pages to the new PDF document
274274 document.ImportPageRange(loadedDocument, bookmark.Destination.PageIndex, endIndex);
275- //Save the document as stream
275+ //Save the document
276276 document.Save("Output.pdf");
277277 }
278278 }
@@ -284,6 +284,10 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"))
284284
285285{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
286286
287+ Imports Syncfusion.Pdf
288+ Imports Syncfusion.Pdf.Parsing
289+ Imports Syncfusion.Pdf.Interactive
290+
287291Using loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
288292Dim bookmarks As PdfBookmarkBase = loadedDocument.Bookmarks
289293For Each bookmark As PdfBookmark In bookmarks
@@ -315,34 +319,35 @@ The Syncfusion<sup>®</sup> PDF library enables the splitting of PDF document
315319{% tabs %}
316320
317321{% 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 " %}
322+
318323{% raw %}
324+ using Syncfusion.Pdf;
325+ using Syncfusion.Pdf.Parsing;
319326
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- }
327+ //Create the values.
328+ int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
329+ //Load the PDF document.
330+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
331+ //Set an output file pattern.
332+ const string destinationFilePattern = "Output{0}.pdf";
331333//Create the split options object.
332334PdfSplitOptions splitOptions = new PdfSplitOptions();
333335//Enable the removal of unused resources property.
334336splitOptions.RemoveUnusedResources = true;
335337//Split the document by ranges.
336- loadDocument .SplitByRanges(new int [ , ] { { 0, 5 }, { 5, 10 } } , splitOptions);
338+ loadedDocument .SplitByRanges(destinationFilePattern, values , splitOptions);
337339//Close the document.
338- loadDocument .Close(true);
340+ loadedDocument .Close(true);
339341
340342{% endraw %}
341343{% endhighlight %}
342344
343345{% highlight c# tabtitle="C# [ Windows-specific] " %}
344346{% raw %}
345347
348+ using Syncfusion.Pdf;
349+ using Syncfusion.Pdf.Parsing;
350+
346351//Create the values.
347352int[ ,] values = new int[ ,] { { 2, 5 }, { 8, 10 } };
348353//Load the PDF document.
@@ -364,6 +369,9 @@ loadedDocument.Close(true);
364369{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
365370{% raw %}
366371
372+ Imports Syncfusion.Pdf
373+ Imports Syncfusion.Pdf.Parsing
374+
367375'Create the values.
368376Dim values As Integer(,) = New Integer(,) {{2, 5},{8, 10}}
369377'Load the PDF document.
@@ -379,7 +387,6 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions)
379387
380388'Close the document.
381389loadedDocument.Close(True)
382-
383390{% endraw %}
384391{% endhighlight %}
385392
@@ -396,33 +403,31 @@ The Syncfusion<sup>®</sup> PDF library enables the splitting of PDF document
396403
397404{% 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 " %}
398405{% raw %}
406+ using Syncfusion.Pdf;
407+ using Syncfusion.Pdf.Parsing;
399408
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- }
409+ //Create the values.
410+ int[ ,] values = new int[ ,] { { 0, 1 }, { 1, 2 } };
411+ //Load the PDF document.
412+ PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
413+ //Set an output file pattern.
414+ const string destinationFilePattern = "Output{0}.pdf";
411415//Create the split options object.
412416PdfSplitOptions splitOptions = new PdfSplitOptions();
413417//Enable the Split tags property.
414418splitOptions.SplitTags = true;
415419//Split the document by ranges.
416- loadDocument .SplitByRanges(new int [ , ] { { 0, 1 }, { 1, 2 } } , splitOptions);
420+ loadedDocument .SplitByRanges(destinationFilePattern, values , splitOptions);
417421
418422//Close the document.
419- loadDocument.Close(true);
420-
423+ loadedDocument.Close(true);
421424{% endraw %}
422425{% endhighlight %}
423426
424427{% highlight c# tabtitle="C# [ Windows-specific] " %}
425428{% raw %}
429+ using Syncfusion.Pdf;
430+ using Syncfusion.Pdf.Parsing;
426431
427432//Create the values.
428433int[ ,] values = new int[ ,] { { 0, 1 }, { 1, 2 } };
@@ -439,12 +444,13 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions);
439444
440445//Close the document.
441446loadedDocument.Close(true);
442-
443447{% endraw %}
444448{% endhighlight %}
445449
446450{% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
447451{% raw %}
452+ Imports Syncfusion.Pdf
453+ Imports Syncfusion.Pdf.Parsing
448454
449455'Create the values.
450456Dim values As Integer(,) = New Integer(,) {{0, 1},{1, 2}}
@@ -461,7 +467,6 @@ loadedDocument.SplitByRanges(destinationFilePattern, values, splitOptions)
461467
462468'Close the document.
463469loadedDocument.Close(True)
464-
465470{% endraw %}
466471{% endhighlight %}
467472
0 commit comments