How to display in viewer

Hello,

I am using the in-premise api. How do I use the viewer as for now it only save the html to a local file. I want to view it in the viewer in the browser. Also the local output file only give 2 links for first 2 pages for my pdf file.

Thank you

@danishPersys

Please check How to integrate GroupDocs.Viewer in ASP.NET Core Web app documentation article or download this sample-app.zip (3.7 MB). You can run this app by typing dotnet run and navigating to https://localhost:7104/viewer in your browser.

This is trial limitation, learn more at Licensing | Documentation

You can request a temporary license at Temporary License - Purchase - groupdocs.com

Hello Vladimir,

Thank you for the response. Now I understand how it works but is there any guide for Java spring because it will be very helpful since I am trying to integrate it into a java spring project which I am trying to generate a link so it will display the file in GroupDocs viewer

@danishPersys

Check our Spring demo project which is using the same Angular UI. Please let us know if it what you’re looking for.

Thank you this is what am I looking for but for this program I have to upload it manually. Is there any function that can help me to fetch file from storage and display it in the viewer? As I already tried to use this coding in the Application.java but it is not showing in localhost:8080/viewer.

Viewer viewer = new Viewer(“sample.docx”);
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources(“page_{0}.html”);
viewOptions.setRenderResponsive(true);
viewer.view(viewOptions);
viewer.close();

@danishPersys

This code snippet will convert sample.docx file to the HTML and place the output in the current directory. The complete solution Spring demo includes a client application and backend API, so it’s much more moving parts there.

I see. So is there a way to make viewer open document from location without uploading it manually? If so, which function should I use to display it?

@danishPersys

In case you’re going to use our Spring Demo you can pass url= query string parameter, file will be downloaded and opened automatically, e.g. https://localhost:7104/viewer?url=https://cms.admin.containerize.com/templates/groupdocs/img/svg/groupdocs-logo.svg see

This works great! May I know which class that I can edit to append the url to the viewer?

@danishPersys

Can you please clarify what behavior you do expect, since adding url parameter should be done at the client code?

What I am expecting is to read a byte array and I want to display it in the viewer. What I am getting now is it just save it on local file and when I open the files they are not displayed in the viewer. I want it to be displayed like the first picture instead of the second picture.
First Picture:
ss28.PNG (87.9 KB)
Second Picture:
ss27.PNG (151.2 KB)

@danishPersys

Let’s sum up, you’re looking for a Spring application that accepts a path to a file or some file identified and displays it in a browser, is it correct?

Yes that is what I am looking for but I don’t know which class to edit to display the files in the browser

@danishPersys

Thank you for the clarification. Please check this spring-boot-sample-app.zip (3.8 MB). It can be started the app with mvn spring-boot:run. After the app is started try pasting http://localhost:8080/?filename=sample.docx&page=1 into a browser address bar to view the first page of sample.docx file that is placed in the storage folder. All the code is located in HelloController.java and MemoryPageStreamFactory.java files.

The solution is great! May I ask further if it is possible if I just want to render the file with the viewer header ? As for now it only shows the physical file without the option to navigate to page or download. I want to render the file and the top navigator shows like in the picture below.

ss40.PNG (266.9 KB)

@danishPersys

Sure, please check this sample application. You can run it by extracting the archive and typing mvn clean spring-boot:run. In case you want to view a file you can pass file query string parameter see

.

Amazing ! Thank you for the quick and superb response. Do you mind to explain which class and function does the ?file= comes from? Just wondering because I am excited to explore and play around with the codes.

@danishPersys

You’re welcome! The file query string parameter is being read by the Angular UI and passed to the server. Angular UI is located in client folder. This is sample Angular application that is referencing @groupdocs.examples.angular/viewer Angular component. The source code for it can be found at GitHub in our public repository GroupDocs.Total-Angular. The code that is reading file query string parameter can be found here.

1 Like

Thanks for the great explanation and quick response!

@danishPersys

You’re welcome!