【问题标题】:How do I convert downloaded file type to pdf in unity?如何统一将下载的文件类型转换为pdf?
【发布时间】: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 谢谢你的建议,你能告诉我如何以及在哪里可以使用它。

标签: c# unity3d unity-ui


【解决方案1】:

我认为问题不在于 PDF 转换器无法读取您提供的文件,而是因为您提供的路径而无法找到它

看到你有一个名为 temp 的字符串,其中包含你要读取的文件的路径,它可能看起来像:“Randomfile.pdf”。但是当 PDF 转换器想要得到这个文件时它找不到它,因为下载的文件还没有 .pdf 扩展名,它只是被称为:“Randomfile”

总之,我认为如果你改变它应该可以工作:

string temp = pathStr +".pdf";

string temp = pathStr;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 2012-04-04
    • 2017-07-28
    • 1970-01-01
    • 2013-08-26
    相关资源
    最近更新 更多