-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathGettingStartedPDF.cs
237 lines (201 loc) · 12.5 KB
/
GettingStartedPDF.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#region Copyright Syncfusion Inc. 2001-2016.
// Copyright Syncfusion Inc. 2001-2016. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.IO;
using Syncfusion.Drawing;
using System.Reflection;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Barcode;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Interactive;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using CGRect = System.Drawing.RectangleF;
using CGPoint = System.Drawing.PointF;
using CGSize = System.Drawing.SizeF;
#endif
namespace SampleBrowser
{
public partial class GettingStartedPDF : SampleView
{
CGRect frameRect = new CGRect();
float frameMargin = 8.0f;
PdfDocument doc;
PdfPage page;
Syncfusion.Drawing.Color gray = Syncfusion.Drawing.Color.FromArgb(255, 77, 77, 77);
Syncfusion.Drawing.Color black = Syncfusion.Drawing.Color.FromArgb(255, 0, 0, 0);
Syncfusion.Drawing.Color white = Syncfusion.Drawing.Color.FromArgb(255, 255, 255, 255);
Syncfusion.Drawing.Color violet = Syncfusion.Drawing.Color.FromArgb(255, 151, 108, 174);
UILabel label1;
UIButton button ;
public GettingStartedPDF()
{
label1 = new UILabel();
button = new UIButton(UIButtonType.System);
button.TouchUpInside += OnButtonClicked;
}
void LoadAllowedTextsLabel()
{
label1.Frame = frameRect;
label1.TextColor = UIColor.FromRGB(38 / 255.0f, 38 / 255.0f, 38 / 255.0f);
label1.Text = "This sample demonstrates how to create a simple PDF document with text and images.";
label1.Font = UIFont.SystemFontOfSize(15);
label1.Lines = 0;
label1.LineBreakMode = UILineBreakMode.WordWrap;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
label1.Font = UIFont.SystemFontOfSize(18);
label1.Frame = new CGRect(0, 12, frameRect.Location.X + frameRect.Size.Width, 50);
}
else {
label1.Frame = new CGRect(frameRect.Location.X, 12, frameRect.Size.Width, 50);
}
this.AddSubview(label1);
button.SetTitle("Generate PDF", UIControlState.Normal);
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
button.Frame = new CGRect(0, 70, frameRect.Location.X + frameRect.Size.Width, 10);
}
else {
button.Frame = new CGRect(frameRect.Location.X, 70, frameRect.Size.Width, 10);
}
this.AddSubview(button);
}
void OnButtonClicked(object sender, EventArgs e)
{
doc = new PdfDocument();
doc.PageSettings.Margins.All = 0;
page = doc.Pages.Add();
PdfGraphics g = page.Graphics;
PdfFont headerFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 35);
PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);
g.DrawRectangle(new PdfSolidBrush(gray), new RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
g.DrawRectangle(new PdfSolidBrush(black), new RectangleF(0, 0, page.Graphics.ClientSize.Width, 130));
g.DrawRectangle(new PdfSolidBrush(white), new RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450));
g.DrawString("Syncfusion", headerFont, new PdfSolidBrush(violet), new PointF(10, 20));
g.DrawRectangle(new PdfSolidBrush(violet), new RectangleF(10, 63, 155, 35));
g.DrawString("File Formats", subHeadingFont, new PdfSolidBrush(black), new PointF(45, 70));
PdfLayoutResult result = HeaderPoints("Optimized for usage in a server environment where spread and low memory usage in critical.", 15);
result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15);
result = HeaderPoints("Microsoft Excel, Word, Presentation, PDF and PDF Viewer.", result.Bounds.Bottom + 15);
result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks.", result.Bounds.Bottom + 15);
result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45);
result = BodyContent("Enable your applications to read and write file formats documents easily.", result.Bounds.Bottom + 25);
result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25);
result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25);
result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25);
PdfPen redPen = new PdfPen(PdfBrushes.Red, 2);
g.DrawLine(redPen, new PointF(40, result.Bounds.Bottom + 92), new PointF(40, result.Bounds.Bottom + 145));
float headerBulletsXposition = 40;
PdfTextElement txtElement = new PdfTextElement("The Experts");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200));
PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2);
g.DrawLine(violetPen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145));
txtElement = new PdfTextElement("Accurate Estimates");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200));
txtElement = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks.");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));
txtElement = new PdfTextElement("Given our expertise, you can expect estimates to be accurate.");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));
PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2);
g.DrawLine(greenPen, new PointF(40, result.Bounds.Bottom + 32), new PointF(40, result.Bounds.Bottom + 85));
txtElement = new PdfTextElement("No-Hassle Licensing");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200));
PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2);
g.DrawLine(bluePen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85));
txtElement = new PdfTextElement("About Syncfusion");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200));
txtElement = new PdfTextElement("No royalties, run time, or server deployment fees means no surprises.");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));
txtElement = new PdfTextElement("Syncfusion offers over 1,000 components and frameworks for mobile, web, and desktop development.");
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));
Stream imgStream = typeof(GettingStartedPDF).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Xamarin_bannerEdit.jpg");
g.DrawImage(PdfImage.FromStream(imgStream), 180, 630, 280, 150);
g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new PointF(10, g.ClientSize.Height - 30));
PdfTextWebLink linkAnnot = new PdfTextWebLink();
linkAnnot.Url = "http://www.syncfusion.com";
linkAnnot.Text = "www.syncfusion.com";
linkAnnot.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic);
linkAnnot.Brush = PdfBrushes.White;
linkAnnot.DrawTextWebLink(page, new PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30));
MemoryStream stream = new MemoryStream();
doc.Save(stream);
doc.Close(true);
if (stream != null)
{
SaveiOS iosSave = new SaveiOS();
iosSave.Save("GettingStarted.pdf", "application/pdf", stream);
}
}
public override void LayoutSubviews()
{
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
frameMargin = 0.0f;
}
frameRect = Bounds;
frameRect.Location = new CGPoint(frameRect.Location.X + frameMargin, frameRect.Location.Y + 1.5f * frameMargin);
frameRect.Size = new CGSize(frameRect.Size.Width - (frameRect.Location.X + frameMargin), frameRect.Size.Height - (frameRect.Location.Y + 1.5f * frameMargin));
LoadAllowedTextsLabel();
base.LayoutSubviews();
}
private PdfLayoutResult BodyContent(string text, float yPosition)
{
float headerBulletsXposition = 35;
PdfTextElement txtElement = new PdfTextElement("3");
txtElement.Font = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 16);
txtElement.Brush = new PdfSolidBrush(violet);
txtElement.StringFormat = new PdfStringFormat();
txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
txtElement.StringFormat.LineLimit = true;
txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 320, 100));
txtElement = new PdfTextElement(text);
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 17);
txtElement.Brush = new PdfSolidBrush(white);
txtElement.StringFormat = new PdfStringFormat();
txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
txtElement.StringFormat.LineLimit = true;
PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 25, yPosition, 450, 130));
return result;
}
private PdfLayoutResult HeaderPoints(string text, float yPosition)
{
float headerBulletsXposition = 220;
PdfTextElement txtElement = new PdfTextElement("l");
txtElement.Font = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 10);
txtElement.Brush = new PdfSolidBrush(violet);
txtElement.StringFormat = new PdfStringFormat();
txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
txtElement.StringFormat.LineLimit = true;
txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 300, 100));
txtElement = new PdfTextElement(text);
txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11);
txtElement.Brush = new PdfSolidBrush(white);
txtElement.StringFormat = new PdfStringFormat();
txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
txtElement.StringFormat.LineLimit = true;
PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 20, yPosition, 320, 100));
return result;
}
}
}