You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/NET/Merge-Documents.md
+16-45Lines changed: 16 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,21 +24,16 @@ Refer to the following code example to merge multiple documents from disk.
24
24
//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.
25
25
//Creates a PDF document.
26
26
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" };
31
29
//Merges PDFDocument.
32
-
PdfDocumentBase.Merge(finalDoc, streams);
30
+
PdfDocumentBase.Merge(finalDoc, source);
33
31
34
32
//Save the document into stream.
35
33
MemoryStream stream = new MemoryStream();
36
34
finalDoc.Save(stream);
37
35
//Close the document.
38
36
finalDoc.Close(true);
39
-
//Disposes the streams.
40
-
stream1.Dispose();
41
-
stream2.Dispose();
42
37
43
38
{% endhighlight %}
44
39
@@ -392,22 +387,16 @@ The following code shows how to merge multiple PDF documents using [Merge](https
392
387
393
388
//Creates a PDF document.
394
389
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" };
400
392
//Merges PDFDocument.
401
-
PdfDocumentBase.Merge(finalDoc, streams);
393
+
PdfDocumentBase.Merge(finalDoc, source);
402
394
403
395
//Save the document into stream.
404
396
MemoryStream stream = new MemoryStream();
405
397
finalDoc.Save(stream);
406
398
//Close the document.
407
399
finalDoc.Close(true);
408
-
//Disposes the streams.
409
-
stream1.Dispose();
410
-
stream2.Dispose();
411
400
412
401
{% endhighlight %}
413
402
@@ -457,25 +446,19 @@ Refer to the following code example to optimize the PDF resources when merging P
457
446
//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.
458
447
//Create a PDF document.
459
448
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" };
465
451
PdfMergeOptions mergeOptions = new PdfMergeOptions();
0 commit comments