|
|
@@ -2,6 +2,7 @@ package com.goafanti.common.utils.pdf;
|
|
|
|
|
|
import com.goafanti.RD.bo.OutWordRdDetails;
|
|
|
import com.goafanti.common.utils.excel.FileUtils;
|
|
|
+import com.goafanti.expenseAccount.bo.MainExpenseAccount;
|
|
|
import com.itextpdf.text.*;
|
|
|
import com.itextpdf.text.pdf.BaseFont;
|
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
@@ -87,6 +88,11 @@ public class PDFUtils {
|
|
|
return font;
|
|
|
}
|
|
|
|
|
|
+ public static Font getFont(int size){
|
|
|
+ Font font =setFont(size,Font.NORMAL);
|
|
|
+ return font;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -107,4 +113,75 @@ public class PDFUtils {
|
|
|
|
|
|
return font;
|
|
|
}
|
|
|
+
|
|
|
+ public void pushMainExpenseExport(MainExpenseAccount mainExpenseAccount,HttpServletResponse response, String uploadPath) {
|
|
|
+ String title = "报销明细表";
|
|
|
+ String attName = String.format("报销明细表_%s.pdf",new Date().getTime());
|
|
|
+ String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".pdf";
|
|
|
+
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ Document document=new Document();
|
|
|
+ try {
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, title,attName);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(realFileName);
|
|
|
+ PdfWriter.getInstance(document, outputStream);
|
|
|
+ document.open();
|
|
|
+ Paragraph paragraph = new Paragraph(title, getTitleFont());
|
|
|
+ paragraph.setAlignment(1);
|
|
|
+ document.add(paragraph);
|
|
|
+ //默认算60
|
|
|
+ pushExpenseTitle(document,mainExpenseAccount);
|
|
|
+
|
|
|
+ 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 static String CHECKNO="报销编号:";
|
|
|
+ private static String APPLYDEP="申请部门:";
|
|
|
+ private static String ANAME="报销人:";
|
|
|
+ private static String CREATETIME="报销日期:";
|
|
|
+ private static String REMARKS="报销事由:";
|
|
|
+ private static String BANK_ACCOUNT="收款方式:";
|
|
|
+ private void pushExpenseTitle(Document document, MainExpenseAccount mainExpenseAccount) throws DocumentException {
|
|
|
+
|
|
|
+ int x= CHECKNO.length() + mainExpenseAccount.getCheckNo().length()/2 +
|
|
|
+ APPLYDEP.length() + mainExpenseAccount.getApplyDepName().length() +
|
|
|
+ ANAME.length() + mainExpenseAccount.getAname().length();
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ if (x>55){
|
|
|
+ builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append(" ")
|
|
|
+ .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(" ")
|
|
|
+ .append(ANAME).append(mainExpenseAccount.getAname());
|
|
|
+ }else {
|
|
|
+ int y =(60-x);
|
|
|
+ StringBuilder blank= new StringBuilder();
|
|
|
+ for (int i = 0; i < y; i++) {
|
|
|
+ blank.append(" ");
|
|
|
+ }
|
|
|
+ builder.append(CHECKNO).append(mainExpenseAccount.getCheckNo()).append(blank)
|
|
|
+ .append(APPLYDEP).append(mainExpenseAccount.getApplyDepName()).append(blank)
|
|
|
+ .append(ANAME).append(mainExpenseAccount.getAname());
|
|
|
+ }
|
|
|
+ Paragraph tile1=new Paragraph(builder.toString(),getFont(8));
|
|
|
+ document.add(tile1);
|
|
|
+
|
|
|
+
|
|
|
+ String str2=String.format("报销日期:%s 报销事由:%s 收款方式:%s",
|
|
|
+ mainExpenseAccount.getCreateTimeStr(),mainExpenseAccount.getRemarks(),
|
|
|
+ mainExpenseAccount.getBank() + " " + mainExpenseAccount.getAccounts() + " " +
|
|
|
+ mainExpenseAccount.getName());
|
|
|
+ Paragraph tile2=new Paragraph(str2,getFont(8));
|
|
|
+ tile2.setAlignment(1);
|
|
|
+ document.add(tile2);
|
|
|
+ }
|
|
|
+
|
|
|
}
|