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 中隐藏EditText的下划线方法
  3. android:configChanges属性
  4. Android 线程超时的例子
  5. Tips: compilation and creating new pro
  6. Android应用在未启动的情况下无法收到指
  7. 一个现有Android工程作为组件加入到另一
  8. Android RadioGroup 设置默认值之后 Radi
  9. 微信ANDROID客户端-会话速度提升70%的背
  10. View类的XML属性、相关方法及说明