0

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());
DalTron
  • 939
  • 3
  • 9
  • 22

2 Answers2

0

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

Lance McCarthy
  • 1,884
  • 1
  • 20
  • 40
0

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

DalTron
  • 939
  • 3
  • 9
  • 22
  • Excellent. That does essentially the same thing as it reads the stream from position 0. – Lance McCarthy Apr 20 '18 at 20:54
  • Yeah, but I had to add additional usings and I still don't know why the other way didn't work and why it didn't even give me an error. – DalTron Apr 20 '18 at 21:02