Java tutorial
/** * * @Title PdfExportBuilder.java * @Description TODO * Copyright: Copyright (c) 2013, Smiletony and/or its affiliates. All rights reserved. * SMILETONY PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * @author NY * @date 2013-10-9 ?4:34:04 * */ package com.ny.apps.exporter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.Observable; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; /** * * @Description TODO * @author <a href="mailto:mynameisny@qq.com">Tony Joseph</a> * @version 1.0 * */ public class PdfExportBuilder implements ExportBuilder { private Document document; /* ? Javadoc * @see java.util.Observer#update(java.util.Observable, java.lang.Object) */ @Override public void update(Observable subject, Object o) { this.export(o); } /* ? Javadoc * @see com.ny.apps.executor.ExportBuilder#export() */ @Override public void export(Object o) { System.out.println(o + " received message."); try { document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(new File("E:\\ny.pdf"))); document.open(); document.add(new Paragraph("Hello " + o)); } catch (FileNotFoundException e) { // TODO ? catch ? e.printStackTrace(); } catch (DocumentException e) { // TODO ? catch ? e.printStackTrace(); } finally { System.out.println("export complete."); document.close(); } } }