LinkToURL.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.IO
  6. Imports System.Drawing
  7. Imports System.Numerics
  8. Imports GrapeCity.Documents.Pdf
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Pdf.Annotations
  12. Imports GrapeCity.Documents.Pdf.Actions
  13.  
  14. '' A simple way to create a link to an external URL,
  15. '' and associate it with a text on a page.
  16. Public Class LinkToURL
  17. Function CreatePDF(ByVal stream As Stream) As Integer
  18. Dim doc = New GcPdfDocument()
  19. Dim page = doc.NewPage()
  20. Dim g = page.Graphics
  21.  
  22. '' Draw some text that will represent the link:
  23. Dim tl = g.CreateTextLayout()
  24. tl.MarginAll = 72
  25. tl.Append("Google google on the wall, please tell me all!",
  26. New TextFormat() With {.Font = StandardFonts.Times, .FontSize = 14})
  27. tl.PerformLayout(True)
  28. g.DrawTextLayout(tl, PointF.Empty)
  29.  
  30. '' Add a link associated with the text area:
  31. page.Annotations.Add(New LinkAnnotation(tl.ContentRectangle, New ActionURI("http://www.google.com")))
  32. ''
  33. '' Done:
  34. doc.Save(stream)
  35. Return doc.Pages.Count
  36. End Function
  37. End Class
  38.