public void createPDF()
{
Document doc = new Document();
        

try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
 
File dir = new File(path);
       if(!dir.exists())
        dir.mkdirs();

       
   File file = new File(dir, "sample.pdf");
   FileOutputStream fOut = new FileOutputStream(file);
     
        PdfWriter.getInstance(doc, fOut);
                 
                //open the document
                doc.open();
                
                
                Paragraph p1 = new Paragraph("Hi! I am generating my first PDF using DroidText----joe");
                Font paraFont= new Font(Font.COURIER);
                p1.setAlignment(Paragraph.ALIGN_CENTER);
                p1.setFont(paraFont);
                
                 //add paragraph to document    
                 doc.add(p1);
                
                 Paragraph p2 = new Paragraph("This is an example of a simple paragraph");
                 Font paraFont2= new Font(Font.COURIER,14.0f,Color.GREEN);
                 p2.setAlignment(Paragraph.ALIGN_CENTER);
                 p2.setFont(paraFont2);
                 
                 doc.add(p2);
                 
                 ByteArrayOutputStream stream = new ByteArrayOutputStream();
                 Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.pdf);
                 bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
                 Image myImg = Image.getInstance(stream.toByteArray());
                 myImg.setAlignment(Image.MIDDLE);
                
                 //add image to document
                 doc.add(myImg);
                
                 //set footer
                 Phrase footerText = new Phrase("This is an example of a footer");
                 HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
                 doc.setFooter(pdfFooter);
                


                
         } catch (DocumentException de) {
           
         } catch (IOException e) {
          
         } 
finally
         {
                 doc.close();
         }
       


类库:http://download.csdn.net/detail/u011636207/7005107


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android获取视频文件某一帧并设置图片
  2. android中usb设备驱动不能自动创建设备节
  3. android_8.1 hdmi设备热插拔事件
  4. Android培训班(72)Dex文件里类定义dvmDef
  5. 【Android】通过Java代码替换TabHost中的
  6. sdk platform tools is missing please u
  7. [置顶] android中屏幕触摸事件
  8. Android(安卓)各国语言缩写-各国语言简称
  9. android shape的使用 2
  10. 1.Android(安卓)Studio 环境搭建并配置Ge