【发布时间】:2022-07-01 22:44:57
【问题描述】:
我有一个代码,我从服务器下载 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);
}
【问题讨论】:
-
使用 C# pdf 库。
-
@NicolasTyler 谢谢你的建议,你能告诉我如何以及在哪里可以使用它。