天天看點

itext導出word 帶圖檔

、package com.gaopin.admin.commons.utils;

import java.awt.Color;

import java.io.ByteArrayOutputStream;

import java.io.DataInputStream;

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.math.BigInteger;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;

import org.apache.poi.xwpf.usermodel.ParagraphAlignment;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import org.apache.poi.xwpf.usermodel.XWPFPictureData;

import org.apache.poi.xwpf.usermodel.XWPFRun;

import org.apache.poi.xwpf.usermodel.XWPFTable;

import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import org.apache.xmlbeans.XmlException;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;

import com.baidubce.util.BaiduBosUtils;

import com.gaopin.admin.model.vo.SysPictureVo;

import com.gaopin.admin.model.vo.SysSapVo;

import com.gaopin.admin.service.impl.SysSapServiceImpl;

import com.lowagie.text.BadElementException;

import com.lowagie.text.Cell;

import com.lowagie.text.Document;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Element;

import com.lowagie.text.Font;

import com.lowagie.text.Image;

import com.lowagie.text.PageSize;

import com.lowagie.text.Paragraph;

import com.lowagie.text.Phrase;

import com.lowagie.text.Table;

import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.rtf.RtfWriter2;

public class WordUtils {

private Document document;

private BaseFont bfChinese;

public BaseFont getBfChinese() {
    return bfChinese;
}

public void setBfChinese(BaseFont bfChinese) {
    this.bfChinese = bfChinese;
}

public Document getDocument() {
    return document;
}

public void setDocument(Document document) {
    this.document = document;
}

public WordUtils() {
    this.document = new Document(PageSize.A4);

}

/**
 * @param filePath
 *            建立一個書寫器(Writer)與document對象關聯,通過書寫器(Writer)可以将文檔寫入到磁盤中
 * @throws DocumentException
 * @throws IOException
 */
public void openDocument(String filePath) throws DocumentException, IOException {
    // 建立一個書寫器(Writer)與document對象關聯,通過書寫器(Writer)可以将文檔寫入到磁盤中
    RtfWriter2.getInstance(this.document, new FileOutputStream(filePath));
    this.document.open();
    // 設定中文字型
    // this.bfChinese = BaseFont.createFont("STSongStd-Light",
    // "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
}

/**
 * @param imgUrl
 *            圖檔路徑
 * @param imageAlign
 *            顯示位置
 * @param height
 *            顯示高度
 * @param weight
 *            顯示寬度
 * @param percent
 *            顯示比例
 * @param heightPercent
 *            顯示高度比例
 * @param weightPercent
 *            顯示寬度比例
 * @param rotation
 *            顯示圖檔旋轉角度
 * @throws MalformedURLException
 * @throws IOException
 * @throws DocumentException
 */
public void insertImg(SysSapVo sysSap, String imgUrl, int imageAlign, int height, int weight, int percent,
        int heightPercent, int weightPercent, int rotation)
        throws MalformedURLException, IOException, DocumentException {
    // 添加圖檔

    Image img = Image.getInstance(imgUrl);
    if (img == null)
        return;
    img.setAbsolutePosition(0, 0);
    img.setAlignment(imageAlign);
    img.scaleAbsolute(height, weight);
    img.scalePercent(percent);
    img.scalePercent(heightPercent, weightPercent);
    img.setRotation(rotation);

    Table aTable = new Table(3, 4);
    int width1[] = { 55, 10, 20 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_LEFT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_CENTER);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 8 );
    Cell cellEmailBB = new Cell(new Phrase("", font));
    cellEmailBB.add(img);
    cellEmailBB.setVerticalAlignment(Element.ALIGN_CENTER);
    cellEmailBB.setHorizontalAlignment(Element.ALIGN_LEFT);
           

// cellEmailBB.setBorderWidthTop(0);

cellEmailBB.setRowspan(4);

cellEmailBB.setBorderColor(new Color(0, 0, 0));

cellEmailBB.setBackgroundColor(new Color(255, 255, 255));

aTable.addCell(cellEmailBB);

Cell cellEmailB = new Cell(new Phrase(" 合同編号:", font));
    cellEmailB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setBorderColor(new Color(0, 0, 0));
    cellEmailB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailB);

    Cell cellEmailBs = new Cell(new Phrase(" " + sysSap.getContractId(), font));
    cellEmailBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setBorderColor(new Color(0, 0, 0));
    cellEmailBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailBs);

    Cell cellFaxA = new Cell(new Phrase(" 日期:", font));
    cellFaxA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setBorderColor(new Color(0, 0, 0));
    cellFaxA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxA);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 小寫的mm表示的是分鐘
    Date time = sysSap.getContractDay();
    String day = sdf.format(time);
    Cell cellFaxAs = new Cell(new Phrase(" " + day, font));
    cellFaxAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setBorderColor(new Color(0, 0, 0));
    cellFaxAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxAs);

    Cell cellFaxB = new Cell(new Phrase(" 制單人:", font));
    cellFaxB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxB.setHorizontalAlignment(Element.ALIGN_LEFT);
    // cellFaxB.setBorderWidthTop(0);
    cellFaxB.setBorderColor(new Color(0, 0, 0));
    cellFaxB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxB);

    Cell cellFaxBs = new Cell(new Phrase(" " + sysSap.getMakeUser(), font));
    cellFaxBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    // cellFaxBs.setBorderWidthTop(0);
    cellFaxBs.setBorderColor(new Color(0, 0, 0));
    cellFaxBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxBs);

    Cell cellFaxAA = new Cell(new Phrase(" 郵箱:", font));
    cellFaxAA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxAA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxAA.setBorderColor(new Color(0, 0, 0));
    cellFaxAA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxAA);

    Cell cellFaxAAs = new Cell(new Phrase(" " + sysSap.getMakeUserEmail(), font));
    cellFaxAAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxAAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxAAs.setBorderColor(new Color(0, 0, 0));
    cellFaxAAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxAAs);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * @param titleStr
 *            标題
 * @param fontsize
 *            字型大小
 * @param fontStyle
 *            字型樣式
 * @param elementAlign
 *            對齊方式
 * @throws DocumentException
 */
public void insertTitle(String titleStr, int fontsize, int fontStyle, int elementAlign) throws DocumentException {
    Font titleFont = new Font(this.bfChinese, fontsize, fontStyle);
    Paragraph title = new Paragraph(titleStr);
    // 設定标題格式對齊方式
    title.setAlignment(elementAlign);
    title.setFont(titleFont);

    this.document.add(title);
}

/*
 * 高品内容許可協定
 */
