PDFViewer_API_Usage.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace Paroxe.PdfRenderer.Examples
  5. {
  6. public class PDFViewer_API_Usage : MonoBehaviour
  7. {
  8. public PDFViewer m_Viewer;
  9. public PDFAsset m_PDFAsset;
  10. IEnumerator Start()
  11. {
  12. #if UNITY_WEBGL
  13. yield break;
  14. #else
  15. Debug.Log(Application.persistentDataPath);
  16. m_Viewer.gameObject.SetActive(true);
  17. m_Viewer.LoadDocumentFromWeb("http://www.pdf995.com/samples/pdf.pdf", "");
  18. // Wait until the pdf document is loaded.
  19. while (!m_Viewer.IsLoaded)
  20. yield return null;
  21. PDFDocument document = m_Viewer.Document;
  22. Debug.Log("Page count: " + document.GetPageCount());
  23. PDFPage firstPage = document.GetPage(0);
  24. Debug.Log("First Page Size: " + firstPage.GetPageSize());
  25. PDFTextPage firstTextPage = firstPage.GetTextPage();
  26. Debug.Log("First Page Chars Count: " + firstTextPage.CountChars());
  27. IList<PDFSearchResult> searchResults = firstTextPage.Search("the", PDFSearchHandle.MatchOption.NONE, 0);
  28. Debug.Log("Search Results Count: " + searchResults.Count);
  29. // Wait 2 seconds and then load another document
  30. yield return new WaitForSeconds(2.0f);
  31. m_Viewer.LoadDocumentFromAsset(m_PDFAsset);
  32. #endif
  33. }
  34. }
  35. }