-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdfReaderWrapper.cs
More file actions
55 lines (38 loc) · 1.66 KB
/
PdfReaderWrapper.cs
File metadata and controls
55 lines (38 loc) · 1.66 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using iText.Kernel.Pdf;
namespace PdfSignabilityCheckerTool;
internal class PdfReaderWrapper
{
private readonly MemoryStream _ms;
internal bool IsOpenedWithFullPermission { get; init; }
internal int Permissions { get; init; }
internal bool IsEncrypted { get; init; }
internal PdfDictionary? Trailer { get; init; }
internal PdfDictionary? PermsDictionary { get; set; }
internal PdfDictionary? DocMdpDictionary { get; set; }
internal PdfArray? ReferenceArray { get; set; }
internal PdfDictionary? ReferenceDictionary { get; set; }
internal PdfDictionary? TransformParamsDictionary { get; set; }
internal PdfNumber? P { get; set; }
public PdfReaderWrapper(MemoryStream ms)
{
_ms = ms;
using PdfReader reader = new(ms);
using PdfDocument pdf = new(reader);
IsOpenedWithFullPermission = reader.IsOpenedWithFullPermission();
Permissions = reader.GetPermissions();
IsEncrypted = reader.IsEncrypted();
Trailer = pdf.GetTrailer();
PdfDictionary? rootCatalog = Trailer.GetAsDictionary(PdfName.Root);
PermsDictionary = rootCatalog?.GetAsDictionary(PdfName.Perms);
DocMdpDictionary = PermsDictionary?.GetAsDictionary(PdfName.DocMDP);
ReferenceArray = DocMdpDictionary?.GetAsArray(PdfName.Reference);
ReferenceDictionary = ReferenceArray?.GetAsDictionary(0);
TransformParamsDictionary = ReferenceDictionary?.GetAsDictionary(PdfName.TransformParams);
P = TransformParamsDictionary?.GetAsNumber(PdfName.P);
}
internal PdfReader GetPdfReader()
{
_ms.Position = 0;
return new PdfReader(_ms);
}
}