public void insertRiskTable(SysSapVo sysSap) throws DocumentException {
    Table aTable = new Table(4, 7);
    int width1[] = { 10, 40, 10, 40 };
    aTable.setWidth(90); // 占頁面寬度 90%
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setAlignment(Element.ALIGN_CENTER);// 居中顯示
    aTable.setAlignment(Element.ALIGN_CENTER);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font fontChinese = new Font(bfChinese, 9, Font.BOLD);
    Font font = new Font(bfChinese, 10);

    Cell cellCompanyA = new Cell(new Phrase("甲方:", fontChinese));
    cellCompanyA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellCompanyA.setHorizontalAlignment(Element.ALIGN_LEFT);
    // 表格隐藏邊框線
    cellCompanyA.setBorderWidthTop(0);
    cellCompanyA.setBorderColor(new Color(0, 0, 0));
    cellCompanyA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellCompanyA);

    Cell cellCompanyAs = new Cell(new Phrase(sysSap.getCompanyAName(), font));
    cellCompanyAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellCompanyAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    // 表格隐藏邊框線
    cellCompanyAs.setBorderWidthTop(0);
    cellCompanyAs.setBorderColor(new Color(0, 0, 0));
    cellCompanyAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellCompanyAs);

    Cell cellCompanyB = new Cell(new Phrase("乙方:", fontChinese));
    cellCompanyB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellCompanyB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellCompanyB.setBorderWidthTop(0);
    cellCompanyB.setBorderColor(new Color(0, 0, 0));
    cellCompanyB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellCompanyB);

    Cell cellCompanyBs = new Cell(new Phrase("高品(北京)圖像有限公司", font));
    cellCompanyBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellCompanyBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellCompanyBs.setBorderWidthTop(0);
    cellCompanyBs.setBorderColor(new Color(0, 0, 0));
    cellCompanyBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellCompanyBs);

    Cell cellAddressA = new Cell(new Phrase("位址:", fontChinese));
    cellAddressA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellAddressA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellAddressA.setBorderWidthTop(0);
    cellAddressA.setBorderColor(new Color(0, 0, 0));
    cellAddressA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellAddressA);

    Cell cellAddressAs = new Cell(new Phrase(sysSap.getAddressA(), font));
    cellAddressAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellAddressAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellAddressAs.setBorderWidthTop(0);
    cellAddressAs.setBorderColor(new Color(0, 0, 0));
    cellAddressAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellAddressAs);

    Cell cellAddressB = new Cell(new Phrase("位址:", fontChinese));
    cellAddressB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellAddressB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellAddressB.setBorderWidthTop(0);
    cellAddressB.setBorderColor(new Color(0, 0, 0));
    cellAddressB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellAddressB);

    Cell cellAddressBs = new Cell(new Phrase("北京市朝陽區東三環中路 12 号現代柏利大廈1108", font));
    cellAddressBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellAddressBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellAddressBs.setBorderWidthTop(0);
    cellAddressBs.setBorderColor(new Color(0, 0, 0));
    cellAddressBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellAddressBs);

    Cell cellZipA = new Cell(new Phrase("郵編:", fontChinese));
    cellZipA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellZipA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellZipA.setBorderWidthTop(0);
    cellZipA.setBorderColor(new Color(0, 0, 0));
    cellZipA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellZipA);

    Cell cellZipAs = new Cell(new Phrase(sysSap.getZipCodeA(), font));
    cellZipAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellZipAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellZipAs.setBorderWidthTop(0);
    cellZipAs.setBorderColor(new Color(0, 0, 0));
    cellZipAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellZipAs);

    Cell cellZipB = new Cell(new Phrase("郵編:", fontChinese));
    cellZipB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellZipB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellZipB.setBorderWidthTop(0);
    cellZipB.setBorderColor(new Color(0, 0, 0));
    cellZipB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellZipB);

    Cell cellZipBs = new Cell(new Phrase("100022", font));
    cellZipBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellZipBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellZipBs.setBorderWidthTop(0);
    cellZipBs.setBorderColor(new Color(0, 0, 0));
    cellZipBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellZipBs);

    Cell cellUserA = new Cell(new Phrase("聯系人:", fontChinese));
    cellUserA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellUserA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellUserA.setBorderWidthTop(0);
    cellUserA.setBorderColor(new Color(0, 0, 0));
    cellUserA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellUserA);

    Cell cellUserAs = new Cell(new Phrase(sysSap.getPersonAId(), font));
    cellUserAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellUserAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellUserAs.setBorderWidthTop(0);
    cellUserAs.setBorderColor(new Color(0, 0, 0));
    cellUserAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellUserAs);

    Cell cellUserB = new Cell(new Phrase("客戶經理:", fontChinese));
    cellUserB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellUserB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellUserB.setBorderWidthTop(0);
    cellUserB.setBorderColor(new Color(0, 0, 0));
    cellUserB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellUserB);

    Cell cellUserBs = new Cell(new Phrase(sysSap.getMakeUser(), font));
    cellUserBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellUserBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellUserBs.setBorderWidthTop(0);
    cellUserBs.setBorderColor(new Color(0, 0, 0));
    cellUserBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellUserBs);

    Cell cellPhoneA = new Cell(new Phrase("電話:", fontChinese));
    cellPhoneA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellPhoneA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellPhoneA.setBorderWidthTop(0);
    cellPhoneA.setBorderColor(new Color(0, 0, 0));
    cellPhoneA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellPhoneA);

    Cell cellPhoneAs = new Cell(new Phrase(sysSap.getPhoneA(), font));
    cellPhoneAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellPhoneAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellPhoneAs.setBorderWidthTop(0);
    cellPhoneAs.setBorderColor(new Color(0, 0, 0));
    cellPhoneAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellPhoneAs);

    Cell cellPhoneB = new Cell(new Phrase("電話:", fontChinese));
    cellPhoneB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellPhoneB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellPhoneB.setBorderWidthTop(0);
    cellPhoneB.setBorderColor(new Color(0, 0, 0));
    cellPhoneB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellPhoneB);

    Cell cellPhoneBs = new Cell(new Phrase("", font));
    cellPhoneBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellPhoneBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellPhoneBs.setBorderWidthTop(0);
    cellPhoneBs.setBorderColor(new Color(0, 0, 0));
    cellPhoneBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellPhoneBs);

    Cell cellEmailA = new Cell(new Phrase("郵箱:", fontChinese));
    cellEmailA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailA.setBorderWidthTop(0);
    cellEmailA.setBorderColor(new Color(0, 0, 0));
    cellEmailA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailA);

    Cell cellEmailAs = new Cell(new Phrase(sysSap.getEmailA(), font));
    cellEmailAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailAs.setBorderWidthTop(0);
    cellEmailAs.setBorderColor(new Color(0, 0, 0));
    cellEmailAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailAs);

    Cell cellEmailB = new Cell(new Phrase("郵箱:", fontChinese));
    cellEmailB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setBorderWidthTop(0);
    cellEmailB.setBorderColor(new Color(0, 0, 0));
    cellEmailB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailB);

    Cell cellEmailBs = new Cell(new Phrase(sysSap.getMakeUserEmail(), font));
    cellEmailBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setBorderWidthTop(0);
    cellEmailBs.setBorderColor(new Color(0, 0, 0));
    cellEmailBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailBs);

    Cell cellFaxA = new Cell(new Phrase("傳真:", fontChinese));
    cellFaxA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setBorderWidthTop(0);
    cellFaxA.setBorderColor(new Color(0, 0, 0));
    cellFaxA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxA);

    Cell cellFaxAs = new Cell(new Phrase(sysSap.getFax(), font));
    cellFaxAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setBorderWidthTop(0);
    cellFaxAs.setBorderColor(new Color(0, 0, 0));
    cellFaxAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxAs);

    Cell cellFaxB = new Cell(new Phrase("傳真:", fontChinese));
    cellFaxB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxB.setBorderWidthTop(0);
    cellFaxB.setBorderColor(new Color(0, 0, 0));
    cellFaxB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxB);

    Cell cellFaxBs = new Cell(new Phrase("010 - 65008192", font));
    cellFaxBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxBs.setBorderWidthTop(0);
    cellFaxBs.setBorderColor(new Color(0, 0, 0));
    cellFaxBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxBs);
    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/*
 * 高品内容許可協定
 */
