如何将下载的文件类型转换为Unity的PDF?
我有一个代码,我正在从服务器下载PDF文件并将其存储到application.persistantdatapath。然后将PDF转换为图像,以便可以在统一的书上渲染它们。这里的问题是,每当下载文件时,其格式将更改为文件类型而不是PDF类型,因此我无法将下载的文件转换为图像。我如何解决这个问题?以下是从远程服务器下载文件的代码。
public void OnClickLoadIngestionEngine(string link, string bookName)
{
bookLink = link;
bookTitle = bookName;
StartCoroutine(DownloadFile(link, bookName));
}
public IEnumerator DownloadFile(string urlString, string bookFilename)
{
path = Path.Combine(Application.persistentDataPath + bookFilename +".pdf");
var uwr = new UnityWebRequest(urlString, UnityWebRequest.kHttpVerbGET);
DontDestroyOnLoad(this);
uwr.downloadHandler = new DownloadHandlerFile(path);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.LogError(uwr.error);
}
else
{
Debug.Log("File successfully downloaded and saved to " + path);
}
SceneManager.LoadScene(ingestionScene);
}
以下是将PDF转换为图像的代码
public void Start()
{
pathStr = GameObject.Find("UI_Manager").GetComponent<UIManager>().path;
string temp = pathStr +".pdf";
Debug.Log(pathStr);
imageStr = Path.Combine(pathStr + bookGameObjectName);
if (!Directory.Exists(imageStr))
{
Directory.CreateDirectory(imageStr);
}
PDFConvert converter = new PDFConvert();
converter.Convert(@temp,
@"C:\\Users\\Lenovo\\AppData\\LocalLow\\ACK\\Bimbisara\\%01d.jpg",
1,
36,
"jpeg",
600,
700);
}
I have a code where I'm downloading pdf file from server and storing it to Application.persistantDataPath. and then converting the pdf to Images so that they can be rendered on a book in unity. Here the issue is that whenever the file is downloaded its format is changed to file type and not pdf type due to which I'm not able to convert the downloaded file to Images. How I can solve this issue? Below is the code which is helps to download file from remote server.
public void OnClickLoadIngestionEngine(string link, string bookName)
{
bookLink = link;
bookTitle = bookName;
StartCoroutine(DownloadFile(link, bookName));
}
public IEnumerator DownloadFile(string urlString, string bookFilename)
{
path = Path.Combine(Application.persistentDataPath + bookFilename +".pdf");
var uwr = new UnityWebRequest(urlString, UnityWebRequest.kHttpVerbGET);
DontDestroyOnLoad(this);
uwr.downloadHandler = new DownloadHandlerFile(path);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.LogError(uwr.error);
}
else
{
Debug.Log("File successfully downloaded and saved to " + path);
}
SceneManager.LoadScene(ingestionScene);
}
Below is code that converts pdf to images
public void Start()
{
pathStr = GameObject.Find("UI_Manager").GetComponent<UIManager>().path;
string temp = pathStr +".pdf";
Debug.Log(pathStr);
imageStr = Path.Combine(pathStr + bookGameObjectName);
if (!Directory.Exists(imageStr))
{
Directory.CreateDirectory(imageStr);
}
PDFConvert converter = new PDFConvert();
converter.Convert(@temp,
@"C:\\Users\\Lenovo\\AppData\\LocalLow\\ACK\\Bimbisara\\%01d.jpg",
1,
36,
"jpeg",
600,
700);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题不是PDF转换器无法读取您提供的文件,而是因为您提供的路径而找不到它,
请看到您的字符串称为temp,并带有您要读取的文件的路径,而是可能看起来类似:“ RandomFile.pdf”。但是,当PDF转换器想要获取此文件时,找不到它,因为下载的文件还没有.pdf扩展名,它只是称为:“ RandomFile”,
总而言之,我认为如果您更改,我认为它应该有效:
string temp = pathStstr +“。pdf”;
到
字符串temp = pathstr;
I believe the problem is not the that PDF converter cant read the file you are supplying but it simply cannot find it because of the path you are supplying
See you have String called temp with the path of the file you want to read, wich might look something like: "Randomfile.pdf". But when the PDF converter wants to get this file it cannot find it because the downloaded file does not have the .pdf extension yet, it is just called: "Randomfile"
In conclusion i think it should work if you change:
string temp = pathStr +".pdf";
to
string temp = pathStr;