简体   繁体   English

Office文档到HTML转换以使用JavaScript在浏览器中查看

[英]Office docs to HTML conversion to view in browser using JavaScript

We are working on AngularJS application. 我们正在开发AngularJS应用程序。 The requirement is to show documents in new tab in HTML format. 要求是以HTML格式在新标签中显示文档。 Thus we are implementing one converter that basically will convert office documents (doc, docx and odt) into HTML viewer. 因此,我们正在实现一个转换器,该转换器基本上将Office文档(doc,docx和odt)转换为HTML查看器。 We have implemented converter using Apache POI . 我们已经使用Apache POI实现了转换器。 We have written three converter to convert doc, docx and odt into HTML. 我们编写了三个转换器,将doc,docx和odt转换为HTML。

PROBLEM 问题

Text conversion working fine, but the problem arise when the doc contain any image. 文本转换工作正常,但是当文档包含任何图像时会出现问题。 So the converter extract image by downloading image on my local system, reference code : 因此,转换器通过在我的本地系统上下载图像来提取图像, 参考代码

protected void doGenerateHTMLFile( String fileInName )
        throws IOException
    {

        String root = "target";
        String fileOutName = root + "/" + fileInName + ".html";

        long startTime = System.currentTimeMillis();

        XWPFDocument document = new XWPFDocument( AbstractXWPFPOIConverterTest.class.getResourceAsStream( fileInName ) );

        XHTMLOptions options = XHTMLOptions.create();// .indent( 4 );
        // Extract image
        File imageFolder = new File( root + "/images/" + fileInName );
        options.setExtractor( new FileImageExtractor( imageFolder ) );
        // URI resolver
        options.URIResolver( new FileURIResolver( imageFolder ) );

        OutputStream out = new FileOutputStream( new File( fileOutName ) );
        XHTMLConverter.getInstance().convert( document, out, options );

    }

Now next task is to show the converted doc into HTML (it include local file system path for containing image) will not show the image as JS : 现在的下一个任务是将转换后的文档显示为HTML(它包含用于包含图像的本地文件系统路径),而不会将图像显示为JS:

 Not allowed to load local resource: file:///C:/Users/admin/M_Test/image/image1.JPG

UPDATE UPDATE

I have changed the path of images to my website path as : http:\\localhost:111\\temp\\ebe6a869-3df7-4ef4-b798-5ed323e4090f\\images\\myimage/wor‌​d/media/image1.JPG at options.URIResolver(new FileURIResolver(new File(sLocalHostImagePath))); 我已将图像路径更改为我的网站路径:http:// \\ localhost:111 \\ temp \\ ebe6a869-3df7-4ef4-b798-5ed323e4090f \\ images \\ myimage / wor‌d / media / image1.JPG在options.URIResolver(new FileURIResolver(new File(sLocalHostImagePath)));

But on conversion it appending the path of my project like : C:\\MY_DRIVE\\PROJECTS\\OutSource\\svn\\IAP-Dynamic-Sql\\http:\\localhost:111\\temp\\ebe6‌​a869-3df7-4ef4-b798-5ed323e4090f\\images\\myimage/word/media/image1.JPG , 但是在转换时,它会附加我项目的路径,例如: C:\\ MY_DRIVE \\ PROJECTS \\ OutSource \\ svn \\ IAP-Dynamic-Sql \\ http:\\ localhost:111 \\ temp \\ ebe6‌a869-3df7-4ef4-b798-5ed323e4090f \\ images \\ myimage / word / media / image1.JPG

how it can only be my localhost path? 怎么只能是我的本地主机路径?

Thus in all we are not able to load doc into well format in new tab. 因此,总而言之,我们无法在新标签页中将文档加载为格式正确的文件。

Is this a correct approach to convert doc into HTML or any better approach can be adopted? 这是将文档转换为HTML的正确方法,还是可以采用任何更好的方法?

Instead of writing custom code to covert these, you might want to make use of mammoth JS library.Might be 4 years too late, it seems :) but anyways its a library for displaying doc, docx documents by converting them to html on the browser side as well as can be handled on the backend. 与其编写自定义代码来掩盖这些内容,不如使用猛mm的JS库,这似乎为时已晚4年:),但无论如何它都是一个用于在浏览器上将它们转换为html来显示doc,docx文档的库以及可以在后端处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 IntelliJ 中,如何使用 Shift + F1 在浏览器中查看生成的文档 - In IntelliJ, how can I view the generated docs in the browser, using Shift + F1 使用iText将HTML转换为PDF - HTML to PDF conversion using iText Android Office Word(.doc / .docx)到(image / html / xml / pdf)转换中是否有任何Api - Is there any Api in android for ms office word(.doc/.docx) to (image/html/xml/pdf) conversion 将 VBA 脚本添加到 Office Word 文档 - Add VBA script to Office Word docs 如何使用Spring MVC从Java中的控制器而不是通过Web浏览器请求HTML视图? - How Do I Request an HTML View from a Controller in Java and not through a Web Browser using Spring MVC? 如何使用 Spring MVC 和 jsp java javascript 在浏览器中查看 excel 文件? - how to view excel file in browser using Spring MVC and jsp java javascript? 如何在不使用JavaScript的情况下将Edraw Office Viewer组件与zk集成? - How to integrate Edraw Office Viewer Component with zk without using javascript? 如何显示不同大小的单词,例如Office或Android中的Google文档功能 - How to display words of different sizes, such as Office or function of Google Docs in Android 如何使用jsp在浏览器中查看excel文件 - how to view excel file in browser using jsp 在没有HTML,没有浏览器且没有Appletviewer的情况下查看Java Applet? - View Java Applet without html and without browser and without Appletviewer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM