Unity 打開PDF顯示在UI或者物體上面


1.里面有用到PDF插件,如果你沒有插件可以去下面鏈接下載:

有積分了可以直接下,沒有的可以評論聯系我,給你發

            

                        插件下載

 

2.  這是設置對象

 

 

 

下面上腳本

using Paroxe.PdfRenderer;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class DocumentGroup : MonoBehaviour
{
    public float m_Page = 0;  
    string downloadFileName;   //pdf 地址    
    public GameObject link;   //plane  也可以  
    public RawImage rawImage;  //UI  也可以

    private void Update()
    {
        m_Page += Time.deltaTime;
        PrintLocalPDF();
    }
    public void PrintLocalPDF()
    {

#if UNITY_EDITOR
        downloadFileName = Application.dataPath + "/wcl.pdf";
        print(downloadFileName);
#elif UNITY_ANDROID
        downloadFileName = Application.persistentDataPath+"/wcl.pdf";       
#endif

        PDFDocument pdfDocument = new PDFDocument(downloadFileName);


        if (pdfDocument.IsValid)
        {
            int pageCount = pdfDocument.GetPageCount();

            PDFRenderer renderer = new PDFRenderer();
            Texture2D tex = renderer.RenderPageToTexture(pdfDocument.GetPage((int)m_Page % pageCount), 1024, 1024);

            tex.filterMode = FilterMode.Bilinear;
            tex.anisoLevel = 8;
           // link.GetComponent<MeshRenderer>().material.mainTexture = tex;  
            rawImage.texture = tex;
        }
    }
}

運行就能播放了,具體擴展看自己需求

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM