Telerik PDF 查看器未加载
Telerik PDF viewer not loading
我正在尝试使用 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());
我没有用于测试的 AzureBlob 实例,但流可能需要重新定位。
试试这个作为快速测试:
using(var memoryStreamFromByte = new MemoryStream(azureFileUpload.PreviewBlob(file.Name)))
{
memoryStreamFromByte.Position = 0;
return memoryStreamFromByte;
}
如果这不起作用,open a private Support Ticket 在这里,这样我就可以使用 blob 凭据直接测试它
感谢 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);
}
}
是我从
那里得到代码的地方
我正在尝试使用 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());
我没有用于测试的 AzureBlob 实例,但流可能需要重新定位。
试试这个作为快速测试:
using(var memoryStreamFromByte = new MemoryStream(azureFileUpload.PreviewBlob(file.Name)))
{
memoryStreamFromByte.Position = 0;
return memoryStreamFromByte;
}
如果这不起作用,open a private Support Ticket 在这里,这样我就可以使用 blob 凭据直接测试它
感谢 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);
}
}