public void insertRiskEvaluationTable(SysSapVo sysSap) throws DocumentException {
    Table aTable = new Table(5, 3);
    int width1[] = { 5, 15, 40, 15, 15 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_LEFT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_LEFT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 9);

    Cell cellEmailB = new Cell(new Phrase(" 最終使用者全稱:", font));
    cellEmailB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailB.setColspan(2);
    cellEmailB.setBorderColor(new Color(0, 0, 0));
    cellEmailB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailB);

    Cell cellEmailBs = new Cell(new Phrase(" " + sysSap.getFinalUser(), font));
    cellEmailBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellEmailBs.setColspan(3);
    cellEmailBs.setBorderColor(new Color(0, 0, 0));
    cellEmailBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellEmailBs);

    Cell cellFaxA = new Cell(new Phrase(" 項目名稱:", font));
    cellFaxA.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxA.setColspan(2);
    cellFaxA.setBorderColor(new Color(0, 0, 0));
    cellFaxA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxA);

    Cell cellFaxAs = new Cell(new Phrase(" " + sysSap.getItemName(), font));
    cellFaxAs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxAs.setColspan(3);
    cellFaxAs.setBorderColor(new Color(0, 0, 0));
    cellFaxAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxAs);

    Cell cellFaxB = new Cell(new Phrase(" 工作号/po号:", font));
    cellFaxB.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxB.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxB.setColspan(2);
    cellFaxB.setBorderColor(new Color(0, 0, 0));
    cellFaxB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxB);

    Cell cellFaxBs = new Cell(new Phrase(" " + sysSap.getWorkNumber(), font));
    cellFaxBs.setVerticalAlignment(Element.ALIGN_LEFT);
    cellFaxBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    cellFaxBs.setColspan(3);
    cellFaxBs.setBorderColor(new Color(0, 0, 0));
    cellFaxBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(cellFaxBs);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * RF圖檔
 * 
 * @throws DocumentException
 * @throws IOException 
 */

public void RFTable(SysSapVo sysSap) throws DocumentException, IOException {
    Table aTable = new Table(5, 2);
    int width1[] = { 5, 15, 40, 15, 15 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_LEFT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_MIDDLE);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 9);
    Font blackFont = new Font(bfChinese, 9,Font.BOLD);

    Cell cellCompanyA = new Cell(new Phrase("序号", font));
    cellCompanyA.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyA.setHorizontalAlignment(Element.ALIGN_CENTER);
    // 表格隐藏邊框線
    cellCompanyA.setBorderColor(new Color(0, 0, 0));
    cellCompanyA.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyA);

    Cell cellCompanyAs = new Cell(new Phrase("圖像編号", font));
    cellCompanyAs.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyAs.setHorizontalAlignment(Element.ALIGN_CENTER);
    // 表格隐藏邊框線
    cellCompanyAs.setBorderColor(new Color(0, 0, 0));
    cellCompanyAs.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyAs);

    Cell cellCompanyB = new Cell(new Phrase("圖像資訊", font));
    cellCompanyB.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyB.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellCompanyB.setBorderColor(new Color(0, 0, 0));
    cellCompanyB.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyB);

    Cell cellCompanyBs = new Cell(new Phrase("圖像尺寸", font));
    cellCompanyBs.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyBs.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellCompanyBs.setBorderColor(new Color(0, 0, 0));
    cellCompanyBs.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyBs);

    Cell cellAddressA = new Cell(new Phrase("許可費用(RMB)", font));
    cellAddressA.setVerticalAlignment(Element.ALIGN_CENTER);
    cellAddressA.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellAddressA.setBorderColor(new Color(0, 0, 0));
    cellAddressA.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellAddressA);

    int num = sysSap.getCompanyBId();
    for (int i = 0; i < sysSap.getSysPic().size(); i++) {
        System.out.println(num);
        if ("RF".equals(sysSap.getSysPic().get(i).getLicenseModel())) {

            ++num;
            Cell numRF = new Cell(new Phrase(String.valueOf(num), font));
            numRF.setVerticalAlignment(Element.ALIGN_CENTER);
            numRF.setHorizontalAlignment(Element.ALIGN_CENTER);
            numRF.setBorderColor(new Color(0, 0, 0));
            numRF.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(numRF);


            String imgUrl = sysSap.getPhoneB() + "/"+ sysSap.getSysPic().get(i).getCorbisID() + ".jpg";
            Image img = Image.getInstance(imgUrl);
            if (img == null)
                return;
            img.setAbsolutePosition(0, 0);
            img.setAlignment(Image.ALIGN_CENTER);
            img.scaleAbsolute(9, 9);
            img.scalePercent(9);
            img.scalePercent(9, 9);
            img.setRotation(9);


            Cell corbisIdRf = new Cell(new Phrase(sysSap.getSysPic().get(i).getCorbisID(), blackFont));
            corbisIdRf.add(img);
            corbisIdRf.setVerticalAlignment(Element.ALIGN_CENTER);
            corbisIdRf.setHorizontalAlignment(Element.ALIGN_CENTER);
            corbisIdRf.setBorderColor(new Color(0, 0, 0));
            corbisIdRf.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(corbisIdRf);

            Cell titleRf = new Cell(new Phrase(" " + sysSap.getSysPic().get(i).getTitle() + "\n" + " " + sysSap.getSysPic().get(i).getCustomCreditLine()+ "\n" + "\n" , font));
            titleRf.setVerticalAlignment(Element.ALIGN_LEFT);
            titleRf.setHorizontalAlignment(Element.ALIGN_LEFT);
            titleRf.setBorderColor(new Color(0, 0, 0));
            titleRf.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(titleRf);

            Cell sizeRf = new Cell(new Phrase(sysSap.getSysPic().get(i).getPictureSize(), blackFont));
            sizeRf.setVerticalAlignment(Element.ALIGN_CENTER);
            sizeRf.setHorizontalAlignment(Element.ALIGN_CENTER);
            sizeRf.setBorderColor(new Color(0, 0, 0));
            sizeRf.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(sizeRf);

            Cell moneyRf = new Cell(new Phrase(sysSap.getSysPic().get(i).getPictureMoney(), blackFont));
            moneyRf.setVerticalAlignment(Element.ALIGN_CENTER);
            moneyRf.setHorizontalAlignment(Element.ALIGN_CENTER);
            moneyRf.setBorderColor(new Color(0, 0, 0));
            moneyRf.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(moneyRf);
        }
    }

    document.add(aTable);
    document.add(new Paragraph("\n"));
}
private void condition(String string, String id) {
    // TODO Auto-generated method stub

}

public static byte[] readInputStream(InputStream inputStream) throws IOException {
    byte[] buffer = new byte[1024];
    int len = 0;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    while ((len = inputStream.read(buffer)) != -1) {
        bos.write(buffer, 0, len);
    }
    bos.close();
    return bos.toByteArray();
}
/**
 * RM圖檔
 * 
 * @throws DocumentException
 * @throws IOException 
 * @throws MalformedURLException 
 */

public void RMTable(SysSapVo sysSap) throws DocumentException, MalformedURLException, IOException {
    Table aTable = new Table(5, 3);
    int width1[] = { 5, 15, 40, 15, 15 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_LEFT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_MIDDLE);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 9);
    Font blackFont = new Font(bfChinese, 9,Font.BOLD);

    Cell cellCompanyA = new Cell(new Phrase("序号", font));
    cellCompanyA.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyA.setHorizontalAlignment(Element.ALIGN_CENTER);
    // 表格隐藏邊框線
    cellCompanyA.setBorderColor(new Color(0, 0, 0));
    cellCompanyA.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyA);

    Cell cellCompanyAs = new Cell(new Phrase("圖像編号", font));
    cellCompanyAs.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyAs.setHorizontalAlignment(Element.ALIGN_CENTER);
    // 表格隐藏邊框線
    cellCompanyAs.setBorderColor(new Color(0, 0, 0));
    cellCompanyAs.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyAs);

    Cell cellCompanyB = new Cell(new Phrase("圖像資訊", font));
    cellCompanyB.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyB.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellCompanyB.setBorderColor(new Color(0, 0, 0));
    cellCompanyB.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyB);

    Cell cellCompanyBs = new Cell(new Phrase("圖像尺寸", font));
    cellCompanyBs.setVerticalAlignment(Element.ALIGN_CENTER);
    cellCompanyBs.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellCompanyBs.setBorderColor(new Color(0, 0, 0));
    cellCompanyBs.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellCompanyBs);

    Cell cellAddressA = new Cell(new Phrase("許可費用(RMB)", font));
    cellAddressA.setVerticalAlignment(Element.ALIGN_CENTER);
    cellAddressA.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellAddressA.setBorderColor(new Color(0, 0, 0));
    cellAddressA.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(cellAddressA);

    int num = 0;
    for (int i = 0; i < sysSap.getSysPic().size(); i++) {
        if ("RM".equals(sysSap.getSysPic().get(i).getLicenseModel())) {
            ++num;
            Cell numRF = new Cell(new Phrase(String.valueOf(num), font));
            numRF.setVerticalAlignment(Element.ALIGN_CENTER);
            numRF.setHorizontalAlignment(Element.ALIGN_CENTER);
            numRF.setBorderColor(new Color(0, 0, 0));
            numRF.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(numRF);



            String imgUrl = sysSap.getPhoneB() + "/"+ sysSap.getSysPic().get(i).getCorbisID() + ".jpg";
            Image img = Image.getInstance(imgUrl);
            if (img == null)
                return;
            img.setAbsolutePosition(0, 0);
            img.setAlignment(Image.ALIGN_LEFT);
            img.scaleAbsolute(9, 9);
            img.scalePercent(9);
            img.scalePercent(9, 9);
            img.setRotation(9);


            Cell corbisIdRM = new Cell(new Phrase(sysSap.getSysPic().get(i).getCorbisID(), blackFont));
            corbisIdRM.add(img);
            corbisIdRM.setVerticalAlignment(Element.ALIGN_CENTER);
            corbisIdRM.setHorizontalAlignment(Element.ALIGN_CENTER);
            corbisIdRM.setBorderColor(new Color(0, 0, 0));
            corbisIdRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(corbisIdRM);

            String model = null;
            String property = null;
            if(sysSap.getSysPic().get(i).getModeStatus() == 2){
                model = "有";
            }else {
                model = "無";
            }
            if(sysSap.getSysPic().get(i).getPropertyStatus() == 2){
                property = "有";
            }else {
                property = "無";
            }

            Cell titleRM = new Cell(new Phrase(" " + sysSap.getSysPic().get(i).getTitle() + "\n" + " " + sysSap.getSysPic().get(i).getCustomCreditLine()+ "\n" , font));
            titleRM.setVerticalAlignment(Element.ALIGN_LEFT);
            titleRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            titleRM.setBorderColor(new Color(0, 0, 0));
            titleRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(titleRM);

            Cell sizeRM = new Cell(new Phrase(sysSap.getSysPic().get(i).getPictureSize(), blackFont));
            sizeRM.setVerticalAlignment(Element.ALIGN_CENTER);
            sizeRM.setHorizontalAlignment(Element.ALIGN_CENTER);
            sizeRM.setBorderColor(new Color(0, 0, 0));
            sizeRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(sizeRM);

            Cell moneyRM = new Cell(new Phrase(sysSap.getSysPic().get(i).getPictureMoney(), blackFont));
            moneyRM.setVerticalAlignment(Element.ALIGN_CENTER);
            moneyRM.setHorizontalAlignment(Element.ALIGN_CENTER);
            moneyRM.setBorderColor(new Color(0, 0, 0));
            moneyRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(moneyRM);

            Cell allowPurposeRM = new Cell(new Phrase(" 圖像許可用途:", font));
            allowPurposeRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowPurposeRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowPurposeRM.setBorderColor(new Color(0, 0, 0));
            allowPurposeRM.setColspan(2);
            allowPurposeRM.setBorderWidthLeft(1);
            allowPurposeRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowPurposeRM);

            Cell allowPurposesRM = new Cell(new Phrase(sysSap.getSysPic().get(i).getAllowablePurpose(), font));
            allowPurposesRM.setColspan(3);
            allowPurposesRM.setBorderWidthRight(1);
            allowPurposesRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowPurposesRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowPurposesRM.setBorderColor(new Color(0, 0, 0));
            allowPurposesRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowPurposesRM);

            Cell allowReginRM = new Cell(new Phrase(" 圖像許可區域:", font));
            allowReginRM.setColspan(2);
            allowReginRM.setBorderWidthLeft(1);
            allowReginRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowReginRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowReginRM.setBorderColor(new Color(0, 0, 0));
            allowReginRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowReginRM);

            Cell allowReginsRM = new Cell(new Phrase(sysSap.getSysPic().get(i).getAllowableRegion(), font));
            allowReginsRM.setColspan(3);
            allowReginsRM.setBorderWidthRight(1);
            allowReginsRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowReginsRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowReginsRM.setBorderColor(new Color(0, 0, 0));
            allowReginsRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowReginsRM);

            Cell allowTimeRM = new Cell(new Phrase(" 圖像許可時間:", font));
            allowTimeRM.setColspan(2);
            allowTimeRM.setBorderWidthLeft(1);
            allowTimeRM.setBorderWidthBottom(1);
            allowTimeRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowTimeRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowTimeRM.setBorderColor(new Color(0, 0, 0));
            allowTimeRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowTimeRM);

            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小寫的mm表示的是分鐘  
            String starTime = sdf.format(sysSap.getSysPic().get(i).getAllowableTime());
            String endTime = sdf.format(sysSap.getSysPic().get(i).getEndTime());
            System.out.println("starTime          = " + starTime);
            System.out.println("endTime           = " + endTime);
            Cell allowTimesRM = new Cell(new Phrase(starTime + " - " + endTime, font));
            allowTimesRM.setColspan(3);
            allowTimesRM.setBorderWidthRight(1);
            allowTimesRM.setBorderWidthBottom(1);
            allowTimesRM.setVerticalAlignment(Element.ALIGN_LEFT);
            allowTimesRM.setHorizontalAlignment(Element.ALIGN_LEFT);
            allowTimesRM.setBorderColor(new Color(0, 0, 0));
            allowTimesRM.setBackgroundColor(new Color(255, 255, 255));
            aTable.addCell(allowTimesRM);


        }
    }

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

