anderx пре 3 година
родитељ
комит
e824db3198

+ 17 - 0
pom.xml

@@ -407,6 +407,23 @@
 			<artifactId>easyword</artifactId>
 			<version>1.1.5</version>
 		</dependency>
+		<dependency>
+			<groupId>com.lowagie</groupId>
+			<artifactId>itext</artifactId>
+			<version>2.1.7</version>
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
+		<dependency>
+			<groupId>com.itextpdf</groupId>
+			<artifactId>itext-asian</artifactId>
+			<version>5.2.0</version>
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/com.lowagie/itext-rtf -->
+		<dependency>
+			<groupId>com.lowagie</groupId>
+			<artifactId>itext-rtf</artifactId>
+			<version>2.1.7</version>
+		</dependency>
 		<!--pdf-->
 		<dependency>
 			<groupId>com.itextpdf</groupId>

+ 15 - 46
src/main/java/com/goafanti/RD/service/impl/RDServiceImpl.java

@@ -16,6 +16,7 @@ import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
+import com.lowagie.text.rtf.RtfWriter2;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -156,10 +157,12 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
 
     @Override
     public void pushDownloadDetailsWord(Long id, HttpServletResponse response) {
+
         OutRdDetails bo = rdDetailsMapper.details(id);
         //        rdDetailsMapper.updateBrowseOrDownload(id, 1);
         OutWordRdDetails data =new OutWordRdDetails();
         BeanUtils.copyProperties(bo,data);
+//        pushDetailsWord(data,response);
         if (bo.getRdStartStr()!=null&&bo.getRdEndStr()!=null){
             data.setStartEndTime(bo.getRdStartStr()+"~"+bo.getRdEndStr());
         }else {
@@ -173,6 +176,15 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
         }
     }
 
+    private void pushDetailsWord(OutWordRdDetails data, HttpServletResponse response) {
+        String tableName = data.getRdName();
+        String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".doc";
+        String attName = data.getRdName()+new Date().getTime() + ".doc";
+        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        WordUtils wordUtils=new WordUtils();
+        wordUtils.pushWord(data,response,tableName,attName,realFileName);
+    }
+
     @Override
     public void pushDownloadDetailsPDF(Long id, HttpServletResponse response) {
         OutRdDetails bo = rdDetailsMapper.details(id);
@@ -188,52 +200,9 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
         String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
         String attName = data.getRdName()+new Date().getTime() + ".pdf";
         response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
-
-        Document document=new Document();
-        try {
-        FileUtils.setAttachmentResponseHeader(response, tableName,attName);
-            FileOutputStream outputStream = new FileOutputStream(realFileName);
-            PdfWriter writer = PdfWriter.getInstance(document, outputStream);
-            document.open();
-            Paragraph paragraph = new Paragraph(data.getRdName(), PDFUtils.getTitleFont());
-            paragraph.setAlignment(1);
-            document.add(paragraph);
-            addDocument(document,"项目起止时间: ",data.getStartEndTime());
-            addDocument(document,"公司名称: ",data.getUserName());
-            addDocument(document,"项目负责人: ",data.getConsultantName());
-            addDocument(document,"技术领域: ",data.getTechnicalField());
-            addDocument(document,"技术来源: ",data.getTechnologySource());
-            addDocument(document,"研发费用总预计: ",data.getTotalAmount().toEngineeringString()+" 万元");
-            addDocument(document,"研发目的/立项目的/实施方式",null);
-            addContent(document,"        "+data.getRdObjective());
-            addDocument(document,"核心技术/创新点",null);
-            addContent(document,"        "+data.getCoreTechnology());
-            addDocument(document,"成果",null);
-            addContent(document,"        "+data.getAchieveResults());
-            document.close();
-            outputStream.close();
-            FileUtils.writeBytes(realFileName, response.getOutputStream());
-            FileUtils.deleteFile(realFileName);
-        } catch (DocumentException e) {
-            e.printStackTrace();
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+        PDFUtils pdfUtils=new PDFUtils();
+        pdfUtils.pushPDF(data,response,tableName,attName,realFileName);
     }
 
-    private void addDocument(Document document, String key, String value) throws DocumentException {
-        if(key!=null)document.add(new Chunk(key,PDFUtils.getBigFont()));
-        Phrase phrase = new Phrase(value, PDFUtils.getFont());
-        phrase.setLeading(40);
-        if(value!=null)document.add(phrase);
-        document.add(Chunk.NEWLINE);
-    }
-    private void addContent(Document document,  String value) throws DocumentException {
-        Phrase phrase = new Phrase(value, PDFUtils.getFont());
-        phrase.setLeading(25);
-        if(value!=null)document.add(phrase);
-        document.add(Chunk.NEWLINE);
-    }
+
 }

+ 0 - 6
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -787,11 +787,5 @@ public class PublicController extends CertifyApiController {
           }
 
 
-	@RequestMapping("/testPDF")
-	public String testPDF(MultipartFile file) {
-		PDFUtils pdfUtils=new PDFUtils();
-		pdfUtils.loadPDF(file);
-		return "OK";
-	}
 
 }

+ 55 - 10
src/main/java/com/goafanti/common/utils/pdf/PDFUtils.java

@@ -1,31 +1,76 @@
 package com.goafanti.common.utils.pdf;
 
-import com.itextpdf.text.BaseColor;
-import com.itextpdf.text.DocumentException;
+import com.goafanti.RD.bo.OutWordRdDetails;
+import com.goafanti.common.utils.excel.FileUtils;
+import com.itextpdf.text.*;
 import com.itextpdf.text.Font;
 import com.itextpdf.text.pdf.BaseFont;
+import com.itextpdf.text.pdf.PdfWriter;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.awt.*;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 
 public class PDFUtils {
 
 
+    public  void pushPDF(OutWordRdDetails data, HttpServletResponse response,String tableName,String attName,String realFileName) {
 
-
-    public void loadPDF(MultipartFile file){
-
+        Document document=new Document();
         try {
-            PDDocument pdDocument=PDDocument.load(file.getInputStream());
-
+            FileUtils.setAttachmentResponseHeader(response, tableName,attName);
+            FileOutputStream outputStream = new FileOutputStream(realFileName);
+            PdfWriter.getInstance(document, outputStream);
+            document.open();
+            Paragraph paragraph = new Paragraph(data.getRdName(), getTitleFont());
+            paragraph.setAlignment(1);
+            document.add(paragraph);
+            addPDFDocument(document,"项目起止时间: ",data.getStartEndTime());
+            addPDFDocument(document,"公司名称: ",data.getUserName());
+            addPDFDocument(document,"项目负责人: ",data.getConsultantName());
+            addPDFDocument(document,"技术领域: ",data.getTechnicalField());
+            addPDFDocument(document,"技术来源: ",data.getTechnologySource());
+            addPDFDocument(document,"研发费用总预计: ",data.getTotalAmount().toEngineeringString()+" 万元");
+            addPDFDocument(document,"研发目的/立项目的/实施方式",null);
+            addPDFContent(document,"        "+data.getRdObjective());
+            addPDFDocument(document,"核心技术/创新点",null);
+            addPDFContent(document,"        "+data.getCoreTechnology());
+            addPDFDocument(document,"成果",null);
+            addPDFContent(document,"        "+data.getAchieveResults());
+            document.close();
+            outputStream.close();
+            FileUtils.writeBytes(realFileName, response.getOutputStream());
+            FileUtils.deleteFile(realFileName);
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }
+
+    }
+
+    private  void addPDFDocument(Document document, String key, String value) throws DocumentException {
+        if(key!=null) {
+            document.add(new Chunk(key, getBigFont()));
+        }
+        Phrase phrase = new Phrase(value, getFont());
+        phrase.setLeading(40);
+        if(value!=null)document.add(phrase);
+        document.add(Chunk.NEWLINE);
     }
+
+    private void addPDFContent(Document document,  String value) throws DocumentException {
+        Phrase phrase = new Phrase(value, getFont());
+        phrase.setLeading(25);
+        if(value!=null)document.add(phrase);
+        document.add(Chunk.NEWLINE);
+    }
+
+
     public static Font getTitleFont(){
         return setFont(24,Font.BOLD);
     }

+ 85 - 0
src/main/java/com/goafanti/common/utils/word/WordUtils.java

@@ -1,12 +1,17 @@
 package com.goafanti.common.utils.word;
 
 import com.alibaba.fastjson.JSON;
+import com.goafanti.RD.bo.OutWordRdDetails;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.utils.excel.FileUtils;
 
 
+import com.goafanti.common.utils.pdf.PDFUtils;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.BaseFont;
+import com.lowagie.text.rtf.RtfWriter2;
 import com.sushengren.easyword.EasyWord;
 import org.springframework.http.MediaType;
 
@@ -55,4 +60,84 @@ public class WordUtils {
         }
     }
 
+    public void pushWord(OutWordRdDetails data, HttpServletResponse response, String tableName, String attName, String realFileName) {
+        Document document=new Document(PageSize.A4);
+        try {
+            FileUtils.setAttachmentResponseHeader(response, tableName,attName);
+            FileOutputStream outputStream = new FileOutputStream(realFileName);
+            RtfWriter2.getInstance(document,outputStream);
+            document.open();
+            Paragraph paragraph=new Paragraph(data.getRdName(),getTitleFont());
+            paragraph.setAlignment(1);
+            document.add(paragraph);
+            addDocument(document,"项目起止时间: ",data.getStartEndTime());
+            addDocument(document,"公司名称: ",data.getUserName());
+            addDocument(document,"项目负责人: ",data.getConsultantName());
+            addDocument(document,"技术领域: ",data.getTechnicalField());
+            addDocument(document,"技术来源: ",data.getTechnologySource());
+            addDocument(document,"研发费用总预计: ",data.getTotalAmount().toEngineeringString()+" 万元");
+            addDocument(document,"研发目的/立项目的/实施方式",null);
+            addContent(document,"        "+data.getRdObjective());
+            addDocument(document,"核心技术/创新点",null);
+            addContent(document,"        "+data.getCoreTechnology());
+            addDocument(document,"成果",null);
+            addContent(document,"        "+data.getAchieveResults());
+            document.close();
+            outputStream.close();
+            FileUtils.writeBytes(realFileName, response.getOutputStream());
+            FileUtils.deleteFile(realFileName);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void addContent(Document document, String value) throws DocumentException {
+        Phrase phrase = new Phrase(value, getFont());
+        phrase.setLeading(25);
+        if(value!=null)document.add(phrase);
+        document.add(Chunk.NEWLINE);
+    }
+
+    private void addDocument(Document document, String key, String value) throws DocumentException {
+        if(key!=null) {
+            document.add(new Chunk(key, getBigFont()));
+        }
+        Phrase phrase = new Phrase(value, getFont());
+        phrase.setLeading(40);
+        if(value!=null)document.add(phrase);
+        document.add(Chunk.NEWLINE);
+    }
+
+    public Font getTitleFont() {
+        return setFont(24,Font.BOLD);
+    }
+
+    public  Font getBigFont(){
+        return setFont(16, Font.BOLD);
+    }
+
+    public  Font getFont(){
+        Font font =setFont(12, Font.NORMAL);
+        return font;
+    }
+
+    private  Font setFont(int size, int style) {
+        BaseFont baseFont=null;
+        Font font=null;
+        try {
+            baseFont=BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+            font=new Font(baseFont,size,style);
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return font;
+    }
 }