【问题标题】:How to show pdf in image view android?如何在图像视图android中显示pdf?
【发布时间】:2017-09-13 21:18:34
【问题描述】:

以下代码是从设备中挑选图像。如何从设备中选择 pdf。以及如何在图像视图中显示 pdf?

  bt_gall .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    // Show only images, no videos or anything else
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    // Always show the chooser (if there are multiple options available)
                    startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
                    alertDialog.dismiss();
                }
            });

【问题讨论】:

  • ImageView 不支持打印pdf
  • pdf 文件不是图片

标签: java android pdf


【解决方案1】:

要选择 pdf 试试这个

Intent intent = new Intent();
        intent.setType("application/pdf");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select PDF"), 1);

要将 Pdf 设置为图像,您需要创建 pdf 的缩略图

要创建缩略图检查这个,

https://stackoverflow.com/a/38829523/3416642

希望这会对你有所帮助。

【讨论】:

  • 例如,当我按下按钮时,我想选择图像文件或pdf文件。代码是什么?
  • @spodee 传递多个 MIME 类型 - 检查此 stackoverflow.com/a/33117677/3416642
  • 当我尝试这段代码时 [Intent intent = new Intent(); intent.setType("image/*|application/pdf");意图.setAction(意图.ACTION_GET_CONTENT);意图.addCategory(意图.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(intent, "Select Document"), 1);] 只选择了图片。
猜你喜欢
  • 1970-01-01
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-26
相关资源
最近更新 更多