package ru.cpro.uchteno.util; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.artofsolving.jodconverter.OfficeDocumentConverter; import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration; import org.artofsolving.jodconverter.office.OfficeConnectionProtocol; import org.artofsolving.jodconverter.office.OfficeManager; public class Libre {// public static void doc2html(InputStream is, OutputStream os) {// doc html try { File inf = File.createTempFile("doc", ".doc"); // FileOutputStream infos = new FileOutputStream(inf); // // int n = 0; byte buff[] = new byte[1024]; while (n >= 0) { n = is.read(buff); if (n > 0) { infos.write(buff, 0, n); } } // is.close(); infos.close(); // File onf = File.createTempFile("doc", ".html"); // jodconverter' ExternalOfficeManagerConfiguration officeConfiguration = new ExternalOfficeManagerConfiguration(); // tcp officeConfiguration .setConnectionProtocol(OfficeConnectionProtocol.SOCKET); // officeConfiguration.setPortNumber(2002); // officeManager OfficeManager officeManager = officeConfiguration .buildOfficeManager(); // officeManager.start(); // OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager); // converter.convert(inf, onf); // officeManager.stop(); // FileInputStream outfis = new FileInputStream(onf); n = 0; while (n >= 0) { n = outfis.read(buff); if (n > 0) { os.write(buff, 0, n); } } // outfis.close(); os.close(); // inf.delete(); onf.delete(); } catch (IOException ex) { Logger.getLogger(Libre.class.getName()).log(Level.SEVERE, null, ex); } } public static void doc2pdf(InputStream is, OutputStream os) { try { File inf = File.createTempFile("doc", ".doc"); FileOutputStream infos = new FileOutputStream(inf); int n = 0; byte buff[] = new byte[1024]; while (n >= 0) { n = is.read(buff); if (n > 0) { infos.write(buff, 0, n); } } is.close(); infos.close(); File onf = File.createTempFile("doc", ".pdf"); ExternalOfficeManagerConfiguration officeConfiguration = new ExternalOfficeManagerConfiguration(); officeConfiguration .setConnectionProtocol(OfficeConnectionProtocol.SOCKET); officeConfiguration.setPortNumber(2002); OfficeManager officeManager = officeConfiguration .buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager); converter.convert(inf, onf); officeManager.stop(); FileInputStream outfis = new FileInputStream(onf); n = 0; while (n >= 0) { n = outfis.read(buff); if (n > 0) { os.write(buff, 0, n); } } outfis.close(); os.close(); inf.delete(); onf.delete(); } catch (IOException ex) { Logger.getLogger(Libre.class.getName()).log(Level.SEVERE, null, ex); } } public static void html2doc(InputStream is, OutputStream os) { try { File inf = File.createTempFile("doc", ".html"); FileOutputStream infos = new FileOutputStream(inf); int n = 0; byte buff[] = new byte[1024]; while (n >= 0) { n = is.read(buff); if (n > 0) { infos.write(buff, 0, n); } } is.close(); infos.close(); File onf = File.createTempFile("doc", ".doc"); ExternalOfficeManagerConfiguration officeConfiguration = new ExternalOfficeManagerConfiguration(); officeConfiguration .setConnectionProtocol(OfficeConnectionProtocol.SOCKET); officeConfiguration.setPortNumber(2002); OfficeManager officeManager = officeConfiguration .buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager); converter.convert(inf, onf); officeManager.stop(); FileInputStream outfis = new FileInputStream(onf); n = 0; while (n >= 0) { n = outfis.read(buff); if (n > 0) { os.write(buff, 0, n); } } outfis.close(); os.close(); inf.delete(); onf.delete(); } catch (IOException ex) { Logger.getLogger(Libre.class.getName()).log(Level.SEVERE, null, ex); } } public static void html2docx(InputStream is, OutputStream os) { try { File inf = File.createTempFile("doc", ".html"); FileOutputStream infos = new FileOutputStream(inf); int n = 0; byte buff[] = new byte[1024]; while (n >= 0) { n = is.read(buff); if (n > 0) { infos.write(buff, 0, n); } } is.close(); infos.close(); File onf = File.createTempFile("doc", ".docx"); ExternalOfficeManagerConfiguration officeConfiguration = new ExternalOfficeManagerConfiguration(); officeConfiguration .setConnectionProtocol(OfficeConnectionProtocol.SOCKET); officeConfiguration.setPortNumber(2002); OfficeManager officeManager = officeConfiguration .buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager); converter.convert(inf, onf); officeManager.stop(); FileInputStream outfis = new FileInputStream(onf); n = 0; while (n >= 0) { n = outfis.read(buff); if (n > 0) { os.write(buff, 0, n); } } outfis.close(); os.close(); inf.delete(); onf.delete(); } catch (IOException ex) { Logger.getLogger(Libre.class.getName()).log(Level.SEVERE, null, ex); } } public static void html2pdf(InputStream is, OutputStream os) { try { File inf = File.createTempFile("doc", ".html"); FileOutputStream infos = new FileOutputStream(inf); int n = 0; byte buff[] = new byte[1024]; while (n >= 0) { n = is.read(buff); if (n > 0) { infos.write(buff, 0, n); } } is.close(); infos.close(); File onf = File.createTempFile("doc", ".pdf"); ExternalOfficeManagerConfiguration officeConfiguration = new ExternalOfficeManagerConfiguration(); officeConfiguration .setConnectionProtocol(OfficeConnectionProtocol.SOCKET); officeConfiguration.setPortNumber(2002); OfficeManager officeManager = officeConfiguration .buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager); converter.convert(inf, onf); officeManager.stop(); FileInputStream outfis = new FileInputStream(onf); n = 0; while (n >= 0) { n = outfis.read(buff); if (n > 0) { os.write(buff, 0, n); } } outfis.close(); os.close(); inf.delete(); onf.delete(); } catch (IOException ex) { Logger.getLogger(Libre.class.getName()).log(Level.SEVERE, null, ex); } } }
tinymce.init({ selector: "textarea", theme: "modern", fullpage_default_doctype: "<!DOCTYPE xhtml>", plugins: [ "advlist autolink lists link image charmap print preview hr anchor pagebreak", "searchreplace wordcount visualblocks visualchars code fullscreen", "insertdatetime media nonbreaking save table contextmenu directionality", "emoticons template paste textcolor fullpage" ], toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image", toolbar2: "print preview media | forecolor backcolor emoticons", image_advtab: true });
tinyMCE.triggerSave();
Libre.java
library:html2doc()
html2docx()
html2pdf()
Source: https://habr.com/ru/post/224795/
All Articles