如何将图像利用iText到PDF转换 [英] How to convert images to pdf using iText

查看:107
本文介绍了如何将图像利用iText到PDF转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请告诉我如何使用iText的API在Android中所拍摄的图像这已经是库转换并保存为PDF文档。帮助尽快必要的。主要目标是创建Android应用程序,从而能够从库中获得多个图像,并将其保存为PDF格式。

Can anyone please show me how to use iText API in android to convert images captured which is already in gallery and save it as pdf document. Help needed as soon as possible. Main objective is to create android application whereby able to get multiple images from the gallery and save it as pdf format.

推荐答案

要得到图库图像日子会把你必须启动startActivityForResult和onActivityResultü可以存储图像中的PDF文件: -

To get the images from gallery u'll have to start the startActivityForResult and in onActivityResult u can store the image in the pdf file:-

第一步拨打画廊意向为: -

First call the gallery intent as:-

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);

然后在onActivityResult得到位图和PDF写

Then in onActivityResult get the bitmap and write it in the PDF

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        if (resultCode == RESULT_OK) {  


        switch(requestCode){    

             case SELECT_PICTURE:
                  Uri selectedImageUri = data.getData();
                  String[] filePathColumn = { MediaStore.Images.Media.DATA };
                  Cursor cursor = getContentResolver().query(selectedImageUri,filePathColumn, null, null, null);
                  cursor.moveToFirst();
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  String picturePath = cursor.getString(columnIndex);
                  cursor.close();
                  Bitmap bmp = BitmapFactory.decodeFile(picturePath);
                  ByteArrayOutputStream stream = new ByteArrayOutputStream();
                  bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

              Document document = new Document();
              File f=new File(Environment.getExternalStorageDirectory(), "SimpleImages.pdf");
              PdfWriter.getInstance(document,new FileOutputStream(f));
              document.open();
              document.add(new Paragraph("Simple Image"));

              Image image = Image.getInstance(stream.toByteArray());
              document.add(image);
              document.close();
              break;
            }  
          }  

    }

希望这有助于..

Hope this helps..

这篇关于如何将图像利用iText到PDF转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