forked from ststeiger/PdfSharpCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge.cs
More file actions
41 lines (36 loc) · 1.26 KB
/
Merge.cs
File metadata and controls
41 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.IO;
using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;
using PdfSharpCore.Test.Helpers;
using Xunit;
namespace PdfSharpCore.Test
{
public class Merge
{
[Fact]
public void CanMerge2Documents()
{
var pdf1Path = PathHelper.GetInstance().GetAssetPath("FamilyTree.pdf");
var pdf2Path = PathHelper.GetInstance().GetAssetPath("test.pdf");
var outputDocument = new PdfDocument();
foreach (var pdfPath in new[] { pdf1Path, pdf2Path })
{
using var fs = File.OpenRead(pdfPath);
var inputDocument = Pdf.IO.PdfReader.Open(fs, PdfDocumentOpenMode.Import);
var count = inputDocument.PageCount;
for (var idx = 0; idx < count; idx++)
{
var page = inputDocument.Pages[idx];
outputDocument.AddPage(page);
}
}
var outFilePath = Path.Combine(PathHelper.GetInstance().RootDir, "Out", "merge.pdf");
var dir = Path.GetDirectoryName(outFilePath);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
outputDocument.Save(outFilePath);
}
}
}