Search code examples
winformsazuretelerikblobpdfviewer

Telerik PDF viewer not loading


I am trying to use Telerik's RadPdfViewer, but I've run into a problem. I cannot seem to get the it to load any document. I am trying to load by stream from azure storage from a blob, I am connected to that correctly, but I can't seem to get the pdf viewer to display the pdf.

If anyone could point me in the right direction it would be very much appreciated

Here is my code to get the pdf from the blob:

    public byte[] PreviewBlob(string blobUri)
    {
        //Create the credentials to save to Azure Blob
        StorageCredentials credentials = new StorageCredentials("pdmacstorage", "IhaveThisEnteredCorrectlyNoWorries");

        //Set the top level container for the file
        folderPath = "job-file";

        //Connect to Azure using the above credentials
        CloudBlobClient client = new CloudBlobClient(new Uri("https://pdmacstorage.blob.core.windows.net/"), credentials);

        //Get refrence to the container
        CloudBlobContainer container = client.GetContainerReference(folderPath);

        //Get refrence to the blob
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobUri);

        using(var memoryStream = new MemoryStream())
        {
            blockBlob.DownloadToStream(memoryStream);
            return memoryStream.ToArray();
        }
    }

Here is my code to call that from another form:

    private Stream callPDFPreivew()
    {
        //Connection to PDData AzureJobFileUploader
        AzureJobFileUploader azureFileUpload = new AzureJobFileUploader();

        using(var memoryStreamFromByte = new MemoryStream(azureFileUpload.PreviewBlob(file.Name)))
        {
            return memoryStreamFromByte;
        }
    }

Then finally this is how I am calling the method, I have this placed in a selection change even.

    pdfViewer.LoadDocument(callPDFPreivew());

Solution

  • Thanks for your suggestion Lance, but I was able to get a work around using this code

                                using(WebClient client = new WebClient())
                        {
                            using(Stream ms = new MemoryStream(client.DownloadData(file.Uri.ToString())))
                            {
                                MemoryStream mStream = new MemoryStream();
                                mStream.SetLength(ms.Length);
                                ms.Read(mStream.GetBuffer(), 0, (int) ms.Length);
                                pdfViewer.LoadDocument(mStream);
                            }
                        }
    

    Here is where I got that code from