ViewerLinkOpenMail.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.IO;
  6. using GrapeCity.Documents.Pdf;
  7. using GrapeCity.Documents.Text;
  8. using System.Drawing;
  9. using GrapeCity.Documents.Pdf.Annotations;
  10. using GrapeCity.Documents.Pdf.Actions;
  11.  
  12. namespace DsPdfWeb.Demos
  13. {
  14. // This sample demonstrates how to create a link annotation which will open Mail program.
  15. // It loads an example pdf with sample link annotation added. You can use the annotation editing features of GcPdfViewer
  16. // to inspect or edit existing link annotation, or add new ones.
  17.  
  18. // This and other samples in this section demonstrate the features of GcPdfViewer
  19. // (a JavaScript PDF viewer control included with DsPdf), mainly the ability
  20. // to change PDF files (add or edit annotations and AcroForm fields, rotate pages etc.)
  21. // when the JS viewer on the client is supported by DsPdf running on the server.
  22. //
  23. // To enable the editing features of the viewer, its supportApi property must be set
  24. // to a URL on the server that implements all or some of the edit supporting APIs
  25. // that are known to/expected by the viewer. This DsPdf demo site provides those APIs,
  26. // which makes it possible to demonstrate the editing when you open the PDF viewer
  27. // in this sample. When you download this sample, in addition to the .NET Core
  28. // console app project that generates the sample PDF, an ASP.NET Core project is
  29. // also included in the download zip (located in the GcPdfViewerWeb sub-folder of the
  30. // downloaded zip), which also provides the necessary APIs. In particular, it includes
  31. // a project that implements the APIs and provides them via a special controller.
  32. // It is actually the same controller that is used by this DsPdf demo site, and which
  33. // can be used in any ASP.NET Core site to enable the viewer editing features.
  34. //
  35. // Look at the following files in the sample download zip for more info:
  36. // - GcPdfViewerWeb\SupportApiDemo: the sample ASP.NET Core web site.
  37. // - GcPdfViewerWeb\SupportApiDemo.sln: solution to build/run the sample web site.
  38. // - GcPdfViewerWeb\SupportApi: support API implementation (can be used in any site).
  39. // - GcPdfViewerWeb\SupportApi\Controllers\GcPdfViewerController.cs: support API controller.
  40. //
  41. // Please note that this and other samples in this section are only available in C# at this time.
  42. //
  43. public class ViewerLinkOpenMail
  44. {
  45. public void CreatePDF(Stream stream)
  46. {
  47. var doc = new GcPdfDocument();
  48. var page = doc.NewPage();
  49. var g = page.Graphics;
  50.  
  51. // Draw some text that will represent the link:
  52. var tf = new TextFormat() { Font = StandardFonts.Times, FontSize = 14 };
  53. var tl = g.CreateTextLayout();
  54. tl.MarginAll = 72;
  55. tl.Append("Feel free to email us at example@example.com", tf);
  56. tl.PerformLayout(true);
  57. g.DrawTextLayout(tl, PointF.Empty);
  58.  
  59. // Add a link with mailto URI:
  60. page.Annotations.Add(new LinkAnnotation(tl.ContentRectangle, new ActionURI("mailto:example@example.com")));
  61.  
  62. // Done:
  63. doc.Save(stream);
  64.  
  65. }
  66.  
  67. // Used by SupportApiDemo to initialize GcPdfViewer.
  68. public static GcPdfViewerSupportApiDemo.Models.PdfViewerOptions PdfViewerOptions
  69. {
  70. get => new GcPdfViewerSupportApiDemo.Models.PdfViewerOptions(
  71. GcPdfViewerSupportApiDemo.Models.PdfViewerOptions.Options.AnnotationEditorPanel,
  72. viewerTools: new string[] { "save", "$navigation", "$split", "text-selection", "pan", "$zoom", "$fullscreen", "download", "print", "rotate", "view-mode", "hide-annotations", "doc-properties", "about" },
  73. annotationEditorTools: new string[] { "edit-select", "$split", "edit-link", "$split", "edit-undo", "edit-redo", "save" });
  74. }
  75. }
  76. }
  77.