- Luis Alberto Coca
- PowerBuilder
- Monday, 28 March 2022 12:50 AM UTC
I am using PB2019R3 consuming with an API that returns a PDF in Blob. I use HttpClient supports Blob response, checking the size of the file I use Len and it is correct.
My problem is how to convert or decode the Blob to PDF to save on local machine.
Reading Powerbuilder 2019R3 documentation, I can't find anything related. In forums I find FileOpen , FileReadEx and OleObject mentioned but no luck.
Only the WebBrowser that supports JavaScript seems to me the best option. First I test creating the script in an html5 and it works I can see the PDF in the Web browser,
<script>
fetch(getInvoice, {
method: "GET",
headers: {
"Content-Type": "Application/PDF",
Authorization: "Bearer " + dataToken,
},
})
.then((Res) => {
if (Res.status === 200) {
return Res.blob();
//return Res.text();
} else {
alert("Error Status :" + Res.status);
}
})
.then((data) => {
const domString = URL.createObjectURL(data);
document.querySelector("#DisplayPdf").setAttribute("src", domString);
});
</script>
now I pass it to EvaluateJavascriptSync and it seems that it does not support fetch. I test with XMLHttpRequest
ls_get_invoice_pdf = 'function get_invoice_Display() {'+&
' fetch(getInvoice,{'+&
' method: "GET",'+&
' headers:{;'+&
' "Content-Type": "Application/PDF",'+&
' "Authorization": "Bearer " + dataToken,'+&
' },'+&
' })'+&
' .then(Res => {'+&
' if(Res.status === 200){'+&
' return Res.blob();'+&
' }else{'+&
' alert("Error Status :" + Res.status);'+&
' }'+&
' })'+&
' .then((data) => {;'+&
' const domString = URL.createObjectURL(data);'+&
' document.body.innerHTML = `'+&
' <embed '+&
' src=""'+&
' type="application/pdf"'+&
' width="800px"+&
' height="600px"'+&
' id="DisplayPdf"'+&
' />'+&
'`;'+&
' document.querySelector("#DisplayPdf").setAttribute("src", domString);'+&
' });'+&
'} get_invoice_Display(); '
wb_webbrowser_pdf.evaluatejavascriptsync(ls_get_invoice_pdf)
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.