PDFActionHandlerHelper.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 
  2. using System.IO;
  3. namespace Paroxe.PdfRenderer
  4. {
  5. #if !UNITY_WEBGL
  6. /// <summary>
  7. /// Provides default action handling implementation.
  8. /// </summary>
  9. public static class PDFActionHandlerHelper
  10. {
  11. public static void ExecuteAction(IPDFDeviceActionHandler actionHandler, IPDFDevice device, PDFAction action)
  12. {
  13. if (action != null)
  14. {
  15. PDFAction.ActionType type = action.GetActionType();
  16. switch (type)
  17. {
  18. case PDFAction.ActionType.Unsupported:
  19. break;
  20. case PDFAction.ActionType.GoTo:
  21. PDFDest dest = action.GetDest();
  22. actionHandler.HandleGotoAction(device, dest.PageIndex);
  23. break;
  24. case PDFAction.ActionType.RemoteGoTo:
  25. string resolvedFilePath = actionHandler.HandleRemoteGotoActionPathResolving(device,
  26. action.GetFilePath());
  27. if (File.Exists(resolvedFilePath))
  28. {
  29. string password = actionHandler.HandleRemoteGotoActionPasswordResolving(device, resolvedFilePath);
  30. PDFDocument newDocument = new PDFDocument(resolvedFilePath, password);
  31. if (newDocument.IsValid)
  32. {
  33. actionHandler.HandleRemoteGotoActionResolved(device, newDocument, action.GetDest().PageIndex);
  34. }
  35. else
  36. {
  37. actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);
  38. }
  39. }
  40. else
  41. {
  42. actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);
  43. }
  44. break;
  45. case PDFAction.ActionType.Uri:
  46. actionHandler.HandleUriAction(device, action.GetURIPath());
  47. break;
  48. case PDFAction.ActionType.Launch:
  49. actionHandler.HandleLaunchAction(device, action.GetFilePath());
  50. break;
  51. }
  52. }
  53. }
  54. public static void ExecuteBookmarkAction(IPDFDevice device, PDFBookmark bookmark)
  55. {
  56. if (device.BookmarksActionHandler != null)
  57. {
  58. PDFDest dest = bookmark.GetDest();
  59. if (dest != null)
  60. {
  61. device.BookmarksActionHandler.HandleGotoAction(device, dest.PageIndex);
  62. }
  63. else
  64. {
  65. PDFAction action = bookmark.GetAction();
  66. if (action != null)
  67. ExecuteAction(device.BookmarksActionHandler, device, action);
  68. }
  69. }
  70. }
  71. public static void ExecuteLinkAction(IPDFDevice device, PDFLink link)
  72. {
  73. if (device.LinksActionHandler != null)
  74. {
  75. PDFDest dest = link.GetDest();
  76. if (dest != null)
  77. {
  78. device.LinksActionHandler.HandleGotoAction(device, dest.PageIndex);
  79. }
  80. else
  81. {
  82. PDFAction action = link.GetAction();
  83. if (action != null)
  84. ExecuteAction(device.LinksActionHandler, device, action);
  85. }
  86. }
  87. }
  88. }
  89. #endif
  90. }