最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用openoffice+jodconverter-code-3.0-bate4實現(xiàn)ppt轉(zhuǎn)圖片

 更新時間:2019年07月25日 10:18:30   作者:kenhins  
這篇文章主要為大家詳細(xì)介紹了利用openoffice+jodconverter-code-3.0-bate4實現(xiàn)ppt轉(zhuǎn)圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了openoffice+jodconverter-code-3.0-bate4實現(xiàn)ppt轉(zhuǎn)圖片的具體代碼,供大家參考,具體內(nèi)容如下

安裝openoffice4  (用于把文檔(ppt)轉(zhuǎn)成pdf)根據(jù)系統(tǒng)的位數(shù)安裝
使用jodconverter-core3.0-beta-4(要上傳maven本地倉庫)
安裝ImageMagick:yum install ImageMagick(用于pdf轉(zhuǎn)圖片)
安裝pdftotext  用于提取文字大綱  yum install poppler-utils
perl腳本(用于提取pdf文檔的文字大綱)

使用jodconverter調(diào)用OpenOffice 將office文檔轉(zhuǎn)換為PDF時。如果轉(zhuǎn)換程序異常中止而OpenOffice并沒有停止運行的話。

openoffice

1、啟動tomcat時,啟動openoffice服務(wù)(個人感覺有風(fēng)險問題)

2、手工用命令,啟動openoffice服務(wù),在使用鏈接服務(wù)(推薦)

package com.document.servers.impl;
 
import java.io.File;
import java.net.ConnectException;
 
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
 
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
 
 
 
//import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
//import com.artofsolving.jodconverter.DocumentConverter;
//import com.artofsolving.jodconverter.DocumentFamily;
//import com.artofsolving.jodconverter.DocumentFormat;
//import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
//import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
//import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import com.document.servers.OfficeService;
 
/**
 * linux下:
 * cd /opt/openoffice4/program 
 * ./soffice "-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" -nologo -headless -nofirststartwizard &
 */
@Service("officeService")
public class OfficeServiceImpl implements OfficeService {
 
  private static final Logger logger = LoggerFactory.getLogger(OfficeServiceImpl.class);
 
  private OfficeManager officeManager;
  private OfficeDocumentConverter documentConverter;
 
//  @PostConstruct
//  public void init() throws Exception {
//    // TODO Auto-generated method stub
//    officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome("/opt/openoffice4").buildOfficeManager();
//
//    documentConverter = new OfficeDocumentConverter(officeManager);
//    // officeManager.stop();
//
//    logger.warn("openoffice starting....");
//    try {
//      officeManager.start();
//      logger.warn("openoffice started");
//    } catch (Exception e) {
//      logger.error("office start failed:{}", e);
//    }
//  }
//
//  @PreDestroy
//  public void destroy() throws Exception {
//    // TODO Auto-generated method stub
//    logger.info("shutdown office service....");
//    if (officeManager != null) {
//      try {
//        
//        officeManager.stop();
//        logger.info("office closed");
//      } catch (Exception e) {
//        logger.error("office close failed:{}", e);
//      }
//    }
//  }
 
//  public void convert(String inputfilename, String outputfilename) {
//    logger.info("convert...." + inputfilename + " to " + outputfilename);
//    documentConverter.convert(new File(inputfilename), new File(outputfilename));
//  }
  
  
  public void manualConvert(String inputfilename, String outputfilename) {
    logger.info("convert...." + inputfilename + " to " + outputfilename);
    // connect to an OpenOffice.org instance running on port 8100 
    ExternalOfficeManagerConfiguration externalProcessOfficeManager = new 
        ExternalOfficeManagerConfiguration(); 
    externalProcessOfficeManager.setConnectOnStart(true); 
    externalProcessOfficeManager.setPortNumber(8100); 
    officeManager = externalProcessOfficeManager.buildOfficeManager(); 
    officeManager.start(); 
    logger.info("openoffice服務(wù)已鏈接");
    documentConverter = new OfficeDocumentConverter(officeManager);
    documentConverter.convert(new File(inputfilename), new File(outputfilename));
  }
  
 
 
}

