如何将下载的文件类型转换为Unity的PDF?

发布于 2025-02-12 04:40:06 字数 1789 浏览 3 评论 0原文

我有一个代码,我正在从服务器下载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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-02-19 04:40:06

我相信问题不是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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文