0

我正在尝试使用 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());
4

2 回答 2

0

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

试试这个作为快速测试:

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

如果这不起作用,请在此处打开私人支持票证,以便我可以直接使用 blob 凭据进行测试

于 2018-04-20T19:51:05.167 回答
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);
                        }
                    }

是我从那里得到代码的地方

于 2018-04-20T20:11:56.463 回答