轉(zhuǎn)換處理方法

package com.document.servers.impl;
 
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.pdfbox.pdmodel.PDDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.document.defined.model.ImagePPT;
import com.document.servers.OfficeService;
import com.document.servers.PPTConvertServers;
import com.document.tool.ImageMagickUtils;
import com.document.tool.SystemConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ppt.util.Command;
 
@Service("pPTConvertServers")
public class PPTConvertServersImpl implements PPTConvertServers {
 
  private static final Logger logger = LoggerFactory.getLogger(PPTConvertServersImpl.class);
 
  @Autowired
  private OfficeService officeService;
 
  /**
   * (non-Javadoc)
   * 利用openoffice把ppt轉(zhuǎn)圖片
   */
  public Map<String, Object> deal_ppt(HttpServletRequest request, String filePath, String extension, String title, String filename)
      throws Exception {
 
    logger.info("ppt轉(zhuǎn)pdf,{}");
 
    // ppt文件地址
    String ppt_target_file = filePath;
 
    // pdf文件地址
    String path = filePath.substring(0, filePath.lastIndexOf("."));
    String pdf_target_file = path + ".pdf";
    // 輸出jpg文件地址
    String images_target_file = path + "/jpg" + "-%d.jpg";
 
    // if(exists(pdf_target_file)){
    // unlink(pdf_target_file);//刪除
    // }
    // copy(new File(ppt_target_file), ppt_target_file, true);
 
    if (!extension.equals(".pdf")) {
      officeService.manualConvert(ppt_target_file, pdf_target_file);// 轉(zhuǎn)成pdf文件
    }
 
    StringWriter writer = new StringWriter();
 
    // 提取文字大綱
    String[] pdf_lines = extractOutLineFromPDF(pdf_target_file);
 
    File filepath = new File(images_target_file);
    File parentFile = filepath.getParentFile();
    if (!parentFile.exists()) {
      logger.info("創(chuàng)建圖片目錄");
      parentFile.mkdirs();
    }
 
    Command.run("convert " + pdf_target_file + " " + images_target_file, writer);// 轉(zhuǎn)成圖片
 
    String basePath = request.getScheme() + "://" + request.getServerName() + "/";
    PDDocument document = PDDocument.load(new File(pdf_target_file));
    int pageCount = document.getNumberOfPages();
    document.close();
 
    List<ImagePPT> list = new ArrayList<ImagePPT>();
    String pathUrl = filename.substring(0, filename.lastIndexOf("."));
    if (pageCount > 0) {
      for (int i = 0; i < pageCount; i++) {
        ImagePPT imagePPT = new ImagePPT();
        imagePPT.setId(i + 1);
        if (pdf_lines.length > 0) {
          try {
            imagePPT.setTitle(pdf_lines[i]);
          } catch (Exception e) {
            // TODO Auto-generated catch block
            imagePPT.setTitle(title);
            logger.info("title,數(shù)組越界");
            //e.printStackTrace();
          }
        } else {
          imagePPT.setTitle(title);
        }
        imagePPT.setUrl(basePath + "images/" + pathUrl + "/jpg-" + i + ".jpg");
        imagePPT.setPreviewUrl(basePath + "preview/images/" + pathUrl + "/preview/pjpg-" + i + ".jpg");
 
//        String oimgDir = SystemConfig.getBlobDirectory() + pathUrl + "/jpg-" + i + ".jpg";
//        String pimgDir = SystemConfig.getBlobDirectory() + pathUrl + "/preview/pjpg-" + i + ".jpg";
//        File pfilepath = new File(pimgDir);
//        File pf = pfilepath.getParentFile();
//        if (!pf.exists()) {
//          pf.mkdirs();
//        }
        //ImageMagickUtils.scale(oimgDir, pimgDir, 240, 180);//預(yù)覽圖
        list.add(imagePPT);
      }
    }
    // 拼接json字符串
 
    ObjectMapper objectMapper = new ObjectMapper();
    String jsonlist = objectMapper.writeValueAsString(list);
    // logger.info(jsonlist);
    Map<String, Object> map=new HashMap<String, Object>();
    map.put("json", jsonlist.toString());
    map.put("totalPage", pageCount);
    return map;
 
  }
 
