Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  15] [ 4]  / answers: 1 / hits: 16642  / 7 Years ago, wed, april 5, 2017, 12:00:00

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>

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?


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 ?


Thanks in advance and sorry for my English.


More From » html

 Answers
26

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>

[#58259] Monday, April 3, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsleyashlynnh

Total Points: 64
Total Questions: 119
Total Answers: 98

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
;