Telerik PDF viewer not loading

867 Views Asked by At

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

There are 2 best solutions below

2
DalTron On BEST ANSWER

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

0
Lance McCarthy On

I dont have a AzureBlob instance to test this with but it's possible the stream need to re-positioned.

Try this as a quick test:

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

If that doesn't work, open a private Support Ticket here so I can test this directly using the blob credentials