  /**
   * 文件已經(jīng)上傳過 ,進(jìn)行替換性轉(zhuǎn)換
   */
  public Map<String, Object> replace_ppt(HttpServletRequest request, String filePath, String extension, String title,
      String filename) throws Exception {
 
    logger.info("替換,ppt轉(zhuǎn)pdf,{}");
 
    // ppt文件地址
    String ppt_target_file = filePath;
 
    // pdf文件地址
    String path = filePath.substring(0, filePath.lastIndexOf("."));
    String pdf_target_file = path + ".pdf";
    // 輸出jpg文件地址
    String images_target_file = path + "/jpg" + "-%d.jpg";
 
    if (!extension.equals(".pdf")) {
      officeService.manualConvert(ppt_target_file, pdf_target_file);// 轉(zhuǎn)成pdf文件
    }
 
    StringWriter writer = new StringWriter();
 
    // 提取文字大綱
    String[] pdf_lines = extractOutLineFromPDF(pdf_target_file);
 
    File filepath = new File(images_target_file);
    File parentFile = filepath.getParentFile();
    if (!parentFile.exists()) {
      logger.info("替換創(chuàng)建圖片目錄");
      parentFile.mkdirs();
    }
    Command.run("convert " + pdf_target_file + " " + images_target_file, writer);// 轉(zhuǎn)成圖片
 
    String basePath = request.getScheme() + "://" + request.getServerName() + "/";
    PDDocument document = PDDocument.load(new File(pdf_target_file));
    int pageCount = document.getNumberOfPages();
    document.close();
 
    List<ImagePPT> list = new ArrayList<ImagePPT>();
    String pathUrl = filename.substring(0, filename.lastIndexOf("."));
    if (pageCount > 0) {
      for (int i = 0; i < pageCount; i++) {
        ImagePPT imagePPT = new ImagePPT();
        imagePPT.setId(i + 1);
        if (pdf_lines.length > 0) {
          try {
            imagePPT.setTitle(pdf_lines[i]);
          } catch (Exception e) {
            // TODO Auto-generated catch block
            imagePPT.setTitle(title);
            logger.info("title,數(shù)組越界");
            // e.printStackTrace();
          }
        } else {
          imagePPT.setTitle(title);
        }
        imagePPT.setUrl(basePath + "images/" + pathUrl + "/jpg-" + i + ".jpg");
        imagePPT.setPreviewUrl(basePath + "preview/images/" + pathUrl + "/preview/pjpg-" + i + ".jpg");
 
//        String oimgDir = SystemConfig.getBlobDirectory() + pathUrl + "/jpg-" + i + ".jpg";
//        String pimgDir = SystemConfig.getBlobDirectory() + pathUrl + "/preview/pjpg-" + i + ".jpg";
//        File pfilepath = new File(pimgDir);
//        File pf = pfilepath.getParentFile();
//        if (!pf.exists()) {
//          pf.mkdirs();
//        }
//        ImageMagickUtils.scale(oimgDir, pimgDir, 240, 180);
        list.add(imagePPT);
      }
    }
    // 拼接json字符串
 
    ObjectMapper objectMapper = new ObjectMapper();
    String jsonlist = objectMapper.writeValueAsString(list);
    // logger.info(jsonlist);
    Map<String, Object> map=new HashMap<String, Object>();
    map.put("json", jsonlist.toString());
    map.put("totalPage", pageCount);
    return map;
 
  }
 
