using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Paroxe.PdfRenderer.Internal;
using Paroxe.PdfRenderer.Internal.Viewer;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Paroxe.PdfRenderer.WebGL;
#if NETFX_CORE && !UNITY_WSA_10_0
using WinRTLegacy;
#endif
namespace Paroxe.PdfRenderer
{
///
/// PDFViewer is an Unity UI component that allow you to visualize PDF Document.
///
public class PDFViewer : UIBehaviour, IPDFDevice, IPDFColoredRectListProvider
{
[SerializeField] public PDFViewerInternal m_Internal;
private IPDFDeviceActionHandler m_BookmarksActionHandler;
private IPDFDeviceActionHandler m_LinksActionHandler;
private PDFPageRange m_CurrentPageRange;
private PDFSearchResult m_CurrentSearchResult;
private PDFDocument m_Document;
private PDFDocument m_SuppliedDocument;
private PDFPageTextureHolder[] m_PageTextureHolders;
private int m_CurrentSearchResultIndex;
private int m_CurrentSearchResultIndexWithinCurrentPage;
private bool m_DelayedOnEnable;
private float m_InvalidPasswordMessageDelay;
#if !UNITY_WEBGL || UNITY_EDITOR
private float m_InvalidPasswordMessageDelayBeforeFade = 0.5f;
#endif
private bool m_InvalidPasswordMessageVisisble;
private bool m_IsLoaded;
private int m_LoadAtPageIndex;
private float m_OverlayAlpha = 0.50f;
private bool m_OverlayVisible;
private int m_PageCount;
private float[] m_PageOffsets;
private Vector2[] m_PageSizes;
private Vector2[] m_NormalPageSizes;
private byte[] m_PendingDocumentBuffer;
private int m_PreviousMostVisiblePage = -1;
private PageFittingType m_PreviousPageFitting;
private Vector2 m_PreviousViewportSize = Vector2.zero;
private float m_PreviousZoom;
private float m_PreviousZoomToGo;
private IList[] m_SearchResults;
private float m_StartZoom;
private float m_UpdateChangeDelay;
private Vector2 m_ViewportSize = Vector2.zero;
#if !UNITY_WEBGL || UNITY_EDITOR
private WWW m_WWW;
#endif
private Vector2 m_ZoomPosition = Vector2.zero;
private PDFRenderer m_Renderer;
private Canvas m_Canvas;
/// ...
private PDFThumbnailsViewer m_ThumbnailsViewer;
private PDFBookmarksViewer m_BookmarksViewer;
[SerializeField] private bool m_AllowOpenURL = true;
[SerializeField] private Component m_BytesSupplierComponent;
[SerializeField] private string m_BytesSupplierFunctionName;
[SerializeField] private GameObject m_BytesSupplierObject;
[SerializeField] private string m_FileName = "";
[SerializeField] private string m_FilePath = "";
[SerializeField] private FileSourceType m_FileSource = FileSourceType.Resources;
[SerializeField] private string m_FileURL = "";
[SerializeField] private string m_Folder = "";
[SerializeField] private bool m_LoadOnEnable = true;
[SerializeField] private float m_MaxZoomFactor = 8.0f;
[SerializeField] private float m_MaxZoomFactorTextureQuality = 4.0f;
[SerializeField] private float m_MinZoomFactor = 0.25f;
[SerializeField] private PageFittingType m_PageFitting = PageFittingType.Zoom;
[SerializeField] private string m_Password = "";
[SerializeField] private PDFAsset m_PDFAsset = null;
[SerializeField] private float m_ZoomFactor = 1.0f;
[SerializeField] private float m_ZoomStep = 0.25f;
[SerializeField] private float m_ZoomToGo;
[SerializeField] private float m_VerticalMarginBetweenPages = 20.0f;
[SerializeField] private bool m_UnloadOnDisable;
[SerializeField] private bool m_ShowVerticalScrollBar = false;
[SerializeField] private bool m_ShowBookmarksViewer = true;
[SerializeField] private bool m_ShowHorizontalScrollBar = true;
[SerializeField] private bool m_ShowThumbnailsViewer = true;
[SerializeField] private bool m_ShowTopBar = false;
[SerializeField] private float m_ScrollSensitivity = 75.0f;
[SerializeField] private Color m_SearchResultColor = new Color(0.0f, 115 / 255.0f, 230 / 255.0f, 125 / 255.0f);
[SerializeField] private Vector2 m_SearchResultPadding = new Vector2(2.0f, 4.0f);
[SerializeField] private float m_SearchTimeBudgetPerFrame = 0.60f;
[SerializeField] private PDFRenderer.RenderSettings m_RenderSettings = new PDFRenderer.RenderSettings();
[SerializeField] private float m_DelayAfterZoomingBeforeUpdate = 0.005f;
[SerializeField] private float m_ParagraphZoomFactor = 2.0f;
[SerializeField] private bool m_ParagraphZoomingEnable = true;
[SerializeField] private float m_ParagraphDetectionThreshold = 12.0f;
[SerializeField] private Texture2D m_PageTileTexture;
[SerializeField] private Color m_PageColor = Color.white;
public delegate void CancelEventHandler(PDFViewer sender);
public delegate void CurrentPageChangedEventHandler(PDFViewer sender, int oldPageIndex, int newPageIndex);
public delegate void DocumentChangedEventHandler(PDFViewer sender, PDFDocument document);
public delegate void LoadFailEventHandler(PDFViewer sender);
public delegate void PDFViewerEventHandler(PDFViewer sender);
public delegate void ZoomChangedEventHandler(PDFViewer sender, float oldZoom, float newZoom);
public event CurrentPageChangedEventHandler OnCurrentPageChanged;
public event PDFViewerEventHandler OnDisabled;
public event DocumentChangedEventHandler OnDocumentLoaded;
public event LoadFailEventHandler OnDocumentLoadFailed;
public event DocumentChangedEventHandler OnDocumentUnloaded;
public event CancelEventHandler OnDownloadCancelled;
public event CancelEventHandler OnPasswordCancelled;
public event ZoomChangedEventHandler OnZoomChanged;
public enum FileSourceType
{
None,
Web,
StreamingAssets,
Resources,
FilePath,
Bytes,
Asset,
DocumentObject
}
public enum PageFittingType
{
ViewerWidth,
ViewerHeight,
WholePage,
Zoom
}
public enum ViewerModeType
{
Move,
ZoomOut,
ZoomIn
}
///
/// Specify if the PDFViewer can open url link with external browser.
///
public bool AllowOpenURL
{
get { return m_AllowOpenURL; }
set { m_AllowOpenURL = value; }
}
///
/// Specify the viewport background color.
///
public Color BackgroundColor
{
get { return m_Internal.m_Viewport.GetComponent().color; }
set
{
if (m_Internal.m_Viewport.GetComponent().color != value)
{
m_Internal.m_Viewport.GetComponent().color = value;
}
}
}
///
/// Specify the relative amount of time is allowed for text search per frame (0.0f to 1.0f).
///
public float SearchTimeBudgetPerFrame
{
get { return m_SearchTimeBudgetPerFrame; }
set { m_SearchTimeBudgetPerFrame = Mathf.Clamp01(value); }
}
///
/// Specify the action handler for bookmarks.
///
public IPDFDeviceActionHandler BookmarksActionHandler
{
get { return m_BookmarksActionHandler; }
set { m_BookmarksActionHandler = value; }
}
///
/// Specify the action handler for links.
///
public IPDFDeviceActionHandler LinksActionHandler
{
get { return m_LinksActionHandler; }
set { m_LinksActionHandler = value; }
}
///
/// This property is intended to be used along side with the bytes file source. (FileSource.Bytes)
/// Specify from which component the byte suplier function resides.
///
public Component BytesSupplierComponent
{
get { return m_BytesSupplierComponent; }
set { m_BytesSupplierComponent = value; }
}
///
/// This property is intended to be used along side with the bytes file source. (FileSource.Bytes)
/// Specify the function name whithin the byte supplier component.
///
public string BytesSupplierFunctionName
{
get { return m_BytesSupplierFunctionName; }
set { m_BytesSupplierFunctionName = value; }
}
///
/// This property is intended to be used along side with the bytes file source. (FileSource.Bytes)
/// Specify the object in which the bytes suppliers component resides.
///
public GameObject BytesSupplierObject
{
get { return m_BytesSupplierObject; }
set { m_BytesSupplierObject = value; }
}
public int CurrentPageIndex
{
get { return GetMostVisiblePageIndex(); }
set
{
int mostVisible = GetMostVisiblePageIndex();
if (value != mostVisible)
{
GoToPage(value);
}
}
}
public int CurrentSearchResultIndex
{
get { return m_CurrentSearchResultIndex; }
}
///
/// Return the byte array of the current loaded pdf document.
///
public byte[] DataBuffer
{
get
{
if (Document != null)
{
return m_Document.DocumentBuffer;
}
return null;
}
}
public PDFDocument Document
{
get { return m_Document; }
}
public string FileName
{
get { return m_FileName; }
set { m_FileName = value; }
}
public string FilePath
{
get { return m_FilePath; }
set { m_FilePath = value; }
}
public FileSourceType FileSource
{
get { return m_FileSource; }
set { m_FileSource = value; }
}
public string FileURL
{
get { return m_FileURL; }
set { m_FileURL = value; }
}
public string Folder
{
get { return m_Folder; }
set { m_Folder = value; }
}
public bool IsLoaded
{
get { return m_IsLoaded; }
}
public bool LoadOnEnable
{
get { return m_LoadOnEnable; }
set { m_LoadOnEnable = value; }
}
public float MaxZoomFactor
{
get { return m_MaxZoomFactor; }
set { m_MaxZoomFactor = value; }
}
public float MaxZoomFactorTextureQuality
{
get { return m_MaxZoomFactorTextureQuality; }
set
{
if (Math.Abs(Mathf.Clamp(value, MinZoomFactor, MaxZoomFactor) - m_MaxZoomFactorTextureQuality) >
float.Epsilon)
{
m_MaxZoomFactorTextureQuality = Mathf.Clamp(value, MinZoomFactor, MaxZoomFactor);
m_UpdateChangeDelay = 1.0f;
}
}
}
public float MinZoomFactor
{
get { return m_MinZoomFactor; }
set { m_MinZoomFactor = value; }
}
public PageFittingType PageFitting
{
get { return m_PageFitting; }
set { m_PageFitting = value; }
}
public string Password
{
get { return m_Password; }
set { m_Password = value; }
}
///
/// Intended to be used along side the Asset file source (FileSource.Asset)
///
public PDFAsset PDFAsset
{
get { return m_PDFAsset; }
set { m_PDFAsset = value; }
}
public bool RenderAnnotations
{
get { return m_RenderSettings.renderAnnotations; }
set
{
if (m_RenderSettings.renderAnnotations != value)
{
m_RenderSettings.renderAnnotations = value;
m_UpdateChangeDelay = 0.1f;
}
}
}
public bool RenderGrayscale
{
get { return m_RenderSettings.grayscale; }
set
{
if (m_RenderSettings.grayscale != value)
{
m_RenderSettings.grayscale = value;
m_UpdateChangeDelay = 0.1f;
}
}
}
public float ScrollSensitivity
{
get { return m_ScrollSensitivity; }
set { m_ScrollSensitivity = value; }
}
public Color SearchResultColor
{
get { return m_SearchResultColor; }
set
{
if (m_SearchResultColor != value)
{
m_SearchResultColor = value;
m_UpdateChangeDelay = 0.25f;
}
}
}
public Vector2 SearchResultPadding
{
get { return m_SearchResultPadding; }
set
{
if (m_SearchResultPadding != value)
{
m_SearchResultPadding = value;
m_UpdateChangeDelay = 0.25f;
}
}
}
public bool ShowBookmarksViewer
{
get { return m_ShowBookmarksViewer; }
set
{
m_ShowBookmarksViewer = value;
bool visible = m_ShowBookmarksViewer;
if (m_IsLoaded)
{
#if !UNITY_WEBGL
if (m_Document.GetRootBookmark().ChildCount == 0)
#endif
visible = false;
}
if (m_Internal.m_LeftPanel != null)
{
m_Internal.m_LeftPanel.m_Bookmarks.gameObject.SetActive(visible);
m_Internal.m_LeftPanel.m_BookmarksTab.gameObject.SetActive(visible);
m_Internal.m_LeftPanel.SetActive(m_ShowThumbnailsViewer || visible);
if (!visible && m_ShowThumbnailsViewer)
m_Internal.m_LeftPanel.OnThumbnailsTabClicked();
else if (visible && !m_ShowThumbnailsViewer)
m_Internal.m_LeftPanel.OnBookmarksTabClicked();
else
m_Internal.m_LeftPanel.OnBookmarksTabClicked();
}
}
}
public bool ShowHorizontalScrollBar
{
get { return m_ShowHorizontalScrollBar; }
set
{
if (m_ShowHorizontalScrollBar != value)
{
m_ShowHorizontalScrollBar = value;
UpdateScrollBarVisibility();
}
}
}
public bool ShowThumbnailsViewer
{
get { return m_ShowThumbnailsViewer; }
set
{
if (m_ShowThumbnailsViewer != value)
{
m_ShowThumbnailsViewer = value;
if (m_Internal.m_LeftPanel != null)
{
m_Internal.m_LeftPanel.m_ThumbnailsViewer.gameObject.SetActive(m_ShowThumbnailsViewer);
m_Internal.m_LeftPanel.m_ThumbnailsTab.gameObject.SetActive(m_ShowThumbnailsViewer);
m_Internal.m_LeftPanel.SetActive(m_ShowThumbnailsViewer || m_ShowBookmarksViewer);
if (!m_ShowBookmarksViewer && m_ShowThumbnailsViewer)
m_Internal.m_LeftPanel.OnThumbnailsTabClicked();
else if (m_ShowBookmarksViewer && !m_ShowThumbnailsViewer)
m_Internal.m_LeftPanel.OnBookmarksTabClicked();
else
m_Internal.m_LeftPanel.OnBookmarksTabClicked();
}
}
}
}
public bool ShowTopBar
{
get { return m_ShowTopBar; }
set
{
if (m_ShowTopBar != value)
{
m_ShowTopBar = value;
if (!m_ShowTopBar)
{
m_Internal.m_TopPanel.gameObject.SetActive(false);
m_Internal.m_TopPanel.sizeDelta = new Vector2(0.0f, 0.0f);
m_Internal.m_Viewport.offsetMax = new Vector2(m_Internal.m_Viewport.offsetMax.x, 0.0f);
m_Internal.m_VerticalScrollBar.offsetMax =
new Vector2(m_Internal.m_VerticalScrollBar.offsetMax.x, 0.0f);
if (m_Internal.m_LeftPanel != null)
{
(m_Internal.m_LeftPanel.transform as RectTransform).sizeDelta =
new Vector2((m_Internal.m_LeftPanel.transform as RectTransform).sizeDelta.x, 0.0f);
}
}
else
{
m_Internal.m_TopPanel.gameObject.SetActive(true);
m_Internal.m_TopPanel.sizeDelta = new Vector2(0.0f, 60.0f);
m_Internal.m_Viewport.offsetMax = new Vector2(m_Internal.m_Viewport.offsetMax.x, -60.0f);
m_Internal.m_VerticalScrollBar.offsetMax =
new Vector2(m_Internal.m_VerticalScrollBar.offsetMax.x, -59.0f);
if (m_Internal.m_LeftPanel != null)
{
(m_Internal.m_LeftPanel.transform as RectTransform).sizeDelta =
new Vector2((m_Internal.m_LeftPanel.transform as RectTransform).sizeDelta.x, -59.0f);
}
}
}
}
}
public bool ShowVerticalScrollBar
{
get { return m_ShowVerticalScrollBar; }
set
{
if (m_ShowVerticalScrollBar != value)
{
m_ShowVerticalScrollBar = value;
UpdateScrollBarVisibility();
}
}
}
public bool UnloadOnDisable
{
get { return m_UnloadOnDisable; }
set { m_UnloadOnDisable = value; }
}
public float VerticalMarginBetweenPages
{
get { return m_VerticalMarginBetweenPages; }
set
{
if (m_VerticalMarginBetweenPages != value)
{
if (value < 0.0f)
{
m_VerticalMarginBetweenPages = 0.0f;
}
else
{
m_VerticalMarginBetweenPages = value;
}
ComputePageOffsets();
UpdatePagesPlacement();
m_Internal.m_PageContainer.sizeDelta = GetDocumentSize();
EnsureValidPageContainerPosition();
}
}
}
public float ZoomFactor
{
get { return m_ZoomToGo; }
set
{
if (Math.Abs(m_ZoomToGo - Mathf.Clamp(value, MinZoomFactor, MaxZoomFactor)) > float.Epsilon)
{
m_ZoomToGo = Mathf.Clamp(value, MinZoomFactor, MaxZoomFactor);
m_ZoomPosition = new Vector2(0.0f, m_ViewportSize.y*0.5f);
NotifyZoomChanged(m_PreviousZoomToGo, m_ZoomToGo);
m_PageFitting = PageFittingType.Zoom;
}
}
}
public float ZoomStep
{
get { return m_ZoomStep; }
set { m_ZoomStep = value; }
}
public bool ParagraphZoomingEnable
{
get
{
return m_ParagraphZoomingEnable;
}
set
{
m_ParagraphZoomingEnable = value;
}
}
public float ParagraphZoomFactor
{
get { return m_ParagraphZoomFactor; }
set { m_ParagraphZoomFactor = value; }
}
public float ParagraphDetectionThreshold
{
get { return m_ParagraphDetectionThreshold; }
set { m_ParagraphDetectionThreshold = value; }
}
public Texture2D PageTileTexture
{
get
{
return m_PageTileTexture;
}
set
{
m_PageTileTexture = value;
}
}
public Color PageColor
{
get
{
return m_PageColor;
}
set
{
m_PageColor = value;
}
}
public void AdjustZoomToPageFitting(PageFittingType pageFitting, Vector2 referencePageSize)
{
if (m_ViewportSize == Vector2.zero)
{
m_ViewportSize = ComputeRectTransformFinalSize(m_Internal.m_Viewport.transform as RectTransform);
if (m_Canvas != null)
{
m_ViewportSize.x /= m_Canvas.scaleFactor;
m_ViewportSize.y /= m_Canvas.scaleFactor;
}
}
switch (pageFitting)
{
case PageFittingType.ViewerWidth:
{
float firstPageWidth = referencePageSize.x;
float viewportWidth = m_ViewportSize.x;
m_ZoomToGo = viewportWidth/firstPageWidth;
break;
}
case PageFittingType.ViewerHeight:
{
float firstPageHeight = referencePageSize.y;
float viewportHeight = m_ViewportSize.y;
m_ZoomToGo = viewportHeight/firstPageHeight;
break;
}
case PageFittingType.WholePage:
{
float firstPageWidth = referencePageSize.x;
float firstPageHeight = referencePageSize.y + 2.0f*m_VerticalMarginBetweenPages;
float viewportWidth = m_ViewportSize.x;
float viewportHeight = m_ViewportSize.y;
m_ZoomToGo = Mathf.Min(viewportWidth/firstPageWidth, viewportHeight/firstPageHeight);
break;
}
case PageFittingType.Zoom:
{
break;
}
}
}
public void CloseDocument()
{
#if !UNITY_WEBPLAYER
if (m_IsLoaded)
{
CleanUp();
}
#endif
}
public string GetFileLocation()
{
switch (m_FileSource)
{
case FileSourceType.FilePath:
return m_FilePath;
case FileSourceType.Resources:
string folder = m_Folder + "/";
if (string.IsNullOrEmpty(m_Folder))
{
folder = "";
}
return (folder + m_FileName).Replace("//", "/").Replace(@"\\", @"/").Replace(@"\", @"/");
case FileSourceType.StreamingAssets:
folder = m_Folder + "/";
if (string.IsNullOrEmpty(m_Folder))
{
folder = "";
}
string location = ("/" + folder + m_FileName).Replace("//", "/")
.Replace(@"\\", @"/")
.Replace(@"\", @"/");
return Application.streamingAssetsPath + location;
case FileSourceType.Web:
return m_FileURL;
default:
return "";
}
}
public void GoToNextPage()
{
if (m_Document == null || !m_Document.IsValid)
{
return;
}
int mostVisiblePage = GetMostVisiblePageIndex();
if (mostVisiblePage + 1 < m_PageCount)
{
GoToPage(mostVisiblePage + 1);
}
else
{
m_Internal.m_PageContainer.anchoredPosition = new Vector2(
m_Internal.m_PageContainer.anchoredPosition.x,
m_Internal.m_PageContainer.sizeDelta.y - m_ViewportSize.y);
}
}
public void GoToNextSearchResult()
{
if (m_SearchResults != null && m_SearchResults.Length > 0)
{
++m_CurrentSearchResultIndex;
++m_CurrentSearchResultIndexWithinCurrentPage;
int oldPageIndex = m_CurrentSearchResult.PageIndex;
if (m_CurrentSearchResultIndexWithinCurrentPage >= m_SearchResults[m_CurrentSearchResult.PageIndex].Count)
{
int nextPage = m_CurrentSearchResult.PageIndex + 1;
while (nextPage < m_PageCount - 1 && m_SearchResults[nextPage].Count == 0)
{
++nextPage;
}
if (nextPage <= m_PageCount - 1 && m_SearchResults[nextPage].Count > 0)
{
m_CurrentSearchResultIndexWithinCurrentPage = 0;
m_CurrentSearchResult = m_SearchResults[nextPage][0];
if (oldPageIndex != nextPage)
{
GoToPage(nextPage);
}
}
else
{
--m_CurrentSearchResultIndexWithinCurrentPage;
--m_CurrentSearchResultIndex;
}
}
else
{
m_CurrentSearchResult =
m_SearchResults[m_CurrentSearchResult.PageIndex][m_CurrentSearchResultIndexWithinCurrentPage];
if (!m_CurrentPageRange.ContainsPage(m_CurrentSearchResult.PageIndex))
GoToPage(m_CurrentSearchResult.PageIndex);
}
}
}
public void GoToPage(int pageIndex)
{
if (pageIndex < 0)
{
pageIndex = 0;
}
else if (pageIndex > m_PageCount - 1)
{
pageIndex = m_PageCount - 1;
}
m_Internal.m_PageInputField.text = (pageIndex + 1).ToString();
m_Internal.m_PageContainer.anchoredPosition = new Vector2(m_Internal.m_PageContainer.anchoredPosition.x,
m_PageOffsets[pageIndex] - m_PageSizes[pageIndex].y*0.5f);
m_Internal.m_PageContainer.anchoredPosition -= m_VerticalMarginBetweenPages*Vector2.up;
SetPageCountLabel(pageIndex, m_PageCount);
EnsureValidPageContainerPosition();
}
public void GoToPreviousPage()
{
if (m_Document == null || !m_Document.IsValid)
{
return;
}
int mostVisiblePage = GetMostVisiblePageIndex();
if (mostVisiblePage - 1 >= 0)
{
GoToPage(mostVisiblePage - 1);
}
else
{
m_Internal.m_PageContainer.anchoredPosition = Vector2.zero;
}
}
public void GoToPreviousSearchResult()
{
if (m_SearchResults != null && m_SearchResults.Length > 0 && m_CurrentSearchResultIndex > 0)
{
--m_CurrentSearchResultIndex;
--m_CurrentSearchResultIndexWithinCurrentPage;
int oldPageIndex = m_CurrentSearchResult.PageIndex;
if (m_CurrentSearchResultIndexWithinCurrentPage < 0)
{
int prevPage = m_CurrentSearchResult.PageIndex - 1;
while (prevPage >= 0 && m_SearchResults[prevPage].Count == 0)
{
--prevPage;
}
if (prevPage >= 0 && m_SearchResults[prevPage].Count > 0)
{
m_CurrentSearchResultIndexWithinCurrentPage = m_SearchResults[prevPage].Count - 1;
m_CurrentSearchResult = m_SearchResults[prevPage][m_SearchResults[prevPage].Count - 1];
if (oldPageIndex != prevPage)
{
GoToPage(prevPage);
}
}
else
{
++m_CurrentSearchResultIndexWithinCurrentPage;
++m_CurrentSearchResultIndex;
}
}
else
{
m_CurrentSearchResult =
m_SearchResults[m_CurrentSearchResult.PageIndex][m_CurrentSearchResultIndexWithinCurrentPage];
if (!m_CurrentPageRange.ContainsPage(m_CurrentSearchResult.PageIndex))
GoToPage(m_CurrentSearchResult.PageIndex);
}
}
}
public void LoadDocument(int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
if (m_IsLoaded)
CleanUp();
CommonLoad();
#endif
}
public void LoadDocument(PDFDocument document, string password, int pageIndex)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.DocumentObject;
m_SuppliedDocument = document;
m_Password = password;
//if (m_SuppliedDocument != null)
CommonLoad();
#endif
}
public void LoadDocument(PDFDocument document, int pageIndex = 0)
{
LoadDocument(document, "", pageIndex);
}
public void LoadDocumentFromAsset(PDFAsset pdfAsset, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
{
CleanUp();
}
m_FileSource = FileSourceType.Asset;
m_PDFAsset = pdfAsset;
m_Password = pdfAsset.Password;
CommonLoad(pdfAsset.m_FileContent);
#endif
}
public void LoadDocumentFromAsset(PDFAsset pdfAsset, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
{
CleanUp();
}
m_FileSource = FileSourceType.Asset;
m_PDFAsset = pdfAsset;
m_Password = password;
CommonLoad(pdfAsset.m_FileContent);
#endif
}
public void LoadDocumentFromResources(string folder, string fileName, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.Resources;
m_Folder = folder;
m_FileName = fileName;
m_FilePath = GetFileLocation();
m_Password = password;
CommonLoad();
#endif
}
public void LoadDocumentFromStreamingAssets(string folder, string fileName, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.StreamingAssets;
m_Folder = folder;
m_FileName = fileName;
m_FilePath = GetFileLocation();
m_Password = password;
CommonLoad();
#endif
}
public void LoadDocumentFromWeb(string url, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.Web;
m_FileURL = url;
m_FilePath = GetFileLocation();
m_Password = password;
CommonLoad();
#endif
}
public void LoadDocumentWithBuffer(byte[] buffer, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.Bytes;
m_Password = password;
CommonLoad(buffer);
#endif
}
public void LoadDocumentWithFile(string filePath, string password, int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
m_LoadAtPageIndex = pageIndex;
if (m_IsLoaded)
CleanUp();
m_FileSource = FileSourceType.FilePath;
m_FilePath = filePath;
m_Password = password;
m_FilePath = GetFileLocation();
m_Password = password;
CommonLoad();
#endif
}
public void OnDownloadCancelButtonClicked()
{
#if !UNITY_WEBGL || UNITY_EDITOR
StopCoroutine(DownloadFileFromWWW());
m_Internal.m_DownloadDialog.gameObject.SetActive(false);
m_WWW = null;
NotifyDownloadCancelled();
CleanUp();
#endif
}
public void OnPageEditEnd()
{
if (m_Document == null || !m_Document.IsValid)
{
return;
}
if (string.IsNullOrEmpty(m_Internal.m_PageInputField.text))
{
return;
}
int pageIndex = int.Parse(m_Internal.m_PageInputField.text) - 1;
GoToPage(pageIndex);
}
public void OnPasswordDialogCancelButtonClicked()
{
m_InvalidPasswordMessageVisisble = false;
m_Internal.m_InvalidPasswordImage.gameObject.SetActive(false);
m_Internal.m_InvalidPasswordImage.GetComponent().alpha = 1.0f;
NotifyPasswordCancelled();
CleanUp();
}
public void OnPasswordDialogOkButtonClicked()
{
#if !UNITY_WEBGL || UNITY_EDITOR
m_Password = m_Internal.m_PasswordInputField.text;
if (TryLoadDocumentWithBuffer(m_PendingDocumentBuffer, m_Password))
{
m_Internal.m_PasswordDialog.gameObject.SetActive(false);
m_InvalidPasswordMessageVisisble = false;
m_Internal.m_InvalidPasswordImage.gameObject.SetActive(false);
m_Internal.m_InvalidPasswordImage.GetComponent().alpha = 1.0f;
m_Internal.m_PasswordInputField.text = "";
}
else
{
m_InvalidPasswordMessageVisisble = true;
m_Internal.m_InvalidPasswordImage.gameObject.SetActive(true);
m_Internal.m_InvalidPasswordImage.GetComponent().alpha = 1.0f;
m_InvalidPasswordMessageDelay = m_InvalidPasswordMessageDelayBeforeFade;
m_Internal.m_PasswordInputField.Select();
}
#endif
}
public void ReloadDocument(int pageIndex = 0)
{
#if !UNITY_WEBPLAYER
LoadDocument(pageIndex);
#endif
}
#if (!UNITY_WINRT && !UNITY_WEBGL) || UNITY_EDITOR
public bool SaveDocumentAsFile(string path)
{
if (m_Document == null || m_Document.DocumentBuffer == null)
{
Debug.LogError("Error while saving document: there is no document loaded.");
return false;
}
if (!new Uri(path).IsWellFormedOriginalString())
{
Debug.LogError("Error while saving document: the path is not well formed => " + path);
return false;
}
try
{
FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write);
stream.Write(m_Document.DocumentBuffer, 0, m_Document.DocumentBuffer.Length);
stream.Close();
return true;
}
catch (Exception ex)
{
Debug.LogError("Exception while saving document: " + ex);
}
return false;
}
#endif
public void SetSearchResults(IList[] searchResults)
{
m_SearchResults = searchResults;
if (m_SearchResults != null && m_SearchResults.Length > 0)
{
m_CurrentSearchResultIndex = 0;
m_CurrentSearchResultIndexWithinCurrentPage = 0;
for (int i = 0; i < m_PageCount; ++i)
{
if (m_SearchResults[i] != null && m_SearchResults[i].Count > 0)
{
m_CurrentSearchResult = m_SearchResults[i][0];
break;
}
}
}
else
{
m_CurrentSearchResult = new PDFSearchResult(-1, 0, 0);
m_CurrentSearchResultIndex = 0;
}
AdjustCurrentSearchResultDisplayed();
m_UpdateChangeDelay = 0.25f;
}
public void UnloadDocument()
{
#if !UNITY_WEBPLAYER
if (m_IsLoaded)
{
CleanUp();
}
#endif
}
public void ZoomIn()
{
ZoomCommon(new Vector2(0.0f, m_ViewportSize.y*0.5f), true);
}
public void ZoomOut()
{
ZoomCommon(new Vector2(0.0f, m_ViewportSize.y*0.5f), false);
}
private void AdjustCurrentSearchResultDisplayed()
{
if (m_SearchResults != null && m_SearchResults.Length > 0)
{
if (!m_CurrentPageRange.ContainsPage(m_CurrentSearchResult.PageIndex))
{
int minPage = m_CurrentPageRange.m_From;
int maxPage = m_CurrentPageRange.m_To;
bool minFound = false;
bool maxFound = false;
for (int i = minPage; i >= 0; --i)
{
if (m_SearchResults[i] != null && m_SearchResults[i].Count > 0)
{
minFound = true;
minPage = i;
break;
}
}
for (int i = maxPage; i < m_PageCount; ++i)
{
if (m_SearchResults[i] != null && m_SearchResults[i].Count > 0)
{
maxFound = true;
maxPage = i;
break;
}
}
int disMinPage = Math.Abs(m_CurrentPageRange.m_From - minPage);
int disMaxPage = Math.Abs(maxPage - m_CurrentPageRange.m_To);
int nearestPage = -1;
if (disMinPage <= disMaxPage)
{
if (minFound)
{
nearestPage = minPage;
}
else if (maxFound)
{
nearestPage = maxPage;
}
}
else
{
if (maxFound)
{
nearestPage = maxPage;
}
else if (minFound)
{
nearestPage = minPage;
}
}
int count = 0;
for (int i = 0; i < nearestPage; ++i)
{
count += m_SearchResults[i].Count;
}
if (minFound || maxFound)
{
if (m_CurrentPageRange.ContainsPage(nearestPage)
|| nearestPage >= m_CurrentPageRange.m_To)
{
m_CurrentSearchResult = m_SearchResults[nearestPage][0];
m_CurrentSearchResultIndex = count;
m_CurrentSearchResultIndexWithinCurrentPage = 0;
}
else
{
m_CurrentSearchResult = m_SearchResults[nearestPage][m_SearchResults[nearestPage].Count - 1];
m_CurrentSearchResultIndex = count + m_SearchResults[nearestPage].Count - 1;
m_CurrentSearchResultIndexWithinCurrentPage = m_SearchResults[nearestPage].Count - 1;
}
}
}
}
}
private void CleanUp()
{
if (m_Document != null)
NotifyDocumentUnloaded(m_Document);
m_Document = null;
if (m_PageTextureHolders != null)
{
foreach (PDFPageTextureHolder holder in m_PageTextureHolders)
{
if (holder.Texture != null)
{
Texture2D tex = holder.Texture;
holder.Texture = null;
Texture2D.Destroy(tex);
Resources.UnloadUnusedAssets();
}
if (holder.m_Page.name != "Page")
{
Destroy(holder.m_Page);
}
}
}
m_IsLoaded = false;
m_Internal.m_PageContainer.anchoredPosition = Vector2.zero;
m_Internal.m_PageContainer.sizeDelta = Vector2.zero;
UpdateScrollBarVisibility();
EnsureValidPageContainerPosition();
m_ZoomToGo = m_StartZoom;
m_PageSizes = null;
m_NormalPageSizes = null;
m_PageOffsets = null;
m_PageCount = 0;
m_PreviousZoom = 0.0f;
m_PreviousZoomToGo = 0.0f;
m_PreviousViewportSize = Vector2.zero;
m_PageTextureHolders = null;
m_CurrentPageRange = null;
m_PreviousMostVisiblePage = -1;
m_OverlayVisible = false;
m_InvalidPasswordMessageVisisble = false;
m_Internal.m_Overlay.gameObject.SetActive(false);
m_Internal.m_PasswordDialog.gameObject.SetActive(false);
m_Internal.m_DownloadDialog.gameObject.SetActive(false);
m_Internal.m_PageCountLabel.text = "";
m_Internal.m_PageZoomLabel.text = "";
m_Internal.m_PageInputField.text = "";
GC.Collect();
GC.WaitForPendingFinalizers();
}
private void CommonLoad(byte[] specifiedBuffer = null)
{
#if !UNITY_WEBPLAYER
UpdateScrollBarVisibility();
EnsureValidPageContainerPosition();
m_IsLoaded = false;
if (m_FileSource == FileSourceType.None)
{
m_OverlayVisible = true;
m_Internal.m_Overlay.gameObject.SetActive(true);
m_Internal.m_Overlay.GetComponent().alpha = 1.0f;
return;
}
#if UNITY_WEBGL && !UNITY_EDITOR
StartCoroutine(LoadDocument_WebGL(specifiedBuffer));
return;
#else
byte[] buffer = specifiedBuffer;
if (m_FileSource != FileSourceType.DocumentObject)
m_SuppliedDocument = null;
if (m_FileSource == FileSourceType.DocumentObject)
{
TryLoadWithSpecifiedDocument(m_SuppliedDocument);
}
else if (m_FileSource == FileSourceType.FilePath)
{
#if !((UNITY_4_6 || UNITY_4_7) && UNITY_WINRT)
buffer = File.ReadAllBytes(GetFileLocation());
OnLoadingBufferFinished(buffer);
#endif
}
else if (m_FileSource == FileSourceType.Resources)
{
buffer = LoadAssetBytesFromResources(GetFileLocation());
OnLoadingBufferFinished(buffer);
}
else if (m_FileSource == FileSourceType.StreamingAssets)
{
#if (UNITY_ANDROID || UNITY_WINRT) && !UNITY_EDITOR
StartCoroutine(DownloadFileFromWWW());
#else
string location = GetFileLocation();
if (File.Exists(location))
buffer = File.ReadAllBytes(location);
OnLoadingBufferFinished(buffer);
#endif
}
else if (m_FileSource == FileSourceType.Web)
{
StartCoroutine(DownloadFileFromWWW());
}
else if (m_FileSource == FileSourceType.Bytes)
{
#if !((UNITY_4_6 || UNITY_4_7) && UNITY_WINRT)
if (buffer != null)
{
OnLoadingBufferFinished(buffer);
}
else if (BytesSupplierComponent != null)
{
#if UNITY_WINRT
MethodInfo methodInfo = BytesSupplierComponent.GetType().GetMethod(BytesSupplierFunctionName, BindingFlags.Public);
#else
MethodInfo methodInfo = BytesSupplierComponent.GetType().GetMethod(BytesSupplierFunctionName);
#endif
if (methodInfo != null)
{
buffer = (byte[]) methodInfo.Invoke(BytesSupplierComponent, null);
}
if (buffer != null)
{
OnLoadingBufferFinished(buffer);
}
}
#endif
if (buffer == null)
{
NotifyDocumentLoadFailed();
}
}
else if (m_FileSource == FileSourceType.Asset)
{
if (m_PDFAsset != null && m_PDFAsset.m_FileContent != null && m_PDFAsset.m_FileContent.Length > 0)
{
OnLoadingBufferFinished(m_PDFAsset.m_FileContent);
}
else
{
NotifyDocumentLoadFailed();
}
}
#endif
#endif
}
private void ComputePageOffsets()
{
float totalOffset = m_VerticalMarginBetweenPages;
m_PageOffsets = new float[m_PageCount];
for (int i = 0; i < m_PageCount; ++i)
{
m_PageOffsets[i] = totalOffset + m_PageSizes[i].y*0.5f;
totalOffset += m_VerticalMarginBetweenPages + m_PageSizes[i].y;
}
}
private void ComputePageSizes()
{
m_PageCount = m_Document.GetPageCount();
m_PageSizes = new Vector2[m_PageCount];
for (int i = 0; i < m_PageCount; ++i)
{
#if UNITY_WEBGL && !UNITY_EDITOR
m_PageSizes[i] = m_NormalPageSizes[i] * m_ZoomFactor;
#else
float w = (m_Document.GetPageWidth(i) * m_ZoomFactor);
float h = (m_Document.GetPageHeight(i) * m_ZoomFactor);
m_PageSizes[i] = new Vector2(w, h);
#endif
}
}
private Vector2 ComputeRectTransformFinalSize(RectTransform rectTransform)
{
if (rectTransform == null || rectTransform.parent == null)
{
return new Vector2(Screen.width, Screen.height);
}
Vector2 offsetDelta = rectTransform.anchorMax - rectTransform.anchorMin;
Vector2 parentSize = ComputeRectTransformFinalSize(rectTransform.parent as RectTransform);
parentSize.Scale(offsetDelta);
return rectTransform.sizeDelta + parentSize;
}
#if UNITY_WEBGL && !UNITY_EDITOR
IEnumerator LoadDocument_WebGL(byte[] specifiedBuffer = null)
{
PDFJS_Promise documentPromise = null;
byte[] buffer = specifiedBuffer;
switch (m_FileSource)
{
case FileSourceType.Asset:
if (m_PDFAsset.m_FileContent == null || m_PDFAsset.m_FileContent.Length == 0)
yield break;
documentPromise = PDFDocument.LoadDocumentFromBytesAsync(m_PDFAsset.m_FileContent);
break;
case FileSourceType.Bytes:
if (buffer != null)
{
documentPromise = PDFDocument.LoadDocumentFromBytesAsync(buffer);
}
else if (BytesSupplierComponent != null)
{
MethodInfo methodInfo = BytesSupplierComponent.GetType().GetMethod(BytesSupplierFunctionName);
if (methodInfo != null)
buffer = (byte[])methodInfo.Invoke(BytesSupplierComponent, null);
if (buffer != null)
documentPromise = PDFDocument.LoadDocumentFromBytesAsync(buffer);
}
if (buffer == null)
yield break;
break;
case FileSourceType.Resources:
buffer = LoadAssetBytesFromResources(GetFileLocation());
if (buffer != null)
documentPromise = PDFDocument.LoadDocumentFromBytesAsync(buffer);
else
yield break;
break;
case FileSourceType.Web:
case FileSourceType.FilePath:
case FileSourceType.StreamingAssets:
documentPromise = PDFDocument.LoadDocumentFromUrlAsync(GetFileLocation());
break;
}
while (!documentPromise.HasFinished)
yield return null;
if (documentPromise.HasSucceeded)
{
m_Document = documentPromise.Result;
m_NormalPageSizes = new Vector2[m_Document.GetPageCount()];
for (int i = 0; i < m_NormalPageSizes.Length; ++i)
{
PDFJS_Promise pagePromise = m_Document.GetPageAsync(i);
while (!pagePromise.HasFinished)
yield return null;
if (pagePromise.HasSucceeded)
{
PDFPage page = pagePromise.Result;
m_NormalPageSizes[i] = page.GetPageSize(1.0f);
}
else
{
NotifyDocumentLoadFailed();
yield break;
}
}
TryLoadWithSpecifiedDocument(m_Document);
}
else
{
NotifyDocumentLoadFailed();
yield break;
}
}
#endif
#if !UNITY_WEBGL || UNITY_EDITOR
IEnumerator DownloadFileFromWWW()
{
m_OverlayVisible = true;
m_Internal.m_Overlay.gameObject.SetActive(true);
m_Internal.m_Overlay.GetComponent().alpha = 0.0f;
m_Internal.m_DownloadDialog.gameObject.SetActive(true);
if (m_FileSource == FileSourceType.Web)
{
m_Internal.m_DownloadSourceLabel.text = GetFileLocation();
}
else
{
m_Internal.m_DownloadSourceLabel.text = "";
}
m_Internal.m_ProgressRect.sizeDelta = new Vector2(0.0f, m_Internal.m_ProgressRect.sizeDelta.y);
m_Internal.m_ProgressLabel.text = "0%";
m_WWW = new WWW(GetFileLocation());
yield return m_WWW;
if (m_WWW != null && m_WWW.error == null && m_WWW.isDone)
{
SetProgress(1.0f);
OnLoadingBufferFinished(m_WWW.bytes);
}
else if (m_WWW == null || m_WWW.error != null)
{
NotifyDocumentLoadFailed();
}
m_Internal.m_DownloadDialog.gameObject.SetActive(false);
}
#endif
private void EnsureValidPageContainerPosition()
{
if (GetDocumentSize().x <= m_ViewportSize.x)
{
m_Internal.m_PageContainer.anchoredPosition = new Vector2(0.0f,
m_Internal.m_PageContainer.anchoredPosition.y);
}
if (m_Internal.m_PageContainer.anchoredPosition.y >
m_Internal.m_PageContainer.sizeDelta.y - m_ViewportSize.y)
{
m_Internal.m_PageContainer.anchoredPosition = new Vector2(
m_Internal.m_PageContainer.anchoredPosition.x,
m_Internal.m_PageContainer.sizeDelta.y - m_ViewportSize.y);
}
if (m_Internal.m_PageContainer.anchoredPosition.y < 0.0f)
{
m_Internal.m_PageContainer.anchoredPosition = new Vector2(
m_Internal.m_PageContainer.anchoredPosition.x, 0.0f);
}
}
private Vector2 GetDocumentSize()
{
Vector2 size = new Vector2(0.0f, 0.0f);
if (m_PageSizes == null)
{
return size;
}
foreach (Vector2 s in m_PageSizes)
{
if (s.x > size.x)
{
size.x = s.x;
}
}
size.y = m_PageOffsets[m_PageCount - 1] + m_PageSizes[m_PageCount - 1].y * 0.5f;
size.x += 0.0f * m_VerticalMarginBetweenPages;
size.y += 1.0f * m_VerticalMarginBetweenPages;
return size;
}
private int GetMostVisiblePageIndex()
{
int mostVisibleIndex = -1;
float mostVisibleArea = 0.0f;
for (int i = m_CurrentPageRange.m_From; i < m_CurrentPageRange.m_To; ++i)
{
RectTransform page = m_Internal.m_PageContainer.GetChild(i) as RectTransform;
float area = PDFInternalUtils.CalculateRectTransformIntersectArea(page, m_Internal.m_Viewport);
if (area > page.sizeDelta.x*page.sizeDelta.y*0.4f)
{
return i;
}
if (area > mostVisibleArea)
{
mostVisibleIndex = i;
mostVisibleArea = area;
}
}
return mostVisibleIndex;
}
private PDFPageRange GetVisiblePageRange()
{
PDFPageRange pageRange = new PDFPageRange();
for (int i = 0; i < m_PageCount; ++i)
{
if (
PDFInternalUtils.CalculateRectTransformIntersectArea(
m_Internal.m_PageContainer.GetChild(i) as RectTransform, m_Internal.m_Viewport) > 0.0f)
{
if (pageRange.m_From == -1)
{
pageRange.m_From = i;
}
else
{
pageRange.m_To = i + 1;
}
}
else if (pageRange.m_From != -1)
{
break;
}
}
if (pageRange.m_From != -1 && pageRange.m_To == -1)
{
pageRange.m_To = pageRange.m_From + 1;
}
return pageRange;
}
private void InstantiatePageTextureHolders()
{
if (m_PageTextureHolders == null)
{
m_PageTextureHolders = new PDFPageTextureHolder[m_PageCount];
for (int i = 0; i < m_PageCount; ++i)
{
m_PageTextureHolders[i] = new PDFPageTextureHolder();
GameObject page = null;
if (i == 0)
page = m_Internal.m_PageSample.gameObject;
else
page = (GameObject)Instantiate(m_Internal.m_PageSample.gameObject);
page.transform.SetParent(m_Internal.m_PageSample.transform.parent);
page.transform.localScale = Vector3.one;
page.transform.localRotation = Quaternion.identity;
m_PageTextureHolders[i].m_PageIndex = i;
m_PageTextureHolders[i].m_Page = page;
m_PageTextureHolders[i].m_PDFViewer = this;
m_PageTextureHolders[i].Texture = null;
}
}
}
void Update()
{
#if !UNITY_WEBGL || UNITY_EDITOR
if (m_WWW != null && !m_WWW.isDone)
{
SetProgress(m_WWW.progress);
}
#endif
if (m_DelayedOnEnable)
{
m_DelayedOnEnable = false;
if (m_LoadOnEnable && !m_IsLoaded)
{
LoadDocument();
}
else
{
m_OverlayVisible = true;
m_Internal.m_Overlay.gameObject.SetActive(true);
m_Internal.m_Overlay.GetComponent().alpha = 1.0f;
}
}
if (Input.touchCount >= 2)
{
if (m_PreviousTouchCount < 2)
{
m_PinchZoomStartZoomFactor = ZoomFactor;
ScrollRect scrollRect = m_Internal.m_Viewport.GetComponent();
scrollRect.inertia = false;
scrollRect.horizontal = false;
scrollRect.vertical = false;
StopCoroutine(DelayedUnlockScrollRect());
}
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
if (m_PreviousTouchCount < 2)
m_PinchZoomStartDeltaMag = touchDeltaMag;
else
ZoomFactor = m_PinchZoomStartZoomFactor / (m_PinchZoomStartDeltaMag / touchDeltaMag);
}
else if (m_PreviousTouchCount >= 2)
StartCoroutine(DelayedUnlockScrollRect());
m_PreviousTouchCount = Input.touchCount;
}
private int m_PreviousTouchCount;
private float m_PinchZoomStartZoomFactor;
private float m_PinchZoomStartDeltaMag;
IEnumerator DelayedUnlockScrollRect()
{
while (Input.touchCount != 0)
yield return null;
ScrollRect scrollRect = m_Internal.m_Viewport.GetComponent();
scrollRect.inertia = true;
scrollRect.horizontal = true;
scrollRect.vertical = true;
}
private byte[] LoadAssetBytesFromResources(string path)
{
string fixedPath = path.Replace(".bytes", "");
if (fixedPath.StartsWith("./"))
{
fixedPath = fixedPath.Substring(2);
}
var pdfAsset = Resources.Load(fixedPath, typeof (TextAsset)) as TextAsset;
if (pdfAsset != null && pdfAsset.bytes != null && pdfAsset.bytes.Length > 0)
{
return pdfAsset.bytes;
}
return null;
}
private void NotifyCurrentPageChanged(int oldPageIndex, int newPageIndex)
{
if (OnCurrentPageChanged != null)
{
OnCurrentPageChanged(this, oldPageIndex, newPageIndex);
}
m_ThumbnailsViewer.OnCurrentPageChanged(newPageIndex);
}
private void NotifyDisabled()
{
if (OnDisabled != null)
{
OnDisabled(this);
}
}
private void NotifyDocumentLoaded(PDFDocument document)
{
if (OnDocumentLoaded != null)
{
OnDocumentLoaded(this, document);
}
m_ThumbnailsViewer.OnDocumentLoaded(document);
m_BookmarksViewer.OnDocumentLoaded(document);
}
private void NotifyDocumentLoadFailed()
{
if (OnDocumentLoadFailed != null)
{
OnDocumentLoadFailed(this);
}
}
private void NotifyDocumentUnloaded(PDFDocument document)
{
if (OnDocumentUnloaded != null)
{
OnDocumentUnloaded(this, document);
}
m_ThumbnailsViewer.OnDocumentUnloaded();
m_BookmarksViewer.OnDocumentUnloaded();
}
private void NotifyDownloadCancelled()
{
if (OnDownloadCancelled != null)
{
OnDownloadCancelled(this);
}
}
private void NotifyPasswordCancelled()
{
if (OnPasswordCancelled != null)
{
OnPasswordCancelled(this);
}
}
private void NotifyZoomChanged(float oldZoom, float newZoom)
{
if (OnZoomChanged != null)
{
OnZoomChanged(this, oldZoom, newZoom);
}
}
protected override void OnDisable()
{
base.OnDisable();
if (m_UnloadOnDisable && m_IsLoaded)
{
if (m_Renderer != null)
m_Renderer.Dispose();
m_Renderer = null;
CleanUp();
}
NotifyDisabled();
GC.Collect();
GC.WaitForPendingFinalizers();
}
protected override void OnEnable()
{
base.OnEnable();
m_Canvas = GetComponentInParent