how i can preview files(documents and images) in angular 6?

笑着哭i 提交于 2019-12-11 17:56:39

问题


I am using angular 6 and need to preview files which are present in some path. I need to preview any file type like img,doc,pdf,excel etc(All office documents). Is there is any single library which support both or need to use different for the same. Please let me know if i can follow any example or any link

Thanks in advance.


回答1:


@gaurav

This is great

https://www.npmjs.com/package/ngx-doc-viewer

Cheers!




回答2:


Each format has its own viewer (PDF, IMG, VIDEO). I do not remember any plugin to preview all of them.

What you can do is use the browser itself to show them. Just open the file URL in another tab or in one iframe in the same page.




回答3:


No browsers currently have the code necessary to render Word Documents, and as far as I know, there are no client-side libraries that currently exist for rendering them either

However, if you only need to display the Word Document, but don't need to edit it, you can use Google Documents' Viewer via an to display a remotely hosted .doc/.docx.

You can use HTML's "Object" tag to embed Video, PDF in the page and get it displayed but having excel may not be supported by it.

The tag defines an embedded object within an HTML document. Use this element to embed multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages.
At least one of the "data" or "type" attribute MUST be defined.

When using for pdf or video the data tag will have the binary data of the content and type will provide information about what type of file it is to the browser. If Object is not supported, you can also use old iFrame to get the same work done.

I have not come across a plugin that supports embedding all files especially Excelsheets and word etc in the HTML. You can also in most, if not all browsers, convert the .doc/.docx as a PDF file and render them using PDF.js or use browser's native capability to do so.



来源:https://stackoverflow.com/questions/53287506/how-i-can-preview-filesdocuments-and-images-in-angular-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!