当前位置: 首页 > 工具软件 > PDF Renderer > 使用案例 >

Unity基于PDFRenderer插件实现文档查看功能

宗政卓
2023-12-01

自定义文档查看功能

IEnumerator LoadPdfBytes( string _path)

 {
    WWW request = new WWW(_path);

    yield return request;

    if (request.isDone)
    {
        PDFDocument document = new PDFDocument(request.bytes, "");
        int pageCount = document.GetPageCount();

        for (int i = 0; i < contentFather.childCount; i++)
        {
            Destroy(contentFather.GetChild(i).gameObject);
        }

        for (int i = 0; i < pageCount; i++)
        {
            PDFPage pdf = document.GetPage(i);

            PDFRenderer render = new PDFRenderer();

            Texture2D texture = render.RenderPageToTexture(pdf, 598 * 3, 842 * 3);

            GameObject raw = Instantiate((GameObject)Resources.Load("Item/itemPDF"));

            raw.transform.SetParent(contentFather);
            
            raw.GetComponent<RawImage>().texture = texture;

            raw.transform.localScale = Vector3.one;

        }
      

    }
    else
    {
        Debug.Log(request.error);
    }
}
 类似资料: