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;
        }
    }
}
复制代码

运行就能播放了,具体扩展看自己需求

 

posted @   剑起苍穹  阅读(1421)  评论(4编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
/*鼠标点击特效*/
点击右上角即可分享
微信分享提示