for web api I am returing the pdf as :-如何在reactjs中打開pdf?
[EnableCors("*", "*", "*")]
[HttpGet]
public byte[] GetReportData()
{
string filePath = "D:\\Decoding.pdf";
byte[] bytes = File.ReadAllBytes(filePath);
return bytes;
}
我打電話我的動作和減速的方法: -
操作: -
export function LoadReportData() {
return (dispatch) => {
dispatch({
type: REQUEST_REPORT,//defining the name of the action to identify in the reducer
});
fetch(APIPATH+'Requisition/GetReportData')//calling the service
.then((response) => response.json())
.then((report) => dispatch(receiveReport(report)));//passing the data to other actions
}
}
//this method use to pass the data coming for the lab test result to the component
export function receiveReport(report) {
return {
type:RECEIVE_REPORT,//defining the name of the action to identify in the reducer
report:report//passing the data to reducer
};
}
減速器: -
case 'RECEIVE_REPORT':
return Object.assign({}, state, {
report: action.report,
loadingReport: false,
});
case 'REQUEST_REPORT':
return Object.assign({}, state, {
loadingReport: true
});
現在新報告就像我從web api傳遞的字節一樣。現在我的要求是,我怎樣才能顯示這個PDF文件,即從我的組件或瀏覽器的下一個選項卡中的web api字節數組來? 注:報告包含字節
@Vadim我試過了,但「Uncaught ReferenceError:PDFJS未定義」即將出現錯誤 – jack123