我想将字节数组转换为有角度的pdf文件。 我已经尝试过下面的堆栈溢出解决方案。但是它没有用。
Open pdf from bytes array in angular 5
service.ts
viewPDF(seqno): any {
const headers = new HttpHeaders(
{
'responseType' : 'arraybuffer' as 'json'
}
);
return this.httpClient.get<any[]>(environment.apiBaseUrl
"intranet/getFileBySeqNo/"+seqno+"",{headers});
}
component.ts
this.httpClientService.viewPDF(x).subscribe(data => {
let file = new Blob([data], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
});
java控制器
public byte[] getFileBySeqNo(int seqNo) {
String systemGuides =null;
byte[] pdf = null;
String sql = "select audio_video_path from slr_r_system_guide
where seq_no=:seqNo";
try {
systemGuides = jdbcTemplate.queryForObject(sql, new
String[] {},String.class);
Path pdfPath = Paths.get(systemGuides);
try {
pdf = Files.readAllBytes(pdfPath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
logger.error(IILUtils.getStackTraceFromException(e));
}
return pdf;
}
有人可以帮助我吗?