Skip to content

Commit d1652ca

Browse files
Merge pull request #2083 from Syncfusion-Content/hotfix/hotfix-v32.1.19
DOCINFRA-2341_merged_using_automation
2 parents 9335b13 + 5fdac69 commit d1652ca

1 file changed

Lines changed: 16 additions & 45 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Merge-Documents.md

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,16 @@ Refer to the following code example to merge multiple documents from disk.
2424
//Due to platform limitations, the PDF file cannot be loaded from disk. However, you can merge multiple documents from stream using the following code snippet.
2525
//Creates a PDF document.
2626
PdfDocument finalDoc = new PdfDocument();
27-
FileStream stream1 = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read);
28-
FileStream stream2 = new FileStream("file2.pdf", FileMode.Open, FileAccess.Read);
29-
//Creates a PDF stream for merging.
30-
Stream[] streams = { stream1, stream2 };
27+
//Creates a string array of source files to be merged.
28+
string[] source = { "file1.pdf", "file2.pdf" };
3129
//Merges PDFDocument.
32-
PdfDocumentBase.Merge(finalDoc, streams);
30+
PdfDocumentBase.Merge(finalDoc, source);
3331

3432
//Save the document into stream.
3533
MemoryStream stream = new MemoryStream();
3634
finalDoc.Save(stream);
3735
//Close the document.
3836
finalDoc.Close(true);
39-
//Disposes the streams.
40-
stream1.Dispose();
41-
stream2.Dispose();
4237

4338
{% endhighlight %}
4439

@@ -392,22 +387,16 @@ The following code shows how to merge multiple PDF documents using [Merge](https
392387

393388
//Creates a PDF document.
394389
PdfDocument finalDoc = new PdfDocument();
395-
//Load the PDF document.
396-
FileStream stream1 = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read);
397-
FileStream stream2 = new FileStream("file2.pdf", FileMode.Open, FileAccess.Read);
398-
//Creates a PDF stream for merging.
399-
Stream[] streams = { stream1, stream2 };
390+
//Creates a string array of source files to be merged.
391+
string[] source = { "file1.pdf", "file2.pdf" };
400392
//Merges PDFDocument.
401-
PdfDocumentBase.Merge(finalDoc, streams);
393+
PdfDocumentBase.Merge(finalDoc, source);
402394

403395
//Save the document into stream.
404396
MemoryStream stream = new MemoryStream();
405397
finalDoc.Save(stream);
406398
//Close the document.
407399
finalDoc.Close(true);
408-
//Disposes the streams.
409-
stream1.Dispose();
410-
stream2.Dispose();
411400

412401
{% endhighlight %}
413402

@@ -457,25 +446,19 @@ Refer to the following code example to optimize the PDF resources when merging P
457446
//Due to platform limitations, the PDF file cannot be loaded from disk. However, you can optimize PDF resources when merging multiple documents from stream using the following code snippet.
458447
//Create a PDF document.
459448
PdfDocument finalDoc = new PdfDocument();
460-
//Load the PDF document.
461-
FileStream stream1 = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read);
462-
FileStream stream2 = new FileStream("file2.pdf", FileMode.Open, FileAccess.Read);
463-
//Creates a PDF stream for merging.
464-
Stream[] streams = { stream1, stream2 };
449+
//Creates a string array of source files to be merged.
450+
string[] source = { "file1.pdf", "file2.pdf" };
465451
PdfMergeOptions mergeOptions = new PdfMergeOptions();
466452
//Enable Optimize Resources.
467453
mergeOptions.OptimizeResources = true;
468454
//Merges PDFDocument.
469-
PdfDocumentBase.Merge(finalDoc, mergeOptions, streams);
455+
PdfDocumentBase.Merge(finalDoc, mergeOptions, source);
470456

471457
//Save the document into stream.
472458
MemoryStream stream = new MemoryStream();
473459
finalDoc.Save(stream);
474460
//Close the document.
475461
finalDoc.Close(true);
476-
//Disposes the streams.
477-
stream1.Dispose();
478-
stream2.Dispose();
479462

480463
{% endhighlight %}
481464

@@ -538,25 +521,19 @@ PdfMargins margin= new PdfMargins();
538521
margin.All=40;
539522
//Set margin.
540523
finalDoc.PageSettings.Margins = margin;
541-
//Load the PDF document.
542-
FileStream stream1 = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read);
543-
FileStream stream2 = new FileStream("file2.pdf", FileMode.Open, FileAccess.Read);
544-
//Create a PDF stream for merging.
545-
Stream[] streams = { stream1, stream2 };
524+
//Creates a string array of source files to be merged.
525+
string[] source = { "file1.pdf", "file2.pdf" };
546526
PdfMergeOptions mergeOptions = new PdfMergeOptions();
547527
//Enable the Extend Margin.
548528
mergeOptions.ExtendMargin = true;
549529
//Merge PDFDocument.
550-
PdfDocumentBase.Merge(finalDoc, mergeOptions, streams);
530+
PdfDocumentBase.Merge(finalDoc, mergeOptions, source);
551531

552532
//Save the document into stream.
553533
MemoryStream stream = new MemoryStream();
554534
finalDoc.Save(stream);
555535
//Close the document.
556536
finalDoc.Close(true);
557-
//Dispose the stream.
558-
stream1.Dispose();
559-
stream2.Dispose();
560537

561538
{% endhighlight %}
562539

@@ -625,24 +602,18 @@ The Syncfusion<sup>&reg;</sup> PDF library enables users to merge PDF documents
625602

626603
//Create a PDF document.
627604
PdfDocument finalDoc = new PdfDocument();
628-
//Load the PDF document.
629-
FileStream stream1 = new FileStream("file1.pdf", FileMode.Open, FileAccess.Read);
630-
FileStream stream2 = new FileStream("file2.pdf", FileMode.Open, FileAccess.Read);
631-
//Create a PDF stream for merging.
632-
Stream[] streams = { stream1, stream2 };
605+
//Create a string array of source files to be merged.
606+
string[] source = { "file1.pdf", "file2.pdf" };
633607
PdfMergeOptions mergeOptions = new PdfMergeOptions();
634608
//Enable the Merge Accessibility Tags.
635609
mergeOptions.MergeAccessibilityTags = true;
636610
//Merge PDFDocument.
637-
PdfDocumentBase.Merge(finalDoc, mergeOptions, streams);
611+
PdfDocumentBase.Merge(finalDoc, mergeOptions, source);
638612
//Save the document into stream.
639613
MemoryStream stream = new MemoryStream();
640614
finalDoc.Save(stream);
641615
//Close the document.
642-
finalDoc.Close(true);
643-
//Dispose the stream.
644-
stream1.Dispose();
645-
stream2.Dispose();
616+
finalDoc.Close(true);
646617

647618
{% endhighlight %}
648619

0 commit comments

Comments
 (0)