Package cn.guoyukun.pdm2pdf

Source Code of cn.guoyukun.pdm2pdf.MainAll

package cn.guoyukun.pdm2pdf;

import java.io.IOException;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.guoyukun.pdm2pdf.model.Domain;
import cn.guoyukun.pdm2pdf.pdm.PdmReader;

import com.itextpdf.text.DocumentException;

public class MainAll {
  // 日志对象
  private static final Logger LOG = LoggerFactory.getLogger(MainAll.class);
  private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy年MM月dd日");
  private static final String TODAY = SDF.format(new Date());
  public static void main(String[] args) throws Exception {
    // 加载配置
    Properties p = new Properties();
    p.load(MainAll.class.getResourceAsStream("/config.properties"));
    // 要加载的pdm
    final String pdm = Helper.loadNotNullString(p, "pdm");
    LOG.info("加载PDM:{}", pdm);
    // 生成到哪个目录
    final String folder = Helper.loadFolderPathWithDefault(p, "folder");
    LOG.info("目标文件夹:{}", folder);
   
    // 文档标题
    final String title = Helper.loadNotNullString(p, "title");
    LOG.info("文档标题:{}", title);

    // 生成时间,不指定会使用当前日期
    final String genDate = Helper.loadStringWithDefault(p, "date", TODAY);

    // Pdm解析器
    PdmReader r = Helper.parsePdm(pdm);
    for(String domain: new String[]{"MS","FL","DC","CH","WH","DM"}){
      gen(domain,r, genDate,title, folder);
    }
   
  }
 

  private static void gen(String domainCode, PdmReader r, String genDate, String title, String folder) throws MalformedURLException, DocumentException, IOException {
    String pdf=folder+domainCode+".pdf";
    // Pdf生成器
    PdfGenerator g = new PdfGenerator();
    // 设置变量
    g.setTables(r.getTables()).setGenerateDate(genDate).setPdfTitle(title)
        .setVersion("V" + r.getVersion());

    // 打开文档,生成封面
    g.newPdf(pdf).openPdf().addOutline().addCover();
    // 生成业务域内容
      Domain domain = Helper.loadDomainConfig(domainCode);
      g.addDomainContent(domain);
    // 关闭文档
    g.closePdf();
  }
 

}
TOP

Related Classes of cn.guoyukun.pdm2pdf.MainAll

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.