| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1185 人关注过本帖
标题:百分帖---------小问题撒分
只看楼主 加入收藏
qingzhu5753
Rank: 4
等 级:业余侠客
帖 子:64
专家分:248
注 册:2009-10-28
收藏
得分:20 
package com.zhaipuhong.j2se.pdf;   
  
import    
import java.util.Date;   
  
import javax.servlet.ServletException;   
import javax.servlet.http.HttpServlet;   
import javax.servlet.http.HttpServletRequest;   
import javax.servlet.http.HttpServletResponse;   
  
import com.lowagie.text.Document;   
import com.lowagie.text.DocumentException;   
import com.lowagie.text.Paragraph;   
import com.lowagie.text.pdf.PdfWriter;   
import com.lowagie.text.pdf.BaseFont;   
import com.lowagie.text.pdf.PdfPTable;   
import com.lowagie.text.pdf.PdfPCell;   
import java.awt.Color;   
  
public class PdfServlet extends HttpServlet {   
  
    private static final long serialVersionUID = -6033026500372479591L;   
  
    public void doGet (HttpServletRequest request, HttpServletResponse response)   
    throws IOException, ServletException {   
  
        // step 1  建立文档对象   
        Document document = new Document();   
        try {   
                //设置文档相应类型   
                response.setContentType("application/pdf");   
                PdfWriter.getInstance(document, response.getOutputStream());   
  
  
                // step 3  打开文档   
                document.open();   
                //支持中文   
                BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);   
                com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);   
                Paragraph pragraph=new Paragraph("你好", FontChinese);   
  
  
                // step 4  向文档中添加内容   
                document.add(pragraph);   
                document.add(new Paragraph(" Hello World !"));   
                document.add(new Paragraph("Date 时间"+new Date().toString()));   
                document.add(new Paragraph(new Date().toString()));   
                document.add(new Paragraph(new Date().toString()));   
  
  
  
                PdfPTable table = new PdfPTable(3);   
                        PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));   
                        cell.setColspan(3);   
                        table.addCell(cell);   
                        table.addCell("1.1");   
                        table.addCell("2.1");   
                        table.addCell("3.1");   
                        table.addCell("1.2");   
                        table.addCell("2.2");   
                        table.addCell("3.2");   
                        cell = new PdfPCell(new Paragraph("cell test1"));   
                        cell.setBorderColor(new Color(255, 0, 0));   
                        table.addCell(cell);   
                        cell = new PdfPCell(new Paragraph("cell test2"));   
                        cell.setColspan(2);   
                        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));   
                        table.addCell(cell);   
                        document.add(table);   
  
        }catch(DocumentException de) {   
            de.printStackTrace();   
            System.err.println("document: " + de.getMessage());   
        }   
  
        // step 5: 关闭文档对象   
        document.close();   
    }   
  
    //支持中文   
    public Paragraph getChineseString(String chineseString){   
      Paragraph pragraph=null;   
      BaseFont bfChinese = null;   
      try {   
        bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",   
                                        BaseFont.NOT_EMBEDDED);   
        com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese,   
            12, com.lowagie.text.Font.NORMAL);   
         pragraph = new Paragraph(chineseString, FontChinese);   
      }   
      catch (Exception ex) {   
        ex.printStackTrace();   
      }   
      return pragraph;   
    }   
}  

package com.zhaipuhong.j2se.pdf;

import
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import java.awt.Color;

public class PdfServlet extends HttpServlet {

    private static final long serialVersionUID = -6033026500372479591L;

    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

        // step 1  建立文档对象
        Document document = new Document();
        try {
                //设置文档相应类型
                response.setContentType("application/pdf");
                PdfWriter.getInstance(document, response.getOutputStream());


                // step 3  打开文档
                document.open();
                //支持中文
                BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
                com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
                Paragraph pragraph=new Paragraph("你好", FontChinese);


                // step 4  向文档中添加内容
                document.add(pragraph);
                document.add(new Paragraph(" Hello World !"));
                document.add(new Paragraph("Date 时间"+new Date().toString()));
                document.add(new Paragraph(new Date().toString()));
                document.add(new Paragraph(new Date().toString()));



                PdfPTable table = new PdfPTable(3);
                        PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
                        cell.setColspan(3);
                        table.addCell(cell);
                        table.addCell("1.1");
                        table.addCell("2.1");
                        table.addCell("3.1");
                        table.addCell("1.2");
                        table.addCell("2.2");
                        table.addCell("3.2");
                        cell = new PdfPCell(new Paragraph("cell test1"));
                        cell.setBorderColor(new Color(255, 0, 0));
                        table.addCell(cell);
                        cell = new PdfPCell(new Paragraph("cell test2"));
                        cell.setColspan(2);
                        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
                        table.addCell(cell);
                        document.add(table);

        }catch(DocumentException de) {
            de.printStackTrace();
            System.err.println("document: " + de.getMessage());
        }

        // step 5: 关闭文档对象
        document.close();
    }

    //支持中文
    public Paragraph getChineseString(String chineseString){
      Paragraph pragraph=null;
      BaseFont bfChinese = null;
      try {
        bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
                                        BaseFont.NOT_EMBEDDED);
        com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese,
            12, com.lowagie.text.Font.NORMAL);
         pragraph = new Paragraph(chineseString, FontChinese);
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }
      return pragraph;
    }
}
2010-04-14 09:48
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:10 
回复 楼主 孤独冷雨
我的判断:这个是用Flash做的,会Flash的话,就应该知道能不能做啊!(我不熟悉Flash,但觉得是可以用控件来实现的)

★★★★★为人民服务★★★★★
2010-04-14 10:24
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
回复 11楼 qingzhu5753
看不懂啊兄弟,偶只会ASP!

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2010-04-14 14:14
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
Java能实现的话,可以使用JavaApplet小应用程序嵌入网页来实现也是个好办法。
2010-04-15 11:27
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
真不知道怎么搞好了!搞不出来啊!

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2010-04-15 16:32
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
回复 15楼 孤独冷雨
把那个丁豆什么的网站上的SWF下下来,反编,研究就行了!

★★★★★为人民服务★★★★★
2010-04-16 08:15
sky222
Rank: 4
等 级:业余侠客
威 望:1
帖 子:152
专家分:225
注 册:2010-3-11
收藏
得分:0 
帮顶一下,
2010-04-16 11:18
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
回复 16楼 cnfarer
呵呵!想的太简单了!

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2010-04-16 11:52
快速回复:百分帖---------小问题撒分
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021708 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved