0

i am looking for a creative solution for a new task. my issue is we need a way to preview local files (extentions: doc, docx, ppt, pptx, pdf, tif, jpeg) in a frame or so of a different web page which provides a link. preview should look like an image of the files or so. we would like to prevent parsing the files to pdf in order to save time...

we are using angular 7, c# asp.net server side. we are very limitted in most solutions, as the data is very secure and is used in an inner office net, that is why we can't use the google docs solution. i also understood that using iframe tag and pointing it src attribute to the file source doesn't load the page due to security resones. in addition all users has the ability to preview the above files types when they do it straight from the document by the open with -> IE or other browsers options.

i tried :

<iframe src="file:///C:/Users/cd/Downloads/MyFile.docx"></iframe>

but: the iframe tag doesn't open the doc file, i can see the iframe in the DOM as a new html but it doesnt have a content of anything i tried also for images and the same, the frame is blank

chaya D
  • 129
  • 1
  • 13
  • 1
    Possible duplicate of [How to open a local disk file with JavaScript?](https://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript) – Vishnudev Krishnadas Jun 02 '19 at 07:56
  • @Vishnudev - no, i tried the examples there and they are displaying the content as text, i want a real preview like an image or so. – chaya D Jun 02 '19 at 10:01
  • What do you wanna do. Please explain the file types you wanna view. There can't be a universal viewer for all file types. – Vishnudev Krishnadas Jun 02 '19 at 10:02
  • Please add output in your console to the question. – Vishnudev Krishnadas Jun 02 '19 at 10:03
  • [Check this please](https://stackoverflow.com/questions/53287506/how-i-can-preview-filesdocuments-and-images-in-angular-6) – Vishnudev Krishnadas Jun 02 '19 at 10:19
  • @Vishnudev - thanks!!! yes, actually i was trying to do like the last link you sent, to put the preview in a iframe, so it will present the file like when i open local files in the web, just in an outer frame – chaya D Jun 02 '19 at 11:00
  • So, you wanna create thumbnails or preview of the file? – Vishnudev Krishnadas Jun 02 '19 at 11:10
  • actually i want to preview, preview i think mean to look at the file content, but not as text, it can be like an image, we prefer it should open like if we do open with but if the only option is to present it as thumbnails so we will do that – chaya D Jun 02 '19 at 12:43

2 Answers2

0

If you are using chrome then chrome specifically blocks local file access this way for security reasons.

more detail is this link : here

mosi98
  • 575
  • 6
  • 16
0

One possible solution is, render the document pages as images and then display them on the web page i.e. using the iframe.

You may use GroupDocs.Viewer for .NET for rendering the document pages into high-fidelity images (PNG/JPG). You can then embed the images into your web page to preview the document. This is how you can get the image representation of the pages in a Word document:

using GroupDocs.Viewer.Options;

// Set output path 
string OutputPagePathFormat = Path.Combine("D:\\output", "page_{0}.png");
// Render document pages
using (Viewer viewer = new Viewer("D:\\sample.docx"))
{
    PngViewOptions options = new PngViewOptions(OutputPagePathFormat);
    viewer.View(options);
    // Rendered images will be saved in the D:\output\ directory.
}

Disclosure: I work as a developer evangelist at GroupDocs.

Usman Aziz
  • 100
  • 3