XRoom_Unity/Assets/Paroxe/PDFRenderer/Examples/Scripts/PDFViewer_API_Usage.cs
2025-05-31 10:20:20 +03:30

49 lines
1.4 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Paroxe.PdfRenderer.Examples
{
public class PDFViewer_API_Usage : MonoBehaviour
{
public PDFViewer m_Viewer;
public PDFAsset m_PDFAsset;
IEnumerator Start()
{
#if UNITY_WEBGL
yield break;
#else
Debug.Log(Application.persistentDataPath);
m_Viewer.gameObject.SetActive(true);
m_Viewer.LoadDocumentFromWeb("https://www.dropbox.com/s/tssavtnvaym2t6b/DocumentationEN.pdf?raw=1", "");
// Wait until the pdf document is loaded.
while (!m_Viewer.IsLoaded)
yield return null;
PDFDocument document = m_Viewer.Document;
Debug.Log("Page count: " + document.GetPageCount());
PDFPage firstPage = document.GetPage(0);
Debug.Log("First Page Size: " + firstPage.GetPageSize());
PDFTextPage firstTextPage = firstPage.GetTextPage();
Debug.Log("First Page Chars Count: " + firstTextPage.CountChars());
IList<PDFSearchResult> searchResults = firstTextPage.Search("the");
Debug.Log("Search Results Count: " + searchResults.Count);
// Wait 2 seconds and then load another document
yield return new WaitForSeconds(2.0f);
m_Viewer.LoadDocumentFromAsset(m_PDFAsset);
#endif
}
}
}