cordova 如何将PDF作为二进制文件传递到window.open()?

k5hmc34c  于 2023-03-08  发布在  其他
关注(0)|答案(2)|浏览(129)

我正在使用Cordova/ionic构建一个应用程序,现在我从一个API获取PDF(我使用该API进行了身份验证)。然后我想在inAppBrowser中显示此PDF,通常使用window.open('http://example.com/the-file.pdf', "_blank", "location=no");打开此浏览器。但是由于我已经获取了数据,因此无法提供URL,而是希望以二进制形式提供数据。
我四处搜索,但只找到了this SO answer,不幸的是,它对我不起作用。
有人知道如何通过window.open()将PDF作为二进制数据传递吗?欢迎使用所有技巧!

l7mqbcuq

l7mqbcuq1#

请看这里的答案:https://stackoverflow.com/a/43297424/1426222

window.open("data:application/pdf;base64,JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwogIC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAvTWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0KPj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAgL1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9udAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2JqCgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAwMDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9vdCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G", "mypdf", "width=700px,height=600px");
new9mtju

new9mtju2#

试试这个

Window.open('http://docs.google.com/gview?url=YOUR_PDF_URL', "_blank", "location=no");

相关问题