如何将保存的jpg图像转换为pdf以在android中的adobe reader中查看图像
我已将jpg文件保存到下面给出的内部存储代码中如何将保存的jpg图像转换为pdf以在android中的adobe reader中查看图像,android,pdf-conversion,Android,Pdf Conversion,我已将jpg文件保存到下面给出的内部存储代码中 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File folderPath = new File(Environment.getExternalStorageDirectory() + "/OCR"); if (!folderPath.exists()) { if (folderPath.mkdir()) ; //directory
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File folderPath = new File(Environment.getExternalStorageDirectory() + "/OCR");
if (!folderPath.exists()) {
if (folderPath.mkdir()) ; //directory is created;
} else {
File photo = new File(folderPath, "OCRPIC" + UUID.randomUUID().toString().substring(0, 5) + ".jpg");
imageUri = FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider", photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, PHOTO_REQUEST);
}
现在,我希望jpg图像隐藏并显示在pdf阅读器中。我尝试了下面给出的一些代码,但抛出了错误,表示不支持文件格式
private void viewPdf(File file) {
Intent intent;
intent = new Intent(Intent.ACTION_VIEW);
Uri photoURI = FileProvider.getUriForFile(MyFileActivity.this, BuildConfig.APPLICATION_ID + ".provider", file);
MyFileActivity.this.grantUriPermission("com.android.camera", photoURI,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(MyFileActivity.this, BuildConfig.APPLICATION_ID + ".provider", file) : Uri.fromFile(file), "application/pdf").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("Download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
}
除了itext Library之外,任何解决此转换的建议或示例。,请检查以下链接,它可能会对您有所帮助。您没有将图像转换为pdf。您的代码试图在pdf阅读器中打开图像。Itext是在android中制作或阅读pdf的好库。有什么不使用它的具体原因吗?@Vihaari Varma Itext lib license说我的应用程序应该免费发布才能免费获得lib,但我可能在以后以付费方式发布应用程序时遇到问题。所以我希望避免使用Itext。