Embedding pdf and images in html

I need to embed both pdf-files and images in my html-page, however, due to the fact that my html contains a form and the user has to be able to decide whether he would like to upload a pdf-file or an image, I need a flexible solution regarding how to embed either a pdf-file or an image with the same code. I read that I could possibly use the <object/> tag, however, I also read that that's not a very "elegant" and possibly slow solution. I also considered to use <embed/> which, as of right now, is the best solution I could come up with. Unfortunately I couldn't find out about if it's a very conventional solution or not.

I can't seem to find very much resources regarding this topic online, hence why I'm asking here. Are there any other/better ways to embed a pdf- or image-file in an html page?

Edit: I want top display the pdf kind of like a file. Also, I don't want the user to be able to resize the pdf in the viewer


I'm sure this is better suited to a comment, however I'm new and am working on unlocking that feature.

...however, due to the fact that my html contains a form and the user has to be able to decide whether he would like to upload a pdf-file or an image...

What are you using for the form (query language & database management)?

(PHP, Django, MySQL, MongoDB, etc)

Are there any other/better ways to embed a pdf- or image-file in an html page?

I would recommend using embed or iframes. You are correct in thinking that the object tag is not an elegant solution, since you are dealing with images.

Edit: I want top display the pdf kind of like a file. Also, I don't want the user to be able to resize the pdf in the viewer

Easy to do with iframes. There's a lot of hate when it comes to iframes. As you seem to plan on using it as a tool to display a file within a page, then I believe using an iframe here is just fine.

Check out this link on iframes. (will also tell you how to keep the user from resizing it)

链接地址: http://www.djcxy.com/p/36420.html

上一篇: 在浏览器中显示PDF时,大多数浏览器会发出多个HTTP请求

下一篇: 在html中嵌入pdf和图像