public void serviceMoneyTable(SysSapVo sysSap) throws DocumentException {

    Table aTable = new Table(2, 1);
    int width1[] = { 20, 80 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_LEFT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_LEFT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 9);

    Cell serviceMoney = new Cell(new Phrase("電子充圖費:", font));
    serviceMoney.setVerticalAlignment(Element.ALIGN_LEFT);
    serviceMoney.setHorizontalAlignment(Element.ALIGN_LEFT);
    // serviceMoney.setBorderWidthTop(0);
    serviceMoney.setBorderColor(new Color(0, 0, 0));
    serviceMoney.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(serviceMoney);

    Cell serviceMoneys = new Cell(new Phrase(sysSap.getServiceMoney(), font));
    serviceMoneys.setVerticalAlignment(Element.ALIGN_RIGHT);
    serviceMoneys.setHorizontalAlignment(Element.ALIGN_RIGHT);
    // serviceMoneys.setBorderWidthTop(0);
    serviceMoneys.setBorderColor(new Color(0, 0, 0));
    serviceMoneys.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(serviceMoneys);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * money
 * 
 * @param sysSap
 * @throws DocumentException
 */

public void moneyTable(SysSapVo sysSap) throws DocumentException {

    Table aTable = new Table(2, 3);
    int width1[] = { 80, 20 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_RIGHT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_RIGHT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 10);

    Cell totalMoney = new Cell(new Phrase("合計:", font));
    totalMoney.setVerticalAlignment(Element.ALIGN_RIGHT);
    totalMoney.setHorizontalAlignment(Element.ALIGN_RIGHT);
    totalMoney.setBorderWidthTop(0);
    totalMoney.setBorderColor(new Color(0, 0, 0));
    totalMoney.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(totalMoney);

    Cell totalMoneys = new Cell(new Phrase(sysSap.getTotalMoney(), font));
    totalMoneys.setVerticalAlignment(Element.ALIGN_RIGHT);
    totalMoneys.setHorizontalAlignment(Element.ALIGN_RIGHT);
    // totalMoneys.setBorderWidthTop(0);
    totalMoneys.setBorderColor(new Color(0, 0, 0));
    totalMoneys.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(totalMoneys);

    Cell taxRate = new Cell(new Phrase("稅率:", font));
    taxRate.setVerticalAlignment(Element.ALIGN_RIGHT);
    taxRate.setHorizontalAlignment(Element.ALIGN_RIGHT);
    taxRate.setBorderWidthTop(0);
    taxRate.setBorderColor(new Color(0, 0, 0));
    taxRate.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(taxRate);

    Cell taxRates = new Cell(new Phrase(sysSap.getTaxRate(), font));
    taxRates.setVerticalAlignment(Element.ALIGN_RIGHT);
    taxRates.setHorizontalAlignment(Element.ALIGN_RIGHT);
    // taxRates.setBorderWidthTop(0);
    taxRates.setBorderColor(new Color(0, 0, 0));
    taxRates.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(taxRates);

    Cell allMoney = new Cell(new Phrase("總金額:", font));
    allMoney.setVerticalAlignment(Element.ALIGN_RIGHT);
    allMoney.setHorizontalAlignment(Element.ALIGN_RIGHT);
    allMoney.setBorderWidthTop(0);
    allMoney.setBorderColor(new Color(0, 0, 0));
    allMoney.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(allMoney);

    Cell allMoneys = new Cell(new Phrase(sysSap.getAllMoney(), font));
    allMoneys.setVerticalAlignment(Element.ALIGN_RIGHT);
    allMoneys.setHorizontalAlignment(Element.ALIGN_RIGHT);
    // allMoneys.setBorderWidthTop(0);
    allMoneys.setBorderColor(new Color(0, 0, 0));
    allMoneys.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(allMoneys);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * 付款期限
 * 
 * @param sysSap
 * @throws DocumentException
 */

public void signTable() throws DocumentException {

    Table aTable = new Table(3, 5);
    int width1[] = { 25, 25, 50 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_RIGHT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_RIGHT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
           

// aTable.setBorderWidth(1); // 邊框寬度

// aTable.setBorderWidthTop(1);

aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

Font font = new Font(bfChinese, 10);

    // 付款期限
    Cell payment = new Cell(new Phrase("付款期限:", font));
    payment.setVerticalAlignment(Element.ALIGN_LEFT);
    payment.setHorizontalAlignment(Element.ALIGN_LEFT);
    payment.setBorderWidthTop(1);
    payment.setBorderWidthLeft(1);
    payment.setBorderColor(new Color(0, 0, 0));
    payment.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(payment);

    Cell payments = new Cell(new Phrase("30天", font));
    payments.setVerticalAlignment(Element.ALIGN_LEFT);
    payments.setHorizontalAlignment(Element.ALIGN_LEFT);
     payments.setBorderWidthTop(1);
    payments.setBorderColor(new Color(0, 0, 0));
    payments.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(payments); 

    Cell paymentss = new Cell(new Phrase("", font));
    paymentss.setVerticalAlignment(Element.ALIGN_LEFT);
    paymentss.setHorizontalAlignment(Element.ALIGN_LEFT);
    paymentss.setBorderWidthTop(1);
    paymentss.setBorderWidthRight(1);
    paymentss.setBorderColor(new Color(0, 0, 0));
    paymentss.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(paymentss);

    // 付款方式
    Cell paymentMethod = new Cell(new Phrase("付款方式:", font));
    paymentMethod.setVerticalAlignment(Element.ALIGN_LEFT);
    paymentMethod.setHorizontalAlignment(Element.ALIGN_LEFT);
     paymentMethod.setBorderWidthLeft(1);
    paymentMethod.setBorderColor(new Color(0, 0, 0));
    paymentMethod.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(paymentMethod);

    Cell paymentMethods = new Cell(new Phrase("電彙,銀行轉賬:", font));
    paymentMethods.setVerticalAlignment(Element.ALIGN_LEFT);
    paymentMethods.setHorizontalAlignment(Element.ALIGN_LEFT);
     paymentMethods.setBorderWidthTop(0);
    paymentMethods.setBorderColor(new Color(0, 0, 0));
    paymentMethods.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(paymentMethods);

    Cell paymentMethodss = new Cell(new Phrase("", font));
    paymentMethodss.setVerticalAlignment(Element.ALIGN_LEFT);
    paymentMethodss.setHorizontalAlignment(Element.ALIGN_LEFT);
     paymentMethodss.setBorderWidthRight(1);
    paymentMethodss.setBorderColor(new Color(0, 0, 0));
    paymentMethodss.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(paymentMethodss);

    // 乙方銀行賬戶
    Cell companyBank = new Cell(new Phrase("乙方銀行賬戶:", font));
    companyBank.setVerticalAlignment(Element.ALIGN_LEFT);
    companyBank.setHorizontalAlignment(Element.ALIGN_LEFT);
     companyBank.setBorderWidthLeft(1);
    companyBank.setBorderColor(new Color(0, 0, 0));
    companyBank.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyBank);

    Cell companyBanks = new Cell(new Phrase("公司名稱: ", font));
    companyBanks.setVerticalAlignment(Element.ALIGN_LEFT);
    companyBanks.setHorizontalAlignment(Element.ALIGN_LEFT);
     companyBanks.setBorderWidthTop(0);
    companyBanks.setBorderColor(new Color(0, 0, 0));
    companyBanks.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyBanks);

    Cell companyBankss = new Cell(new Phrase("高品(北京)圖像有限公司", font));
    companyBankss.setVerticalAlignment(Element.ALIGN_LEFT);
    companyBankss.setHorizontalAlignment(Element.ALIGN_LEFT);
     companyBankss.setBorderWidthRight(1);
    companyBankss.setBorderColor(new Color(0, 0, 0));
    companyBankss.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyBankss);

    // 開戶行名稱
    Cell bankName = new Cell(new Phrase("", font));
    bankName.setVerticalAlignment(Element.ALIGN_LEFT);
    bankName.setHorizontalAlignment(Element.ALIGN_LEFT);
     bankName.setBorderWidthLeft(1);
    bankName.setBorderColor(new Color(0, 0, 0));
    bankName.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankName);

    Cell bankNames = new Cell(new Phrase("開戶銀行名稱: ", font));
    bankNames.setVerticalAlignment(Element.ALIGN_LEFT);
    bankNames.setHorizontalAlignment(Element.ALIGN_LEFT);
     bankNames.setBorderWidthTop(0);
    bankNames.setBorderColor(new Color(0, 0, 0));
    bankNames.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankNames);

    Cell bankNamess = new Cell(new Phrase("交通銀行股份有限公司北京東三環支行", font));
    bankNamess.setVerticalAlignment(Element.ALIGN_LEFT);
    bankNamess.setHorizontalAlignment(Element.ALIGN_LEFT);
     bankNamess.setBorderWidthRight(1);
    bankNamess.setBorderColor(new Color(0, 0, 0));
    bankNamess.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankNamess);

    // 開戶行帳号
    Cell bankNumber = new Cell(new Phrase("", font));
    bankNumber.setVerticalAlignment(Element.ALIGN_LEFT);
    bankNumber.setHorizontalAlignment(Element.ALIGN_LEFT);
    bankNumber.setBorderWidthLeft(1);
    bankNumber.setBorderWidthBottom(1); 
    bankNumber.setBorderColor(new Color(0, 0, 0));
    bankNumber.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankNumber);

    Cell bankNumbers = new Cell(new Phrase("開戶行賬号: ", font));
    bankNumbers.setVerticalAlignment(Element.ALIGN_LEFT);
    bankNumbers.setHorizontalAlignment(Element.ALIGN_LEFT);
    bankNumbers.setBorderWidthBottom(1); 
    bankNumbers.setBorderColor(new Color(0, 0, 0));
    bankNumbers.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankNumbers);

    Cell bankNumberss = new Cell(new Phrase("110061575018800004456", font));
    bankNumberss.setVerticalAlignment(Element.ALIGN_LEFT);
    bankNumberss.setHorizontalAlignment(Element.ALIGN_LEFT);
    bankNumberss.setBorderWidthBottom(1);
    bankNumberss.setBorderWidthRight(1);  
    bankNumberss.setBorderColor(new Color(0, 0, 0));
    bankNumberss.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(bankNumberss);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * 條例
 * 
 * @param sysSap
 * @throws DocumentException
 */

