LinkToURL.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using GrapeCity.Documents.Text;
  9. using GrapeCity.Documents.Pdf;
  10. using GrapeCity.Documents.Pdf.Annotations;
  11. using GrapeCity.Documents.Pdf.Actions;
  12.  
  13. namespace DsPdfWeb.Demos
  14. {
  15. // A simple way to create a link to an external URL,
  16. // and associate it with a text on a page.
  17. public class LinkToURL
  18. {
  19. public int CreatePDF(Stream stream)
  20. {
  21. var doc = new GcPdfDocument();
  22. var page = doc.NewPage();
  23. var g = page.Graphics;
  24.  
  25. // Draw some text that will represent the link:
  26. var tf = new TextFormat() { Font = StandardFonts.Times, FontSize = 14 };
  27. var tl = g.CreateTextLayout();
  28. tl.MarginAll = 72;
  29. tl.Append("Google google on the wall, please tell me all!", tf);
  30. tl.PerformLayout(true);
  31. g.DrawTextLayout(tl, PointF.Empty);
  32.  
  33. // Add a link associated with the text area:
  34. page.Annotations.Add(new LinkAnnotation(tl.ContentRectangle, new ActionURI("http://www.google.com")));
  35.  
  36. // Done:
  37. doc.Save(stream);
  38. return doc.Pages.Count;
  39. }
  40. }
  41. }
  42.