GcDocsDataSheet.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System
  6. Imports System.IO
  7. Imports System.Drawing
  8. Imports System.Linq
  9. Imports System.Collections.Generic
  10. Imports GrapeCity.Documents.Pdf
  11. Imports GrapeCity.Documents.Pdf.AcroForms
  12. Imports GrapeCity.Documents.Text
  13. Imports GrapeCity.Documents.Common
  14. Imports GrapeCity.Documents.Drawing
  15. Imports System.Numerics
  16.  
  17. '' This sample generates a two-page data sheet about the new
  18. '' Document Solutions product line.
  19. Public Class GcDocsDataSheet
  20. Private _fc As New FontCollection()
  21. Private _darkGray As Color = Color.FromArgb(64, 64, 64)
  22. Private _lightGray As Color = Color.FromArgb(232, 232, 232)
  23. Private _blue As Color = Color.FromArgb(&H3B, &H5C, &HAA)
  24. Private _disposables As List(Of IDisposable) = New List(Of IDisposable)
  25.  
  26. '' Main entry point of this sample
  27. Function CreatePDF(ByVal stream As Stream) As Integer
  28. Dim doc = New GcPdfDocument()
  29. _fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
  30. '' First page:
  31. Page1(doc)
  32. '' Second page:
  33. Page2(doc)
  34. '' Save the PDF:
  35. doc.Save(stream)
  36. '' Dispose images after the document has been saved:
  37. _disposables.ForEach(Sub(d_) d_.Dispose())
  38. '' Done:
  39. Return doc.Pages.Count
  40. End Function
  41.  
  42. Private Function GetImage(ByVal path As String) As IImage
  43. Dim Image = ImageFromFile(path)
  44. _disposables.Add(Image)
  45. Return Image
  46. End Function
  47.  
  48. Private Sub Page1(ByVal doc As GcPdfDocument)
  49. Dim page = doc.Pages.Add()
  50. Dim g = page.Graphics
  51. Dim tl = New TextLayout(g.Resolution) With {.FontCollection = _fc}
  52.  
  53. Dim gclogo = GetImage(Path.Combine("Resources", "ImagesBis", "gc-logo-100px.png"))
  54. Dim gclogoRc = New RectangleF(36, 0, 72 * 1.8F, 72)
  55. Dim rcs As RectangleF() = Nothing
  56. g.DrawImage(gclogo, gclogoRc, Nothing,
  57. New ImageAlign(ImageAlignHorz.Left, ImageAlignVert.Center, True, True, True, False, False), rcs)
  58. g.DrawLine(rcs(0).Right + 10, rcs(0).Top, rcs(0).Right + 10, rcs(0).Bottom, _darkGray, 1)
  59.  
  60. tl.Clear()
  61. tl.ParagraphAlignment = ParagraphAlignment.Center
  62. tl.MaxHeight = gclogoRc.Height
  63. tl.Append("Developer Solutions",
  64. New TextFormat() With {.FontName = "open sans", .FontSize = 16, .ForeColor = _darkGray})
  65. tl.PerformLayout(True)
  66. g.DrawTextLayout(tl, New PointF(gclogoRc.Right + 20, gclogoRc.Y))
  67.  
  68. Dim back = GetImage(Path.Combine("Resources", "ImagesBis", "GCDocs-datasheet-sm.png"))
  69. Dim backRcClip = New RectangleF(0, 72, page.Size.Width, page.Size.Width - 72 * 1.75F)
  70. Dim backRc = New RectangleF(-72, -72 * 4, page.Size.Width + 72 * 4, page.Size.Height + 72 * 4)
  71. g.DrawImage(back, backRc, backRcClip, ImageAlign.StretchImage)
  72. g.FillRectangle(New RectangleF(0, backRcClip.Bottom, page.Size.Width, page.Size.Height - backRcClip.Bottom), _lightGray)
  73. g.DrawLine(backRcClip.X, backRcClip.Bottom, backRcClip.Right, backRcClip.Bottom, Color.White, 1, DashStyle.Solid)
  74. g.DrawLine(backRcClip.X, backRcClip.Bottom + 1, backRcClip.Right, backRcClip.Bottom + 1, _darkGray, 1, DashStyle.Solid)
  75.  
  76. Dim blueRc = New RectangleF(0, backRcClip.Y, page.Size.Width, 72 * 4)
  77. g.FillRectangle(blueRc, Color.FromArgb(220, _blue))
  78.  
  79. blueRc.Inflate(0, -36)
  80. g.FillRectangle(New RectangleF(blueRc.Location, New SizeF(10, blueRc.Height)), Color.White)
  81.  
  82. blueRc.Inflate(-36, 0)
  83. tl.Clear()
  84. tl.ParagraphAlignment = ParagraphAlignment.Near
  85. tl.MaxWidth = blueRc.Width
  86. tl.MaxHeight = blueRc.Height
  87. tl.Append("NEW PRODUCT LINE",
  88. New TextFormat() With {.FontName = "open sans semibold", .FontSize = 20, .ForeColor = Color.White})
  89. tl.PerformLayout(True)
  90. g.DrawTextLayout(tl, blueRc.Location)
  91.  
  92. Dim midRc = New RectangleF(blueRc.X, blueRc.Y + tl.ContentHeight, blueRc.Width, blueRc.Height - tl.ContentHeight)
  93.  
  94. tl.Clear()
  95. tl.ParagraphAlignment = ParagraphAlignment.Far
  96. tl.Append(
  97. "Take total control of your digital documents with this NEW collection of ultra-fast, low-footprint document APIs for .NET Standard 2.0. These intuitive, extensible APIs " +
  98. "allow you to create, load, modify, and save Excel spreadsheets and PDF files in any .NET Standard 2.0 application",
  99. New TextFormat() With {.FontName = "open sans light", .FontSize = 14, .ForeColor = Color.White})
  100. tl.PerformLayout(True)
  101. g.DrawTextLayout(tl, blueRc.Location)
  102.  
  103. midRc.Height -= tl.ContentHeight
  104. midRc.Inflate(0, -20)
  105.  
  106. Dim hex = GetImage(Path.Combine("Resources", "ImagesBis", "gcd-hex-logo-white.png"))
  107. Dim hexRc = New RectangleF(midRc.Location, New SizeF(midRc.Height, midRc.Height))
  108. g.DrawImage(hex, hexRc, Nothing, ImageAlign.StretchImage)
  109.  
  110. tl.Clear()
  111. tl.ParagraphAlignment = ParagraphAlignment.Center
  112. tl.MaxHeight = midRc.Height
  113. tl.Append("Document Solutions",
  114. New TextFormat() With {.FontName = "open sans semibold", .FontSize = 26, .ForeColor = Color.White})
  115. tl.PerformLayout(True)
  116. g.DrawTextLayout(tl, New PointF(midRc.X + midRc.Height + 10, midRc.Y))
  117.  
  118. Dim pointRc = New RectangleF(0, backRcClip.Bottom, page.Size.Width / 2, (page.Size.Height - backRcClip.Bottom) / 2 - 12)
  119. tl.ParagraphAlignment = ParagraphAlignment.Near
  120. tl.MaxWidth = pointRc.Width
  121. tl.MaxHeight = pointRc.Height
  122. tl.MarginLeft = 80
  123. tl.MarginTop = 25
  124. tl.MarginBottom = 0
  125.  
  126. Dim addPoint As Action(Of IImage, String, String) =
  127. Sub(img, caption, text)
  128. Dim imgRect = New RectangleF(pointRc.X + 20, pointRc.Y + tl.MarginTop, 48, 48)
  129. g.DrawImage(img, imgRect, Nothing, New ImageAlign() With {.AlignHorz = ImageAlignHorz.Center, .AlignVert = ImageAlignVert.Center, .BestFit = True})
  130. tl.Clear()
  131. tl.AppendLine(caption, New TextFormat() With {.FontName = "open sans semibold", .FontSize = 11})
  132. tl.Append(text, New TextFormat() With {.FontName = "open sans light", .FontSize = 11})
  133. tl.PerformLayout(True)
  134. If Not tl.ContentHeightFitsInBounds Then
  135. Throw New Exception("Unexpected: text overflow.")
  136. End If
  137. g.DrawTextLayout(tl, pointRc.Location)
  138. End Sub
  139.  
  140. Dim drawCircle As Action(Of PointF) =
  141. Sub(p)
  142. Dim d = 128.0F
  143. Dim angle = (16 * Math.PI) / 180.0F
  144. g.Transform =
  145. Matrix3x2.CreateTranslation(-d / 2, -d / 2) *
  146. Matrix3x2.CreateRotation(angle) *
  147. Matrix3x2.CreateTranslation(p.X + d / 2, p.Y + d / 2)
  148.  
  149. Dim rr = New RectangleF(PointF.Empty, New SizeF(d, d))
  150. For i = 0 To 2
  151. g.FillEllipse(rr, Color.FromArgb(30 + i * 10, _darkGray))
  152. rr.Inflate(-1, -1)
  153. Next
  154. g.FillEllipse(rr, _darkGray)
  155. rr.Inflate(-1, -1)
  156. g.FillEllipse(rr, Color.White)
  157. rr.Inflate(-6, -6)
  158. g.FillEllipse(rr, _darkGray)
  159.  
  160. tl.Clear()
  161. tl.MaxHeight = d
  162. tl.MaxWidth = d
  163. tl.MarginLeft = 0
  164. tl.MarginRight = 0
  165. tl.MarginTop = 0
  166. tl.MarginBottom = 0
  167. tl.TextAlignment = TextAlignment.Center
  168. tl.ParagraphAlignment = ParagraphAlignment.Center
  169. tl.ParagraphSpacing = -4
  170. Dim tf = New TextFormat() With {.FontName = "open sans light", .FontSize = 18, .ForeColor = Color.White}
  171. tl.Append("DEPLOY" + vbCrLf + "TO", tf)
  172. tl.Append(" AZURE" + vbCrLf, New TextFormat(tf) With {.FontName = "open sans semibold"})
  173. tl.Append(" ")
  174. tl.PerformLayout(True)
  175. g.DrawTextLayout(tl, PointF.Empty)
  176. g.Transform = Matrix3x2.Identity
  177. End Sub
  178.  
  179. addPoint(GetImage(Path.Combine("Resources", "ImagesBis", "ico-hex-.NET.png")),
  180. "Expand the reach of modern apps",
  181. "With full support for .NET Standard 2.0, you can target multiple platforms, devices, and cloud with one code base.")
  182.  
  183. pointRc.Offset(0, pointRc.Height)
  184. addPoint(GetImage(Path.Combine("Resources", "ImagesBis", "ico-hex-code.png")),
  185. "Comprehensive, highly programmable",
  186. "Do more with your Excel spreadsheets and PDFs: these APIs support Windows, Mac, Linux, and a wide variety of features for your documents.")
  187.  
  188. pointRc.Offset(pointRc.Width, -pointRc.Height)
  189. tl.MarginRight = 30
  190. addPoint(GetImage(Path.Combine("Resources", "ImagesBis", "ico-hex-speed.png")),
  191. "High-speed, small footprint",
  192. "The API architecture is designed to generate large, optimized documents, fast—while remaining lightweight and extensible.")
  193.  
  194. pointRc.Offset(0, pointRc.Height)
  195. addPoint(GetImage(Path.Combine("Resources", "ImagesBis", "ico-hex-nodependences.png")),
  196. "No dependencies",
  197. "Generate and edit digital documents with no Acrobat or Excel dependencies.")
  198.  
  199. g.FillRectangle(New RectangleF(0, page.Size.Height - 16, page.Size.Width, 16), _darkGray)
  200.  
  201. drawCircle(New PointF(page.Size.Width - 160, backRcClip.Bottom - 105))
  202.  
  203. End Sub
  204.  
  205. Private Class Bullet
  206. Public Property Caption As String
  207. Public Property Points As List(Of String)
  208. End Class
  209.  
  210. Private Sub Page2(ByVal doc As GcPdfDocument)
  211. Dim page = doc.Pages.Add()
  212. Dim g = page.Graphics
  213. Dim tl = New TextLayout(g.Resolution) With {.FontCollection = _fc}
  214. Dim col0X = 36
  215. Dim colWidth = page.Size.Width / 3 - 40
  216. Dim colGap = 20
  217. Dim vgap = 10
  218. Dim ser1Y = 100
  219. Dim ser2Y = 72 * 6
  220. Dim h = 45
  221.  
  222. Dim dspdf = New List(Of Bullet) From
  223. {
  224. New Bullet() With {.Caption = "Advanced Text Handling", .Points = New List(Of String) From {
  225. "Standard PDF Fonts, Truetype Fonts, Open type Fonts, WOFF Fonts, system font loading, font embedding, fallback and linked fonts, EUDC fonts",
  226. "Advanced text rendering features",
  227. "Special character support"
  228. }},
  229. New Bullet() With {.Caption = "Cross-Platform, Cross-Framework compatibility", .Points = New List(Of String) From {
  230. ".NET Standard 2.0",
  231. ".NET Core 2.0",
  232. ".NET Framework",
  233. "Mono",
  234. "Xamarin iOS",
  235. "VSTO-style API"
  236. }},
  237. New Bullet() With {.Caption = "Security", .Points = New List(Of String) From {
  238. "Encryption and decrpyption",
  239. "User and owner passwords",
  240. "AllowCopyContent, AllowEditAnnotations, AllowEditContent, AllowPrint",
  241. "Digital Signatures"
  242. }},
  243. New Bullet() With {.Caption = "Annotations", .Points = New List(Of String) From {
  244. "Figures",
  245. "Comments",
  246. "Text",
  247. "Signatures",
  248. "Stamps",
  249. "Modify, extract or delete annotations from existing PDFs"
  250. }},
  251. New Bullet() With {.Caption = "Fillable Form Fields", .Points = New List(Of String) From {
  252. "Textbox",
  253. "Checkbox",
  254. "Combobox",
  255. "Listbox",
  256. "Radio button",
  257. "Push button",
  258. "Signature field",
  259. "Modify, extract or delete form fields from existing PDFs"
  260. }},
  261. New Bullet() With {.Caption = "Navigation", .Points = New List(Of String) From {
  262. "Outlines",
  263. "Hyperlinks"
  264. }},
  265. New Bullet() With {.Caption = "Additional Features", .Points = New List(Of String) From {
  266. "50 barcodes and properties",
  267. "Create PDF/A files",
  268. "Maintain document history with document properties",
  269. "Generate linearized PDFs for fast web view",
  270. "Full image and graphic support on all platforms",
  271. "Add and delete pages",
  272. "Chage page sizes",
  273. "Page orientation"
  274. }}
  275. }
  276.  
  277. Dim gcexcel = New List(Of Bullet) From
  278. {
  279. New Bullet() With {.Caption = "Fast and Efficient", .Points = New List(Of String) From {
  280. "Lightweight",
  281. "Optimized for processing large Excel documents quickly"
  282. }},
  283. New Bullet() With {.Caption = "Cross-Platform, Cross-Framework compatibility", .Points = New List(Of String) From {
  284. ".NET Standard 2.0",
  285. ".NET Core 2.0",
  286. ".NET Framework",
  287. "Mono",
  288. "Xamarin.iOS",
  289. "VSTO-style API"
  290. }},
  291. New Bullet() With {.Caption = "Data Visualization", .Points = New List(Of String) From {
  292. "Shapes and pictures",
  293. "Slicers",
  294. "Sparklines",
  295. "Charts"
  296. }},
  297. New Bullet() With {.Caption = "Powerful Calculation Engine", .Points = New List(Of String) From {
  298. "450+ Excel functions",
  299. "Calculate",
  300. "Query",
  301. "Generate",
  302. "Sorting",
  303. "Filtering",
  304. "Grouping"
  305. }},
  306. New Bullet() With {.Caption = "Seamless Excel Compatibility", .Points = New List(Of String) From {
  307. "Import and export Excel files",
  308. "Export to PDF",
  309. "Encrypt files",
  310. "Workbooks and worksheets",
  311. "Cell range operations",
  312. "Pivot and Excel tables",
  313. "Data validation",
  314. "Annotations",
  315. "Comments"
  316. }},
  317. New Bullet() With {.Caption = "Conditional Formatting Rules", .Points = New List(Of String) From {
  318. "Cell value",
  319. "Average",
  320. "Color scale",
  321. "Data bar",
  322. "Icon sets",
  323. "Top and Bottom",
  324. "Unique",
  325. "Expression"
  326. }},
  327. New Bullet() With {.Caption = "Flexible Themes And Components", .Points = New List(Of String) From {
  328. "Customizable themes",
  329. "Configurable components",
  330. "Summary data",
  331. "Custom styles",
  332. "Embedded drawing objects",
  333. "Integrated calculation engine"
  334. }}
  335. }
  336.  
  337. Dim addHeader As Action(Of Single, String, String) =
  338. Sub(y, caption, text)
  339. Dim bluerc = New RectangleF(0, y, 28, h)
  340. g.FillRectangle(bluerc, _blue)
  341. Dim caprc = New RectangleF(bluerc.Right, y, 72 * 2.75F, h)
  342. g.FillRectangle(caprc, _lightGray)
  343. caprc.X = col0X
  344. caprc.Width -= col0X - bluerc.Width
  345. g.DrawString(caption, New TextFormat() With {.FontName = "open sans semibold", .FontSize = 12}, caprc, TextAlignment.Leading, ParagraphAlignment.Center, False)
  346. Dim textrc = New RectangleF(caprc.Right, caprc.Top, page.Size.Width - caprc.Right, caprc.Height)
  347. textrc.Inflate(-10, 0)
  348. g.DrawString(text, New TextFormat() With {.FontName = "open sans light", .FontSize = 9}, textrc, TextAlignment.Leading, ParagraphAlignment.Center, True)
  349. End Sub
  350.  
  351. Dim addList As Func(Of PointF, String, List(Of String), RectangleF) =
  352. Function(ByVal pt, ByVal caption, ByVal items)
  353. Dim tf = New TextFormat() With {.FontName = "open sans light", .FontSize = 9}
  354. Dim ret = New RectangleF(pt, SizeF.Empty)
  355. tl.Clear()
  356. tl.MaxWidth = colWidth
  357. tl.AppendLine(caption, New TextFormat() With {.FontName = "open sans", .FontBold = True, .FontSize = 9})
  358. tl.PerformLayout(True)
  359. g.DrawTextLayout(tl, pt)
  360. ret.Width = tl.ContentWidth
  361. ret.Height = tl.ContentHeight
  362. pt.Y += ret.Height
  363. tl.Clear()
  364. Dim itemPrefix = $"{ChrW(&H2022)} "
  365. tl.FirstLineIndent = -g.MeasureStringWithTrailingWhitespace(itemPrefix, tf).Width
  366. For Each item In items
  367. tl.AppendLine(itemPrefix + item, tf)
  368. Next
  369. tl.PerformLayout(True)
  370. g.DrawTextLayout(tl, pt)
  371. ret.Width = Math.Max(ret.Width, tl.ContentWidth)
  372. ret.Height += tl.ContentHeight
  373. Return ret
  374. End Function
  375.  
  376. addHeader(45,
  377. "Document Solutions for PDF",
  378. "This high-speed, feature-rich PDF document API for .NET Standard 2.0 gives you total " +
  379. "control of your PDF documents, with no dependencies on Adobe Acrobat.Generate, " +
  380. "edit, and store feature - rich PDF documents without compromising design or features.")
  381.  
  382. Dim ipt = New PointF(col0X, ser1Y)
  383. For Each bullet In dspdf
  384. Dim rc = addList(ipt, bullet.Caption, bullet.Points)
  385. If (rc.Bottom < ser2Y - 120) Then
  386. ipt = New PointF(rc.X, rc.Bottom + vgap)
  387. Else
  388. ipt = New PointF(rc.X + colWidth + colGap, ser1Y)
  389. End If
  390. Next
  391.  
  392. addHeader(ser2Y,
  393. "Document Solutions for Excel",
  394. "Generate high-performance Excel spreadsheets with no dependencies on Excel! " +
  395. "Generate, convert, calculate, format, and parse spreadsheets in any app.")
  396.  
  397. Dim topY = ser2Y + h + 10
  398. ipt = New PointF(col0X, topY)
  399. For Each bullet In gcexcel
  400. Dim rc = addList(ipt, bullet.Caption, bullet.Points)
  401. If (rc.Bottom < page.Size.Height - 100) Then
  402. ipt = New PointF(rc.X, rc.Bottom + vgap)
  403. Else
  404. ipt = New PointF(rc.X + colWidth + colGap, topY)
  405. End If
  406. Next
  407.  
  408. Dim hdrRc = New RectangleF(28, 0, page.Size.Width - 28 * 2, 36)
  409. g.FillRectangle(hdrRc, _darkGray)
  410. Dim w = hdrRc.Width / 7
  411. Dim hdrs = New String() {"Create", "Load", "Edit", "Save", "Analyze"}
  412.  
  413. Dim hdrTf = New TextFormat() With {.FontName = "open sans", .FontSize = 12, .ForeColor = Color.White}
  414. Dim trc = New RectangleF(hdrRc.X + w, hdrRc.Y, w, hdrRc.Height)
  415. For i = 0 To hdrs.Length - 1
  416. g.DrawString(hdrs(i), hdrTf, trc, TextAlignment.Center, ParagraphAlignment.Center, False)
  417. If (i < hdrs.Length - 1) Then
  418. g.DrawLine(trc.Right, trc.Top + 12, trc.Right, trc.Bottom - 12, Color.White, 1)
  419. End If
  420. trc.Offset(w, 0)
  421. Next
  422.  
  423. Dim ftrRc = New RectangleF(0, page.Size.Height - 36, page.Size.Width, 36)
  424. g.FillRectangle(ftrRc, _darkGray)
  425. Dim ftr0 = "mescius.com"
  426. Dim ftr1 = "(c) MESCIUS inc.All rights reserved.All other product and brand names are trademarks and/or registered trademarks of their respective holders."
  427. ftrRc.Inflate(-col0X, -5)
  428. hdrTf.FontSize = 12
  429. g.DrawString(ftr0, hdrTf, ftrRc, TextAlignment.Leading, ParagraphAlignment.Near, False)
  430. hdrTf.FontSize = 6
  431. g.DrawString(ftr1, hdrTf, ftrRc, TextAlignment.Leading, ParagraphAlignment.Far, False)
  432. ftrRc.Inflate(0, -5)
  433. g.DrawImage(GetImage(Path.Combine("Resources", "ImagesBis", "logo-GC-white.png")), ftrRc, Nothing,
  434. New ImageAlign() With {.AlignHorz = ImageAlignHorz.Right, .AlignVert = ImageAlignVert.Center, .BestFit = True})
  435. End Sub
  436. End Class
  437.