  /**
   * 提取pdf文字大綱
   * @param pdf_file
   * @return
   * @throws UnsupportedEncodingException
   * @throws Exception
   */
  public static String[] extractOutLineFromPDF(String pdf_file) throws UnsupportedEncodingException {
    String svndir = PPTConvertServersImpl.class.getResource("").getPath();
    svndir = svndir.split("WEB-INF")[0];
    svndir = svndir.replaceFirst("file:", "");
    logger.info(svndir);
 
    String command = "/usr/bin/perl " + svndir + "WEB-INF/sh/pdf_outline.pl " + pdf_file;
    logger.info(command);
 
    ByteArrayOutputStream writer = new ByteArrayOutputStream();
 
    Command.run2(command, writer);
    String outline = writer.toString("utf-8");
    logger.info("title pdf,{}", outline);
    String[] items = outline.split("http:///");
 
    return items;
  }
 
  /**
   * 文件是否存在
   * 
   * @param filename
   * @return @throws IOException
   */
  public static boolean exists(String filename) {
    try {
      File file = new File(filename);
      return file.exists();
    } catch (Exception e) {
      return false;
    }
  }
 
  /**
   * 刪除文件
   * 
   * @param filename
   * @return
   */
  public static boolean unlink(String filename) {
    try {
      File file = new File(filename);
      if (file.isFile()) {
        file.delete();
        return true;
      }
      return false;
    } catch (Exception e) {
      return false;
    }
  }
 
