我想在我的网站中嵌入PDF文件,它看起来像这样:
I wanted to embed a PDF file in my website, it looked like this:
<object data="data/PDFTest1.pdf" type="application/pdf" id="data"></object>但是随后我想首先使用ajax获取文件(在javascript文件中),在JavaScript中编辑它的源代码,然后创建< object> 并将结果数据提供给它.问题是对象在其 data 属性中需要一个url,并且不直接接受实际数据.我该如何处理?
But then I wanted to first Get the file with ajax (in a javascript file), edit it's source code in JavaScript, and then create an <object> and give it the resulting data. The problem is that the Object needs a url in its data attribute, and does not accept the actual data directly. How can I handle this?
有没有一种方法可以创建伪造的网址"?例如在javascript中?
Is there a way to create a "fake url" in javascript for example?
还是我可以通过其他方式将数据传递给对象?
Or can I somehow pass the data in another way to the object?
还是应该使用其他标签?
Or should I maybe use some other tag ?
在此先感谢您的英语.
推荐答案您实际上不需要URL.您可以将PDF转换为base64,并将data属性设置为数据本身.您只需要在base64前面加上数据:"前缀,然后是mime类型,分号"base64",然后是代表PDF的base64编码字符串.
You don't actually need a URL. You can convert the PDF to base64 and set the data attribute to the data itself. You just need to prefix the base64 with "data:" then the mime type, a semi-colon, "base64," and then the base64 encoded string that represents the PDF.
<object data="data:application/pdf;base64,YOURBASE64DATA" type="application/pdf"></object>更多推荐
直接为Object标签提供数据
发布评论