Telerik PDF查看器未加载

时间:2018-04-20 19:04:15

标签: winforms azure telerik blob pdfviewer

我正在尝试使用Telerik的RadPdfViewer,但我遇到了一个问题。我似乎无法得到它来加载任何文件。我试图从blob的azure存储流加载,我正确地连接到了,但我似乎无法让pdf查看器显示pdf。

如果有人能指出我正确的方向,我们将非常感激

以下是我从blob获取pdf的代码:

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

以下是我从其他表单调用该代码的代码:

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

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

然后最后这就是我调用方法的方法,我将其置于选择更改中。

    pdfViewer.LoadDocument(callPDFPreivew());

2 个答案:

答案 0 :(得分:0)

我没有AzureBlob实例来测试它,但是流可能需要重新定位。

试试这个作为快速测试:

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

如果这不起作用,open a private Support Ticket在这里,我可以使用blob凭证直接测试这个

答案 1 :(得分:0)

感谢您的建议Lance,但我能够使用此代码

                            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是我从

获取代码的地方