public void rulesTable() throws DocumentException {

    Table aTable = new Table(1, 2);
    int width1[] = { 100 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_RIGHT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_RIGHT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 10);


    Cell rulesTable = new Cell(new Phrase("", font));
    rulesTable.setVerticalAlignment(Element.ALIGN_LEFT);
    rulesTable.setHorizontalAlignment(Element.ALIGN_LEFT);
     rulesTable.setBorderWidth(0);;
    rulesTable.setBorderColor(new Color(0, 0, 0));
    rulesTable.setBackgroundColor(new Color(204, 204, 204));
    aTable.addCell(rulesTable);

    Cell rulesTables = new Cell(new Phrase(
            "本報價依據後附之《高品内容許可協定》或出現在高品網址www.gaopinimages.com網頁内《高品内容許可協定》内條款和條件實行。簽署了本許可協定表明您承認您已經閱讀、了解并同意所有條款和條件。",
            font));
    rulesTables.setVerticalAlignment(Element.ALIGN_LEFT);
    rulesTables.setHorizontalAlignment(Element.ALIGN_LEFT);
     rulesTables.setBorderWidth(0);
    rulesTables.setBorderColor(new Color(0, 0, 0));
    rulesTables.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(rulesTables);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

/**
 * 簽約
 * 
 * @param sysSap
 * @throws DocumentException
 */

public void SignTable(SysSapVo sysSap) throws DocumentException {

    Table aTable = new Table(4, 5);
    int width1[] = { 20, 30, 20, 30 };
    aTable.setWidths(width1);// 設定每列所占比例
    aTable.setWidth(100); // 占頁面寬度 90%
    aTable.setAlignment(Element.ALIGN_RIGHT);// 居中顯示
    aTable.setAlignment(Element.ALIGN_RIGHT);// 縱向居中顯示
    aTable.setAutoFillEmptyCells(true); // 自動填滿
    aTable.setBorderWidth(0); // 邊框寬度
    aTable.setBorderColor(new Color(0, 125, 255)); // 邊框顔色

    Font font = new Font(bfChinese, 10);

    // 甲方
    Cell companyAName = new Cell(new Phrase("甲方:", font));
    companyAName.setVerticalAlignment(Element.ALIGN_LEFT);
    companyAName.setHorizontalAlignment(Element.ALIGN_LEFT);
    companyAName.setBorderWidthTop(0);
    companyAName.setBorderColor(new Color(0, 0, 0));
    companyAName.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyAName);

    Cell companyANames = new Cell(new Phrase(sysSap.getCompanyAName(), font));
    companyANames.setVerticalAlignment(Element.ALIGN_LEFT);
    companyANames.setHorizontalAlignment(Element.ALIGN_LEFT);
    companyANames.setBorderWidthTop(0);
    companyANames.setBorderColor(new Color(0, 0, 0));
    companyANames.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyANames);

    // 乙方
    Cell companyBName = new Cell(new Phrase("乙方:", font));
    companyBName.setVerticalAlignment(Element.ALIGN_LEFT);
    companyBName.setHorizontalAlignment(Element.ALIGN_LEFT);
    companyBName.setBorderWidthTop(0);
    companyBName.setBorderColor(new Color(0, 0, 0));
    companyBName.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyBName);

    Cell companyBNames = new Cell(new Phrase("高品(北京)圖像有限公司", font));
    companyBNames.setVerticalAlignment(Element.ALIGN_LEFT);
    companyBNames.setHorizontalAlignment(Element.ALIGN_LEFT);
    companyBNames.setBorderWidthTop(0);
    companyBNames.setBorderColor(new Color(0, 0, 0));
    companyBNames.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(companyBNames);

    // 甲方蓋章
    Cell sealA = new Cell(new Phrase("(蓋章)", font));
    sealA.setVerticalAlignment(Element.ALIGN_LEFT);
    sealA.setHorizontalAlignment(Element.ALIGN_LEFT);
    sealA.setBorderWidthTop(0);
    sealA.setBorderColor(new Color(0, 0, 0));
    sealA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(sealA);

    Cell sealAs = new Cell(new Phrase("", font));
    sealAs.setVerticalAlignment(Element.ALIGN_LEFT);
    sealAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    sealAs.setBorderWidthTop(0);
    sealAs.setBorderColor(new Color(0, 0, 0));
    sealAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(sealAs);

    // 乙方蓋章
    Cell sealB = new Cell(new Phrase("(蓋章)", font));
    sealB.setVerticalAlignment(Element.ALIGN_LEFT);
    sealB.setHorizontalAlignment(Element.ALIGN_LEFT);
    sealB.setBorderWidthTop(0);
    sealB.setBorderColor(new Color(0, 0, 0));
    sealB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(sealB);

    Cell sealBs = new Cell(new Phrase("", font));
    sealBs.setVerticalAlignment(Element.ALIGN_LEFT);
    sealBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    sealBs.setBorderWidthTop(0);
    sealBs.setBorderColor(new Color(0, 0, 0));
    sealBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(sealBs);

    // 甲方授權代表人
    Cell personA = new Cell(new Phrase("授權代表人:", font));
    personA.setVerticalAlignment(Element.ALIGN_LEFT);
    personA.setHorizontalAlignment(Element.ALIGN_LEFT);
    personA.setBorderWidthTop(0);
    personA.setBorderColor(new Color(0, 0, 0));
    personA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(personA);

    Cell personAs = new Cell(new Phrase("", font));
    personAs.setVerticalAlignment(Element.ALIGN_LEFT);
    personAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    personAs.setBorderWidthTop(0);
    personAs.setBorderColor(new Color(0, 0, 0));
    personAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(personAs);

    // 乙方授權代表人
    Cell personB = new Cell(new Phrase("授權代表人:", font));
    personB.setVerticalAlignment(Element.ALIGN_LEFT);
    personB.setHorizontalAlignment(Element.ALIGN_LEFT);
    personB.setBorderWidthTop(0);
    personB.setBorderColor(new Color(0, 0, 0));
    personB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(personB);

    Cell personBs = new Cell(new Phrase("", font));
    personBs.setVerticalAlignment(Element.ALIGN_LEFT);
    personBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    personBs.setBorderWidthTop(0);
    personBs.setBorderColor(new Color(0, 0, 0));
    personBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(personBs);

    // 甲方簽署
    Cell signA = new Cell(new Phrase("簽署:", font));
    signA.setVerticalAlignment(Element.ALIGN_LEFT);
    signA.setHorizontalAlignment(Element.ALIGN_LEFT);
    signA.setBorderWidthTop(0);
    signA.setBorderColor(new Color(0, 0, 0));
    signA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(signA);

    Cell signAs = new Cell(new Phrase("", font));
    signAs.setVerticalAlignment(Element.ALIGN_LEFT);
    signAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    signAs.setBorderWidthTop(0);
    signAs.setBorderColor(new Color(0, 0, 0));
    signAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(signAs);

    // 乙方簽署
    Cell signB = new Cell(new Phrase("簽署:", font));
    signB.setVerticalAlignment(Element.ALIGN_LEFT);
    signB.setHorizontalAlignment(Element.ALIGN_LEFT);
    signB.setBorderWidthTop(0);
    signB.setBorderColor(new Color(0, 0, 0));
    signB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(signB);

    Cell signBs = new Cell(new Phrase("", font));
    signBs.setVerticalAlignment(Element.ALIGN_LEFT);
    signBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    signBs.setBorderWidthTop(0);
    signBs.setBorderColor(new Color(0, 0, 0));
    signBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(signBs);

    // 甲方簽署日期
    Cell timeA = new Cell(new Phrase("日期:", font));
    timeA.setVerticalAlignment(Element.ALIGN_LEFT);
    timeA.setHorizontalAlignment(Element.ALIGN_LEFT);
    timeA.setBorderWidthTop(0);
    timeA.setBorderColor(new Color(0, 0, 0));
    timeA.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(timeA);

    Cell timeAs = new Cell(new Phrase("   年          月          日", font));
    timeAs.setVerticalAlignment(Element.ALIGN_LEFT);
    timeAs.setHorizontalAlignment(Element.ALIGN_LEFT);
    timeAs.setBorderWidthTop(0);
    timeAs.setBorderColor(new Color(0, 0, 0));
    timeAs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(timeAs);

    // 乙方簽署
    Cell timeB = new Cell(new Phrase("日期:", font));
    timeB.setVerticalAlignment(Element.ALIGN_LEFT);
    timeB.setHorizontalAlignment(Element.ALIGN_LEFT);
    timeB.setBorderWidthTop(0);
    timeB.setBorderColor(new Color(0, 0, 0));
    timeB.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(timeB);

    Cell timeBs = new Cell(new Phrase("   年          月          日", font));
    timeBs.setVerticalAlignment(Element.ALIGN_LEFT);
    timeBs.setHorizontalAlignment(Element.ALIGN_LEFT);
    timeBs.setBorderWidthTop(0);
    timeBs.setBorderColor(new Color(0, 0, 0));
    timeBs.setBackgroundColor(new Color(255, 255, 255));
    aTable.addCell(timeBs);

    document.add(aTable);
    document.add(new Paragraph("\n"));
}

