希望將可點擊鏈接添加到通過 API 連接到 SSRS 的 C# Web 應用程式。單擊鏈接時,應用程式應從 SSRS 下載 pdf 檔案。
當前實作下載檔案,但內容為空白。希望能得到一些幫助,以便資料出現在 pdf 中。
控制器.cs
[HttpGet]
[Route("ssrs")]
public async Task<IHttpActionResult> GetSsrsReportAsync()
{
var clientHandler = new HttpClientHandler();
clientHandler.UseDefaultCredentials = true;
clientHandler.PreAuthenticate = true;
clientHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
var client = new HttpClient(clientHandler);
byte[] response = await client.GetByteArrayAsync("http://***.***.local/ReportServer?/proj_20800014/SE_SurfaceWater_Tbl&rs:Command=Render&rs:Format=PDF"); // returns html cause its a webpage
return new FileResult(new MemoryStream(response), Request, "HelloWorld.pdf");
}
報告.vue
methods: {
GetSsrsReport() {
axios.get(`/api/library/portfolio/ssrs`)
.then(results => {
console.log(results.data);
const fileName = 'HelloWorld.pdf';
let theNewFile = atob(results.data);
let blob = new Blob([theNewFile]);
if (navigator.msSaveBlob) {
return navigator.msSaveBlob(blob, fileName);
}
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
blob = null;
})
.catch(error => {
console.error(error);
});
},
}
uj5u.com熱心網友回復:
與引數結合的本機ReportServerrs:Format=PDF應該始終是 PDF 檔案,而不是 html。
問題可能是您已經組合了rs:Command=Render首先處理的引數,因此rs:Format忽略了。
試試這個 URL:
http://***.***.local/ReportServer?/proj_20800014/SE_SurfaceWater_Tbl&rs:Format=PDF
要驗證,只需將其保存byte[] response到檔案并驗證您可以將其作為預期的 PDF 檔案打開。
這在檔案中是模棱兩可的:Export a Report Using URL Access
uj5u.com熱心網友回復:
我試過
byte[] response = await client.GetByteArrayAsync("http://europa.ddms.local/ReportServer?/proj_20800014/SE_SurfaceWater_Tbl_pdf&rs:Format=PDF");
var result = Convert.ToBase64String(response);
return Json(result);
但是在將字串轉換為 js 方面的 pdf 檔案時遇到問題。遇到一個"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded error"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/405164.html
標籤:
