-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITextTestCases.cs
More file actions
59 lines (47 loc) · 1.73 KB
/
ITextTestCases.cs
File metadata and controls
59 lines (47 loc) · 1.73 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
56
57
58
59
using iText.Kernel.Events;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using System.IO;
namespace CDT.WARS {
public class PageRotation {
public static readonly PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
public static readonly PdfNumber LANDSCAPE = new PdfNumber(90);
public static readonly PdfNumber PORTRAIT = new PdfNumber(0);
public static readonly PdfNumber SEASCAPE = new PdfNumber(270);
public void ManipulatePdf(string dest) {
var eventHandler = new PageRotationEventHandler();
using (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest))) {
pdfDoc.AddEventHandler(PdfDocumentEvent.START_PAGE, eventHandler);
using (var doc = new Document(pdfDoc)) {
//Portrait (0)
eventHandler.SetRotation(PORTRAIT);
doc.Add(new Paragraph($"Hello World!\nRotation: {PORTRAIT}"));
//landscape (90)
eventHandler.SetRotation(LANDSCAPE);
doc.Add(new AreaBreak());
doc.Add(new Paragraph($"Hello World!\nRotation: {LANDSCAPE}"));
//inverted portrait (180)
eventHandler.SetRotation(INVERTEDPORTRAIT);
doc.Add(new AreaBreak());
doc.Add(new Paragraph($"Hello World!\nRotation: {INVERTEDPORTRAIT}"));
//Seascape (270)
eventHandler.SetRotation(SEASCAPE);
doc.Add(new AreaBreak());
doc.Add(new Paragraph($"Hello World!\nRotation: {SEASCAPE}"));
doc.Close();
}
}
}
}
internal class PageRotationEventHandler : IEventHandler {
protected PdfNumber rotation = PageRotation.PORTRAIT;
public void SetRotation(PdfNumber orientation) {
this.rotation = orientation;
}
public void HandleEvent(Event @event) {
PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
docEvent.GetPage().Put(PdfName.Rotate, rotation);
}
}
}