细心!用心!耐心!

吾非文人,乃市井一俗人也,读百卷书,跨江河千里,故申城一游; 一两滴辛酸,三四年学业,五六点粗墨,七八笔买卖,九十道人情。

BlogJava 联系 聚合 管理
  1 Posts :: 196 Stories :: 10 Comments :: 0 Trackbacks


/**
   import com.lowagie.text.*;
   import com.lowagie.text.pdf.PdfWriter;
   import java.io.*;
   import java.text.*;
   文档输出
*/
public static void billImagePdfGenerator(String pdfMsg, String brand, OutputStream output)
    {
        Document document = new Document(PageSize.A4);
        String tempStr = "";
        try
        {
            PdfWriter.getInstance(document, output);
            document.open();
            Image jpg = Image.getInstance("emice/jsp/images/bi" + brand + ".jpg");
            jpg.scalePercent(80F);
            document.add(jpg);
            BufferedReader reader = null;
            reader = new BufferedReader(new StringReader(pdfMsg));
            while((tempStr = reader.readLine()) != null)
            {
                if(tempStr.startsWith("Page  "))
                    document.newPage();
                Phrase phrase = new Phrase(10F, tempStr + "\n", FontFactory.getFont("Courier", 9F));
                document.add(phrase);
            }
            document.close();
            reader.close();
        }
        catch(DocumentException de)
        {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe)
        {
            System.err.println(ioe.getMessage());
        }
    }
   
   
   
  /**
     获取向前或者向后几天的日期
  */
  public static final String getCaseFormatTime(int shiftDay)
    {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(1);
        int month = cal.get(2);
        int date = cal.get(5);
        int hour = cal.get(11);
        int minute = cal.get(12);
        int second = cal.get(13);
        date += shiftDay;
        cal.set(year, month, date, hour, minute, second);
        Date d = cal.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        String dateString = sdf.format(d);
        return dateString;
    }
   
   
   
    /**
      获取当前时间
    */
    public static final String getCurrentFormatDate()
    {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        String dateString = sdf.format(d);
        return dateString;
    }
   
    /**
      获取资源文件内容
      import org.apache.struts.util.MessageResources;
      import org.apache.struts.util.PropertyMessageResourcesFactory;
    */
    public static String getMessage(String resourceName, String messageName)
    {
        MessageResources resource = (new PropertyMessageResourcesFactory()).createResources(resourceName);
        String value = resource.getMessage(messageName);
        if(value == null)
            value = "";
        return value;
    }

posted on 2007-10-16 16:55 张金鹏 阅读(310) 评论(0)  编辑  收藏 所属分类: core java中的一些数据结构的处理

只有注册用户登录后才能发表评论。


网站导航: