0

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);


    }
Omkar P
  • 29
  • 5

1 Answers1

1

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;

Allan Vonk
  • 11
  • 2
  • Hi, thank you for suggestion I tried and changed the code, Where in pdf to image conversion will be done in coroutine but no out put, and also I have noticed pdf is not converted to Images. – Omkar P Jul 01 '22 at 16:13