using Paroxe.PdfRenderer; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; using static LangChaoRommMinIo; public class PdfManager : BaseFilePrefabItem { private PDFViewer pdfview; public override void Init(FileConfig fileConfig) { base.Init(fileConfig); if (!string.IsNullOrEmpty(fileConfig.Url)) { string url = fileConfig.Url; if (!fileConfig.Url.Contains("http")) { url = "https://" + fileConfig.Url; } showPDF(url); LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => { Debug.Log("rfd==>" + rfd.url); Debug.Log("rfd==>" + rfd.bytes.Length); string url = rfd.url; // StartCoroutine(SavePDF(Application.persistentDataPath + "/" + fileConfig.UUid + Path.GetExtension(fileConfig.FileName), rfd.bytes)); }); } } private IEnumerator SavePDF(string path, byte[] bytes) { Debug.Log(" Path ==> " + path); FileInfo file = new FileInfo(path); if (file.Exists) { // file.Delete(); yield return new WaitForSeconds(0.02f); showPDF(path); } else { Stream sw = File.Create(path); // FileStream sw = new FileStream(path); sw.Write(bytes, 0, bytes.Length); sw.Close(); sw.Dispose(); yield return new WaitForSeconds(0.02f); showPDF(path); } } public void showPDF(string url) { //this.transform.localPosition = new Vector3(0,0,0.69f); pdfview = this.GetComponent(); pdfview.FileURL = url; pdfview.LoadDocument(); } public override void OnScaleStopped() { if (transform.localScale.x < 0.0001f) { transform.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f); } } }