Exemple #1
0
    void TextPageAPI(PDFDocument document)
    {
        Debug.Log("TEXTPAGE API-------------------------");

        PDFPage page = document.GetPage(1);

        Debug.Log("Page size: " + page.GetPageSize());

        PDFTextPage textPage   = page.GetTextPage();
        int         countChars = textPage.CountChars();

        Debug.Log("Page chars count: " + countChars);

        string str = textPage.GetText(0, countChars);

        Debug.Log("Page text: " + str);

        int rectCount = textPage.CountRects(0, countChars);

        Debug.Log("Rect count: " + rectCount);

        string boundedText = textPage.GetBoundedText(0, 0, page.GetPageSize().x, page.GetPageSize().y * 0.5f, 2000);

        Debug.Log("Bounded text: " + boundedText);
    }
Exemple #2
0
    IEnumerator Start()
    {
#if UNITY_WEBGL
        yield break;
#else
        Debug.Log(Application.persistentDataPath);

        m_Viewer.gameObject.SetActive(true);

        m_Viewer.LoadDocumentFromWeb("http://www.pdf995.com/samples/pdf.pdf", "");

        // 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", PDFSearchHandle.MatchOption.NONE, 0);
        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
    }
Exemple #3
0
    IEnumerator Start()
    {
        Debug.Log("WebGLTest: ");

        PDFJS_Promise <PDFDocument> documentPromise = PDFDocument.LoadDocumentFromUrlAsync("https://crossorigin.me/http://www.pdf995.com/samples/pdf.pdf");

        while (!documentPromise.HasFinished)
        {
            yield return(null);
        }

        if (!documentPromise.HasSucceeded)
        {
            Debug.Log("Fail: documentPromise");
            yield break;
        }
        else
        {
            Debug.Log("Success: documentPromise");
        }

        PDFDocument document = documentPromise.Result;

        PDFJS_Promise <PDFPage> pagePromise = document.GetPageAsync(0);

        while (!pagePromise.HasFinished)
        {
            yield return(null);
        }

        if (!pagePromise.HasSucceeded)
        {
            Debug.Log("Fail: pagePromise");
            yield break;
        }
        else
        {
            Debug.Log("Success: pagePromise");
        }

        PDFPage page = pagePromise.Result;

        PDFJS_Promise <Texture2D> renderPromise = PDFRenderer.RenderPageToTextureAsync(page, (int)page.GetPageSize().x, (int)page.GetPageSize().y);

        while (!renderPromise.HasFinished)
        {
            yield return(null);
        }

        if (!renderPromise.HasSucceeded)
        {
            Debug.Log("Fail: pagePromise");
            yield break;
        }

        Texture2D renderedPageTexture = renderPromise.Result;

        (m_RawImage.transform as RectTransform).sizeDelta = new Vector2(renderedPageTexture.width, renderedPageTexture.height);
        m_RawImage.texture = renderedPageTexture;

        yield return(new WaitForSeconds(2.5f));
    }