如何将图像利用iText到PDF转换如何将、图像、PDF、iText

2023-09-05 10:36:39 作者:可否泼你一脸水

任何人都可以请告诉我如何使用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..

 
精彩推荐
图片推荐