首先导入Paroxe PDFRenderer 插件
Unity3D 加载PDF文件以及简单的切换页面_unity 打开word pdf_菜菜ANY的博客-CSDN博客先导入插件 PDFRenderer链接: 提取码: z78q然后使用以下代码就可以using Paroxe.PdfRenderer;using System.Collections;using System.Collections.Generic;using System.IO;using UnityEngine;using UnityEngine.Networking;using U._unity 打开word pdf
UnityWebRequest 读取PDF
UnityWebRequest request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();if (!request.isNetworkError && request.isDone)
{bytesDocument = request.downloadHandler.data;
}
使用获取到的字节数组打开PDF
documentPDF = new PDFDocument(bytesDocument);
RawImage 显示PDF
currentPage = 0;
Texture2D pdf = documentPDF.Renderer.RenderPageToTexture(documentPDF.GetPage(currentPage));ure = pdf;
UnityWebRequest 读取PDF
UnityWebRequest request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();if (!request.isNetworkError && request.isDone)
{bytesDocument = request.downloadHandler.data;
}
使用获取到的字节数组打开PDF
PDFJS_Promise<PDFDocument> documentPromise = PDFDocument.LoadDocumentFromBytesAsync(bytesDocument);while (!documentPromise.HasFinished)
{yield return null;
}if (!documentPromise.HasSucceeded)
{yield break;
}documentPDF = documentPromise.Result;
RawImage 显示PDF
currentPage = 0;
PDFJS_Promise<PDFPage> pagePromise = documentPDF.GetPageAsync(currentPage);while (!pagePromise.HasFinished)
{yield return null;
}if (!pagePromise.HasSucceeded)
{yield break;
}PDFPage pagePDF = pagePromise.Result;PDFJS_Promise<Texture2D> renderPromise = PDFRenderer.RenderPageToTextureAsync(pagePDF, (int)pagePDF.GetPageSize().x, (int)pagePDF.GetPageSize().y);while (!renderPromise.HasFinished)
{yield return null;
}if (!renderPromise.HasSucceeded)
{yield break;
}Texture2D pdf = renderPromise.ure = pdf;
PC 平台通过PDFDocument.GetPage(int) 获取指定页码的PDF,WebGL 平台通过PDFDocument.GetPageAsync(int) 获取指定页码的PDF,修改参数即可实现翻页
sumPages = documentPDF.GetPageCount(); //PDF总页码//下一页
currentPage += 1;
if (currentPage >= sumPages)
{currentPage = 0;
}/* todo
* 切换显示PDF
*///上一页
currentPage -= 1;
if (currentPage < 0)
{currentPage = sumPages - 1;
}/* todo
* 切换显示PDF
*/
Unity3D 加载PDF文件以及简单的切换页面_unity 打开word pdf_菜菜ANY的博客-CSDN博客先导入插件 PDFRenderer链接: 提取码: z78q然后使用以下代码就可以using Paroxe.PdfRenderer;using System.Collections;using System.Collections.Generic;using System.IO;using UnityEngine;using UnityEngine.Networking;using U._unity 打开word pdf
if (!Directory.Exists(downloadPath))
{Directory.CreateDirectory(downloadPath);
}string downloadFileName = url.Substring(url.LastIndexOf('/') + 1);
string localPath = downloadPath + "/" + downloadFileName;UnityWebRequest webRequest = UnityWebRequest.Get(url);
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{if (File.Exists(localPath)){File.Delete(localPath);}
}
else
{var file = webRequest.downloadHandler.data;FileStream fileStream = new FileStream(localPath, FileMode.Create);fileStream.Write(file, 0, file.Length);fileStream.Close();
}
UnityWebGL截图/图片/文件调用浏览器下载 | 梓喵出没 (azimiao).html
根据参考编写jslib,并放入Plugins 文件夹
引入dll
[DllImport("__Internal")]
private static extern void PDFDownloader(string strData, string fileName);
实现下载
string downloadFileName = url.Substring(url.LastIndexOf('/') + 1);UnityWebRequest request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();if (!request.isNetworkError && request.isDone)
{byte[] downloadBytes = request.downloadHandler.data;if (downloadBytes != null){PDFDownloader(System.Convert.ToBase64String(downloadBytes), downloadFileName);}
}
Android用PdfRenderer类开发打开pdf文件的功能_android pdfrenderer-CSDN博客PdfRenderer是Android官方用于开发打开pdf文件功能的类,今天介绍一下它的最基本的使用。 使用PdfRenderer有这么几步: 1、用文件的路径生成一个File对象: File file = new File("/mnt/sdcard/printTemplate.pdf"); 2、然后需要用ParcelFileDescriptor类对File对象打一下包: _android pdfrenderer
各种文件对应的ContentType,拿来即用_pdf的contenttype_way_more的博客-CSDN博客Content-TypeContent-Type即内容类型,Content-Type用于定义网络文件的类型和网页的编码,决定文件接收方将以什么形式、什么编码读取这个文件,这就是经常看到一些网页点击的结果却是下载到的一个文件或一张图片的原因。ContentType属性指定响应的 HTTP内容类型。如果未指定 ContentType,默认为TEXT/HTML。我们在代码也经常需要定义ContentType,用于指定响应的类型例:response.setCharacterEncoding("utf-8"_pdf的contenttype
【100个 Unity实用技能】| Unity中常用的几种路径 分析,不同平台路径总结_unity 路径_呆呆敲代码的小Y的博客-CSDN博客在Unity中有很多种路径,尤其是在不同的平台上,同一种路径的写法可能最终是不一样的。本文就来总结一下Unity中的几种路径,以及简单的使用方法。_unity 路径
本文发布于:2024-01-28 16:33:35,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064308168757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |