-
Notifications
You must be signed in to change notification settings - Fork 3
/
PageHelper.cs
63 lines (50 loc) · 1.92 KB
/
PageHelper.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using iDiTect.Pdf.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Pdf.Demo
{
public static class PageHelper
{
public static void InsertPage()
{
PdfFile pdfFile = new PdfFile();
PdfDocument document = pdfFile.Import(File.ReadAllBytes("sample.pdf"));
//Create a new Pdf page
PdfPage page = new PdfPage();
//Insert new page after the first page of document
document.Pages.Insert(1, page);
File.WriteAllBytes("InsertPage.pdf", pdfFile.Export(document));
}
public static void RemovePage()
{
PdfFile pdfFile = new PdfFile();
PdfDocument document = pdfFile.Import(File.ReadAllBytes("sample.pdf"));
//Delete the second page of document
document.Pages.RemoveAt(1);
File.WriteAllBytes("RemovePage.pdf", pdfFile.Export(document));
}
public static void SplitPage()
{
PdfFile pdfFile = new PdfFile();
PdfDocument document = pdfFile.Import(File.ReadAllBytes("sample.pdf"));
//Split each page to a new Pdf document
List<PdfDocument> splitDocuments = document.Split();
for (int i = 0; i < splitDocuments.Count; i++)
{
PdfDocument split = splitDocuments[i];
File.WriteAllBytes(String.Format("Split-page{0}.pdf", i + 1), pdfFile.Export(split));
}
}
public static void MergePage()
{
PdfFile pdfFile = new PdfFile();
PdfDocument document = pdfFile.Import(File.ReadAllBytes("sample.pdf"));
PdfDocument document2 = pdfFile.Import(File.ReadAllBytes("sample2.pdf"));
document.Merge(document2);
File.WriteAllBytes("MergePage.pdf", pdfFile.Export(document));
}
}
}