public void closeDocument() throws DocumentException {
    this.document.close();
}

/**
 * 導出
 * 
 * @param file
 *            word檔案(路徑+檔案名),word檔案自動建立
 * @param dataList
 *            資料
 * @return
 * @throws XmlException
 * @throws IOException
 * @throws DocumentException
 */
public static boolean getSapWord(SysSapVo sysSap, File file,HttpServletResponse response) throws IOException, XmlException, DocumentException {

    WordUtils wt = new WordUtils();
    String path = "";
    if(StringUtils.isNotBlank(sysSap.getItemName())){

        path= "d:\\aaa\\" + sysSap.getItemName() + ".doc";
    }else{
        path= "d:\\aaa\\" + sysSap.getContractId() + ".doc";
    }
    wt.openDocument(path);
    wt.insertImg(sysSap, sysSap.getPhoneB() + "/gaopinimages.png", Image.ALIGN_LEFT, 13, 13, 13,
            13, 13, 13);
    wt.insertTitle("高品内容許可協定", 12, Font.BOLD, Element.ALIGN_CENTER);
    wt.insertRiskTable(sysSap);
    wt.insertRiskEvaluationTable(sysSap);
    // RM
    if ("1".equals(sysSap.getEmailB())) {
        wt.insertTitle("RM免版稅内容", 12, Font.BOLD, Element.ALIGN_CENTER);
        wt.RMTable(sysSap);
    }
    // 2 RF
    if ("2".equals(sysSap.getEmailB())) {
        wt.insertTitle("RF免版稅内容", 12, Font.BOLD, Element.ALIGN_CENTER);
        wt.RFTable(sysSap);
    }
    // 2 RF
    if ("3".equals(sysSap.getEmailB())) {
        wt.insertTitle("RM免版稅内容", 12, Font.BOLD, Element.ALIGN_CENTER);
        wt.RMTable(sysSap);
        wt.insertTitle("RF免版稅内容", 12, Font.BOLD, Element.ALIGN_CENTER);
        wt.RFTable(sysSap);
    }
    if (!"0".equals(sysSap.getServiceMoney()) && !"0.00".equals(sysSap.getServiceMoney())) {
        wt.serviceMoneyTable(sysSap);
    }
    wt.moneyTable(sysSap);
    wt.signTable();
    wt.rulesTable();
    wt.SignTable(sysSap);
    wt.closeDocument();
           

// OutputStream output = new FileOutputStream(path);

// wt.write(output);

// output.flush();

// output.close();

File files = new File(path);

FileInputStream fileIntput = new FileInputStream(files);

response.setContentType(“application/vnd.ms-word”);

// response.setContentType(“application/octet-stream”);

response.addHeader(“Content-Disposition”, “attachment;filename=”+sysSap.getContractId() + “.doc”);

OutputStream ouputStream = response.getOutputStream();

// String urlString = “http://weitu-650-water.bj.bcebos.com/233107877533.jpg“;

// URL url = new URL(urlString);

DataInputStream dataInputStream = new DataInputStream(fileIntput);

byte[] buffer = new byte[1024];  
    int length;  

    while ((length = dataInputStream.read(buffer)) > 0) {  
        ouputStream.write(buffer, 0, length);  
    }  

    dataInputStream.close(); 
           

// wb.write(ouputStream);

ouputStream.flush();

ouputStream.close();

System.out.println("導出成功");

    boolean isSucess = true;
    return isSucess;
}

private void write(OutputStream output) {
    // TODO Auto-generated method stub

}
           

}