forked from UglyToad/PdfPig
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGithubIssuesTests.cs
156 lines (128 loc) · 5.76 KB
/
GithubIssuesTests.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
namespace UglyToad.PdfPig.Tests.Integration
{
using Content;
using DocumentLayoutAnalysis.PageSegmenter;
using DocumentLayoutAnalysis.WordExtractor;
public class GithubIssuesTests
{
[Fact]
public void Issue945()
{
// Odd ligatures names
var path = IntegrationHelpers.GetDocumentPath("MOZILLA-3136-0.pdf");
using (var document = PdfDocument.Open(path))
{
var page = document.GetPage(2);
Assert.Contains("ff", page.Letters.Select(l => l.Value));
}
path = IntegrationHelpers.GetDocumentPath("68-1990-01_A.pdf");
using (var document = PdfDocument.Open(path))
{
var page = document.GetPage(7);
Assert.Contains("fi", page.Letters.Select(l => l.Value));
}
path = IntegrationHelpers.GetDocumentPath("TIKA-2054-0.pdf");
using (var document = PdfDocument.Open(path))
{
var page = document.GetPage(3);
Assert.Contains("fi", page.Letters.Select(l => l.Value));
page = document.GetPage(4);
Assert.Contains("ff", page.Letters.Select(l => l.Value));
page = document.GetPage(6);
Assert.Contains("fl", page.Letters.Select(l => l.Value));
page = document.GetPage(16);
Assert.Contains("ffi", page.Letters.Select(l => l.Value));
}
}
[Fact]
public void Issue943()
{
var path = IntegrationHelpers.GetDocumentPath("MOZILLA-10225-0.pdf");
using (var document = PdfDocument.Open(path))
{
var page = document.GetPage(1);
Assert.NotNull(page);
var letters = page.Letters;
Assert.NotNull(letters);
var words = NearestNeighbourWordExtractor.Instance.GetWords(page.Letters);
var blocks = DocstrumBoundingBoxes.Instance.GetBlocks(words);
Assert.Equal("Rocket and Spacecraft Propulsion", blocks[0].TextLines[0].Text);
Assert.Equal("Principles, Practice and New Developments (Second Edition)", blocks[0].TextLines[1].Text);
}
}
[Fact]
public void Issue736()
{
var doc = IntegrationHelpers.GetDocumentPath("Approved_Document_B__fire_safety__volume_2_-_Buildings_other_than_dwellings__2019_edition_incorporating_2020_and_2022_amendments.pdf");
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
Assert.True(document.TryGetBookmarks(out var bookmarks));
Assert.Single(bookmarks.Roots);
Assert.Equal(36, bookmarks.Roots[0].Children.Count);
}
}
[Fact]
public void Issue693()
{
var doc = IntegrationHelpers.GetDocumentPath("reference-2-numeric-error.pdf");
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
var page1 = document.GetPage(1);
Assert.Equal(1269, page1.Letters.Count);
}
}
[Fact]
public void Issue692()
{
var doc = IntegrationHelpers.GetDocumentPath("cmap-parsing-exception.pdf");
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
var page1 = document.GetPage(1);
Assert.Equal(796, page1.Letters.Count);
}
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = false, SkipMissingFonts = false }))
{
var ex = Assert.Throws<InvalidOperationException>(() => document.GetPage(1));
Assert.StartsWith("Read byte called on input bytes which was at end of byte set.", ex.Message);
}
}
[Fact]
public void Issue874()
{
var doc = IntegrationHelpers.GetDocumentPath("ErcotFacts.pdf");
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
var page1 = document.GetPage(1);
Assert.Equal(1788, page1.Letters.Count);
var page2 = document.GetPage(2);
Assert.Equal(2430, page2.Letters.Count);
}
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = false }))
{
var ex = Assert.Throws<ArgumentNullException>(() => document.GetPage(1));
Assert.StartsWith("Value cannot be null.", ex.Message);
}
}
[Fact]
public void Issue913()
{
var doc = IntegrationHelpers.GetSpecificTestDocumentPath("Rotation 45.pdf");
using (var document = PdfDocument.Open(doc))
{
var page1 = document.GetPage(1);
for (int l = 131; l <= 137; ++l)
{
var letter = page1.Letters[l];
Assert.Equal(TextOrientation.Other, letter.TextOrientation);
Assert.Equal(45.0, letter.GlyphRectangle.Rotation, 5);
}
var page2 = document.GetPage(2);
Assert.Equal(157, page2.Letters.Count);
var page3 = document.GetPage(3);
Assert.Equal(283, page3.Letters.Count);
var page4 = document.GetPage(4);
Assert.Equal(304, page4.Letters.Count);
}
}
}
}