  /**
   * 拷貝文件
   * 
   * @param file
   * @param newname
   * @param overwrite
   * @return
   */
  public static boolean copy(File file, String newname, boolean overwrite) {
    try {
      if (!overwrite && new File(newname).exists()) {
        return false;
      }
      FileInputStream input = new FileInputStream(file);
      File dest = new File(newname);
      if (!mkdir(dest.getParent())) {
        return false;
      }
      FileOutputStream output = new FileOutputStream(newname);
      byte[] b = new byte[1024 * 5];
      int len;
      while ((len = input.read(b)) != -1) {
        output.write(b, 0, len);
      }
      output.flush();
      output.close();
      input.close();
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
 
  /**
   * 創(chuàng)建目錄
   * 
   * @param dirname
   * @return
   */
  public static boolean mkdir(String dir) {
    try {
      File file = new File(dir);
      if (!file.exists()) {
        file.mkdirs();
      }
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
}

上傳ppt文件處理類:

package com.document.handle.controller;
 
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
 
import com.document.servers.PPTConvertServers;
import com.document.tool.FilenameUtils;
import com.document.tool.SystemConfig;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
 
@Controller
public class PptToImageController {
 
  private static final Logger logger = LoggerFactory.getLogger(PptToImageController.class);
 
  private static final String TYPE_BLOB = "BLOB";
 
  private static final String CALLBACK = "callback"; // 回調(diào)函數(shù)的參數(shù)名
 
  @Autowired
  private PPTConvertServers pPTConvertServers;
 
  @RequestMapping(value = "/convert/upload")
  public ModelAndView updateFile(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("name", "Hello Word");
    mav.setViewName("/ppt/uploadFile");
    logger.info("/convert/upload");
    return mav;
  }
 
  /**
   * 顯示上傳文件的頁面表單。
   */
  @SuppressWarnings("unchecked")
  private ModelAndView showUploadForm(HttpServletRequest request, String type) {
    // 所有請求參數(shù)
    Map<String, String> params = new HashMap<String, String>();
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String name = paramNames.nextElement();
      String value = request.getParameter(name);
      if (null != value) {
        params.put(name, value);
      }
    }
 
    ModelAndView mav = new ModelAndView();
    mav.setViewName("/upload/" + type.toLowerCase());
    mav.addObject("parameters", params);
    return mav;
  }
 
  /**
   * 保存用戶上傳的文件。
   * @throws UnsupportedEncodingException
   */
  private Map<String, Object> saveUploadedFile(HttpServletRequest request, MultipartFile file, String type) {
 
    // 文件內(nèi)容MD5串,避免文件重復(fù)上傳
    String md5 = null;
    try {
      md5 = DigestUtils.md5Hex(file.getBytes());
      logger.info("文件內(nèi)容MD5串,{}", md5);
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
 
    String originalFilename = file.getOriginalFilename();
 
    String extension = FilenameUtils.getExtension(originalFilename); // 文件擴(kuò)展名
 
    String filename = null;
    if (md5 != null) {
      filename = FilenameUtils.generateFileNameMd5(extension, md5);
    } else {
      filename = FilenameUtils.generateFileName(extension);
    }
    
 
    
    String filenameUrl = null; // 文件訪問的URL
    String absoluteFilename = null; // 文件存儲的絕對路徑
 
    filenameUrl = SystemConfig.getBlobUrl() + filename;
    absoluteFilename = SystemConfig.getBlobDirectory() + filename;
 
    // 檢查是否需要創(chuàng)建目錄
    File filepath = new File(absoluteFilename);
    File parentFile = filepath.getParentFile();
    if (!parentFile.exists()) {
      parentFile.mkdirs();
    }
    
    Map<String, Object> params = new HashMap<String, Object>();
    // 所有請求參數(shù)
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String name = paramNames.nextElement();
      String value = request.getParameter(name);
      if (null != value) {
        params.put(name, value);
      }
    }
    
    String pdftitle = originalFilename.substring(0, originalFilename.lastIndexOf("."));
    params.put("title", pdftitle);
    Map<String, Object> officeMap=new HashMap<String, Object>();
    if (filepath.exists()) {
      // 文件已上傳過,文件進(jìn)行替換
      try {
        officeMap = pPTConvertServers.replace_ppt(request, absoluteFilename, extension, pdftitle, filename);
        params.put("totalPage", officeMap.get("totalPage"));
        params.put("data", officeMap.get("json"));
        params.put("status", "success");
      } catch (Exception e) {
        // TODO Auto-generated catch block
        logger.info("把ppt文件轉(zhuǎn)pdf失敗,{}", e);
        params.put("status", "fail");
        params.put("data", "把ppt文件轉(zhuǎn)pdf失敗");
        params.put("totalPage", 0);
        e.printStackTrace();
      }
      
      return params;
    }
    
    
    // 保存文件
    BufferedOutputStream bos = null;
    try {
      byte[] fileBytes = file.getBytes();
      bos = new BufferedOutputStream(new FileOutputStream(filepath));
      bos.write(fileBytes);
    } catch (IOException e) {
      logger.error("保存'" + originalFilename + "'時發(fā)生異常,Cause: ", e);
    } finally {
      if (null != bos) {
        try {
          bos.close();
        } catch (IOException e) {
        }
      }
    }
 
    // params.put("url", filenameUrl);
    // params.put("originalFilename", originalFilename);
    // params.put("filesize", file.getSize());
 
    // 把ppt文件轉(zhuǎn)pdf,pdf轉(zhuǎn)圖片
    try {
      officeMap = pPTConvertServers.deal_ppt(request, absoluteFilename, extension, pdftitle, filename);
      params.put("totalPage", officeMap.get("totalPage"));
      params.put("data", officeMap.get("json"));
      params.put("status", "success");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      logger.info("把ppt文件轉(zhuǎn)pdf失敗,{}", e);
      params.put("status", "fail");
      params.put("data", "把ppt文件轉(zhuǎn)pdf失敗");
      params.put("totalPage", 0);
      e.printStackTrace();
    }
 
    return params;
  }
 
  /**
   * 處理文件上傳。
   * @throws IOException
   * 
   */
  @RequestMapping(value = "/convert/upload", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  public @ResponseBody String uploadFilePost(HttpServletRequest request,
      @RequestParam("file") MultipartFile file) throws IOException {
 
    String callback = request.getParameter(CALLBACK); // 回調(diào)函數(shù)的函數(shù)名
    String json = "請上傳文件";
    Map<String, Object> params = new HashMap<String, Object>();
 
    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    ObjectWriter writer = mapper.writerWithType(Map.class);
 
    if (!file.isEmpty()) {
      params = saveUploadedFile(request, file, TYPE_BLOB);
      if (params == null) {
        params = new HashMap<String, Object>();
        json = "文件已上傳過";
        params.put("status", "fail");
        params.put("data", json);
        json = writer.writeValueAsString(params);
        return json.toString();
      }
 
      try {
        json = writer.writeValueAsString(params);
        // json = (String) params.get("data");
      } catch (Exception e) {
        logger.error("轉(zhuǎn)換Blob上傳參數(shù)為JSON時發(fā)生異常,Cause: ", e);
      }
 
      if (StringUtils.isBlank(callback)) {
        return json.toString();
      } else {
        return callback + "(" + json.toString() + ");";
      }
 
    }
 
    // 還沒上傳文件的
    params.put("status", "fail");
    params.put("data", json);
    json = writer.writeValueAsString(params);
    return json.toString();
  }
 
}

預(yù)覽圖代理輸出-----處理類:

package com.document.handle.controller;
 
import java.io.File;
import java.io.IOException;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.document.tool.ImageMagickUtils;
import com.document.tool.SystemConfig;
 
 
 
@Controller
public class ImageAgentController {
 
  private static final Logger LOG = LoggerFactory.getLogger(ImageAgentController.class);
  
  /**
   * ppt預(yù)覽圖片代理輸出
   * @throws IOException 
   */
  @RequestMapping("/preview/images/{year}/{month}/{md5id}/{preview}/{filename}.{ext}")
  public void cropImage(@PathVariable String year, @PathVariable String month, @PathVariable String md5id,@PathVariable String preview, @PathVariable String filename, @PathVariable String ext, HttpServletRequest request, HttpServletResponse response) throws IOException {
    //String rootDir = "/data05/ovp/images/";
    String rootDir = SystemConfig.getBlobDirectory();
    String oname = filename.substring(1,filename.length());//原圖文件名
    String dirString = rootDir + year+"/" +month + "/" + md5id + "/"+oname+"." + ext;
    String targetFileString = rootDir + year+"/" +month + "/" + md5id + "/preview/" + filename + "." + ext;
    
    LOG.info("corpImage..." + dirString + " -> " +targetFileString );
    File newfile = new File(targetFileString);
    String pathString = newfile.getParent();
    LOG.info("pathString...{} {}" , pathString);
    File pathFile = new File(pathString);
    if(!pathFile.exists()){
      LOG.info("---create file---");
      pathFile.mkdirs();
    }
    boolean status = ImageMagickUtils.scale(dirString, targetFileString, 240, 180);
    if(status){
      response.reset(); 
      response.setContentType("image/" + ext);
      
      java.io.InputStream in = new java.io.FileInputStream(targetFileString);
      //FilenameUrlUtils.getImageFilename(targetFileString);
      
      if ( in != null )
      {
        byte[] b = new byte[1024]; 
        int len;
        while( (len = in.read(b)) != -1 )
        {
          response.getOutputStream().write(b);   
        }
      
        in.close(); 
      }
    }
  }
  
 
}

提取文字大綱的perl腳本:

use strict;
use warnings;
use utf8;
use open ':encoding(utf8)';
binmode(STDOUT, ":utf8");
sub trim($)
{
    my $string = shift;
    $string =~ s/^\s+//;
    $string =~ s/\s+$//;
    return $string;
}
if(!$ARGV[0]){
 die;
}
open my $fh, "pdftotext -layout -enc UTF-8 $ARGV[0] - |" or die $!;
my $firstline=<$fh>;
print trim($firstline);
my $pageNum = 1;
 
while ( my $line = <$fh> ) {
  if ( $line =~ /\xC/ ) {
    my $count = ($line =~ tr/\xC//);
    for(my $i=0;$i<$count-1;$i++){
        print "http:///".$pageNum;
        $pageNum++;
    }
    if(trim($line)){
        print "http:///".trim($line);
    }
    $pageNum++;
  }
}
close $fh;

可能遇到的問題:

1、ppt轉(zhuǎn)pdf時,遇到啟動失?。ú磺宄遣皇窃俅螁右鸬模?/p>

2、轉(zhuǎn)換后的pdf 表格里的中文會出現(xiàn)亂碼

3、有時會出現(xiàn)關(guān)閉服務(wù)器的所用服務(wù)(尚不清楚什么原因引起的)

4、處理請求時,經(jīng)常出現(xiàn)超時504

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java NIO實現(xiàn)群聊系統(tǒng)

    Java NIO實現(xiàn)群聊系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Java NIO實現(xiàn)群聊系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Java并發(fā)(Runnable+Thread)實現(xiàn)硬盤文件搜索功能

    Java并發(fā)(Runnable+Thread)實現(xiàn)硬盤文件搜索功能

    這篇文章主要介紹了Java并發(fā)(Runnable+Thread)實現(xiàn)硬盤文件搜索,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • RestTemplate發(fā)送HTTP?POST請求使用方法詳解

    RestTemplate發(fā)送HTTP?POST請求使用方法詳解

    這篇文章主要為大家介紹了RestTemplate發(fā)送HTTP?POST請求的使用方法詳解,有需要的朋友可以借鑒參考下希望能夠有所幫助,祝大家多多進(jìn)步
    2022-03-03
  • SpringBoot使用@Scheduled實現(xiàn)定時任務(wù)的并行執(zhí)行

    SpringBoot使用@Scheduled實現(xiàn)定時任務(wù)的并行執(zhí)行

    在SpringBoot中,如果使用@Scheduled注解來定義多個定時任務(wù),默認(rèn)情況下這些任務(wù)將會被安排在一個單線程的調(diào)度器中執(zhí)行,這意味著,這些任務(wù)將會串行執(zhí)行,而不是并行執(zhí)行,本文介紹了SpringBoot使用@Scheduled實現(xiàn)定時任務(wù)的并行執(zhí)行,需要的朋友可以參考下
    2024-06-06
  • SpringMVC?RESTFul實體類創(chuàng)建及環(huán)境搭建

    SpringMVC?RESTFul實體類創(chuàng)建及環(huán)境搭建

    這篇文章主要為大家介紹了SpringMVC?RESTFul實體類創(chuàng)建及環(huán)境搭建詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • RabbitMQ之死信隊列深入解析

    RabbitMQ之死信隊列深入解析

    這篇文章主要介紹了RabbitMQ之死信隊列深入解析,?死信,顧名思義就是無法被消費的消息,字面意思可以這樣理解,一般來說,producer將消息投遞到 broker 或者直接到 queue 里了,consumer 從 queue 取消息進(jìn)行消費,需要的朋友可以參考下
    2023-09-09
  • java中跨域問題解決的幾種方式

    java中跨域問題解決的幾種方式

    這篇文章主要給大家介紹了關(guān)于java中跨域問題解決的幾種方式, 在前后端分離項目中,經(jīng)常會遇到跨域問題,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • java對象強(qiáng)轉(zhuǎn)成object的方法實現(xiàn)

    java對象強(qiáng)轉(zhuǎn)成object的方法實現(xiàn)

    在 Java 編程中,有時候我們需要將一個具體的對象強(qiáng)制轉(zhuǎn)換成 Object 類型,本文主要介紹了java對象強(qiáng)轉(zhuǎn)成object的方法實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-03-03
  • 使用java實現(xiàn)telnet-client工具分享

    使用java實現(xiàn)telnet-client工具分享

    這篇文章主要介紹了使用java實現(xiàn)telnet-client工具,需要的朋友可以參考下
    2014-03-03
  • com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的區(qū)別及設(shè)定serverTimezone的方法

    com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的區(qū)

    這篇文章主要介紹了com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的區(qū)別以及設(shè)定serverTimezone的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09

最新評論

青川县| 五原县| 崇州市| 肇庆市| 阳曲县| 麻栗坡县| 德保县| 长治县| 信宜市| 绥德县| 海门市| 栾川县| 洛扎县| 东丰县| 济宁市| 西乌| 益阳市| 万宁市| 莱阳市| 沾化县| 大庆市| 青冈县| 霸州市| 临西县| 西吉县| 洪雅县| 泗洪县| 卓尼县| 曲水县| 孟州市| 图片| 无棣县| 澳门| 东港市| 富宁县| 绥滨县| 龙海市| 尼玛县| 和平区| 漳浦县| 平湖市|