PDFViewerDefaultActionHandler.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. namespace Paroxe.PdfRenderer.Internal.Viewer
  3. {
  4. class PDFViewerDefaultActionHandler : IPDFDeviceActionHandler
  5. {
  6. public void HandleGotoAction(IPDFDevice device, int pageIndex)
  7. {
  8. device.GoToPage(pageIndex);
  9. }
  10. public void HandleLaunchAction(IPDFDevice device, string filePath)
  11. {
  12. #if !UNITY_WEBGL
  13. if (filePath.Trim().Substring(filePath.Length - 4).ToLower().Contains("pdf"))
  14. {
  15. device.LoadDocumentFromFile(filePath, "", 0);
  16. }
  17. #endif
  18. }
  19. public string HandleRemoteGotoActionPasswordResolving(IPDFDevice device, string resolvedFilePath)
  20. {
  21. return "";
  22. }
  23. public string HandleRemoteGotoActionPathResolving(IPDFDevice device, string filePath)
  24. {
  25. return filePath;
  26. }
  27. public void HandleRemoteGotoActionResolved(IPDFDevice device, PDFDocument document, int pageIndex)
  28. {
  29. #if !UNITY_WEBGL
  30. device.LoadDocument(document, "", pageIndex);
  31. #endif
  32. }
  33. public void HandleRemoteGotoActionUnresolved(IPDFDevice device, string resolvedFilePath)
  34. {
  35. // ...
  36. }
  37. public void HandleUnsuportedAction(IPDFDevice device)
  38. {
  39. // ...
  40. }
  41. public void HandleUriAction(IPDFDevice device, string uri)
  42. {
  43. if (uri.Trim().Substring(uri.Length - 4).ToLower().Contains("pdf"))
  44. {
  45. #if !UNITY_WEBGL
  46. device.LoadDocumentFromWeb(uri, "", 0);
  47. #endif
  48. }
  49. else if (device.AllowOpenURL)
  50. {
  51. if (uri.Trim().ToLowerInvariant().StartsWith("http:")
  52. || uri.Trim().ToLowerInvariant().StartsWith("https:")
  53. || uri.Trim().ToLowerInvariant().StartsWith("ftp:"))
  54. {
  55. Application.OpenURL(uri);
  56. }
  57. }
  58. }
  59. }
  60. }