Setup GroupDocs Viewer in Coldfusion Environment

I have the demo version of both comparison and the viewer programs. Trying to start simple by viewing a word doc. In my attempt to get this to work I have been bouncing back and forth between the java version and the .net version of your Viewer Product in the vain attempt to view word docs in my browser.

I have not been able use the Jar files or the dlls. All the examples I have found use Frameworks like Visual Studios or Eclipse (both of which I have never used.)

Can someone work with me on setting a simple view of a word doc using either the Java or .net versions of the viewer. Coldfusion should be able to handle both.

thanks

@jfgill1,

Thanks for taking interest in GroupDocs APIs.

Please note that all the APIs at GroupDocs are back-end APIs that provide the wide range of features for document manipulation. The APIs do not provide any built-in UI or control that can be embedded in your front end application. You can easily use any Java or .NET API in your ColdFusion application by including the API’s JAR or DLL.

GroupDocs.Viewer provides the feature of rendering the document pages in the form that can be displayed easily in your front end application. The API provides the following modes to render a document.

  • Html based rendering: In Html based rendering, the API generates the Html representation of each page of the source document. You can easily manipulate the Html content of each page as a string. You can either embed the HTML content directly in your application or save it as an HTML file and display it in the browser.
  • Image-based rendering: In image-based rendering, the API converts each page of the document into an image (PNG, JPG, BMP). You can easily save the image to your desired location and display it in your application to view the content of the document.

Following code snippet shows how to get HTML representation of a Word document using GroupDocs.Viewer for Java in ColdFusion.

<cfscript> 
    viewerConfig = createObject("java", "com.groupdocs.viewer.config.ViewerConfig"); 
    viewerConfig.setStoragePath("D:\Storage\");
    viewerConfig.setCachePath("D:\Storage\cache");
    viewerConfig.setUseCache(true);
    
    HtmlOptions = createObject("java", "com.groupdocs.viewer.converter.options.HtmlOptions"); 
    HtmlOptions.setResourcesEmbedded(true); 

    ViewerHandler = createObject("java", "com.groupdocs.viewer.handler.ViewerHtmlHandler").init(viewerConfig); 
    
    list = CreateObject( "java", "java.util.ArrayList" ).Init();
   
    list = ViewerHandler.getPages("calibre.docx", HtmlOptions);

    // getPages retuns list of the PageHtml. You can loop through the list to get HTML content of each page of the document and save it as HTML file or display it in the web page (as shown below using cfoutput tag).
</cfscript>
<cfoutput>
<cfloop from="1" to="#arraylen(list)#" index="x">
#list[x].HtmlContent#<br/>
</cfloop>
</cfoutput>

Please make sure that GroupDocs.Viewer.jar file is placed in …\WEB-INF\lib\ folder.

You can also explore more about GroupDocs.Viewer API by referring to the following documentation.

Thank you for the quick response. I was way off on what I was trying to do. Loaded the code and got the following error. Not sure where i need to start in troubleshooting. Here is the error i got. Looks like the list is empty. The file I am pulling is a one page word doc. very basic word doc. Any thoughts? thanks again for all the help.

java.lang.NullPointerException

The error occurred in C:/inetpub/wwwroot/comparedoc/index_java.cfm: line 26
24 : list = CreateObject( “java”, “java.util.ArrayList” ).Init();
25 :
26 : list = ViewerHandler.getPages("#source#", HtmlOptions);
27 :
28 : // getPages retuns list of the PageHtml. You can loop through the list to get HTML content of each page of the document and save it as HTML file or display it in the web page (as shown below using cfoutput tag).

@jfgill1,

Thanks for your response.

Would you please share with us the complete source code you are using to render the document?

In my playing around with the code I can view images and pdfs but word and text files i get the error. thanks

viewerConfig = createObject("java", "com.groupdocs.viewer.config.ViewerConfig"); viewerConfig.setStoragePath("C:\inetpub\wwwroot\compareDoc"); viewerConfig.setCachePath("C:\inetpub\wwwroot\compareDoc\cache"); viewerConfig.setUseCache(true);
HtmlOptions = createObject("java", "com.groupdocs.viewer.converter.options.HtmlOptions"); 
HtmlOptions.setResourcesEmbedded(true); 

ViewerHandler = createObject("java", "com.groupdocs.viewer.handler.ViewerHtmlHandler").init(viewerConfig); 

list = CreateObject( "java", "java.util.ArrayList" ).Init();
list = ViewerHandler.getPages("xrayallowance.docx", HtmlOptions);
writedump(list);
// getPages retuns list of the PageHtml. You can loop through the list to get HTML content of each page of the document and save it as HTML file or display it in the web page (as shown below using cfoutput tag).
#list[x].HtmlContent#

@jfgill1,

Thanks for sharing with us the source code.

We have tested your provided code at our end and the Word and text documents are rendering without any issue. Please make sure that source document (i.e. xrayallowance.docx) is located in C:\inetpub\wwwroot\compareDoc\ folder and the file name that you are using in the getPages method is correct. If the issue persists, please share with us the problematic Word and text documents as well as the version of GroupDocs.Viewer for Java you are using.

Hi thanks for the response. We did check the the path and file name. Cause when I viewed a pdf or image the code worked. Path is C:\inetpub\wwwroot\compareDoc

Attached are the files I tried to open and my code.:
Testfiles.zip (21.5 KB)

The version i am using is GroupDocs.Viewer_17.5.0-Java . I just downloaded the file from your site as an evaluation of the software. I am trying to build a proof of concept for my boss. We want to build a document comparison tool. My first attempt is just to view the files.

thanks

@jfgill1,

Thanks for providing the required details.

We used your provided index_java.cfm file at our end and experienced the exception that you have reported earlier (see screenshot). However, we noticed that the Word document you are rendering has docx extension whereas you are using doc in the code (see this). After using docx extension in the code, the document was rendered without any issue (see output). Please check the same at your end and share with us the outcomes.