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