Greetings to community
I am generating PDF reports using ITEXT library.
'com.itextpdf:itextpdf:5.0.6'
I am doing this like that
Document document = new Document();
fileName = FileName + Common.getCurrentDateTime() + ".pdf";
fileName1 = FileName + Common.getCurrentDateTime() + ".pdf";
String dest = context.getExternalFilesDir(null) + "/RTS";
File dir = new File(dest);
if (!dir.exists())
dir.mkdirs();
try {
File file = new File(dest, fileName);
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file, false);
//FileOutputStream fOut = new FileOutputStream(file);
//PdfWriter.getInstance(document, new FileOutputStream(dest));
PdfWriter.getInstance(document, fOut);
// PdfWriter.getInstance(document, fOut);
} catch (DocumentException e) {
e.printStackTrace();
Log.v("PdfError", e.toString());
// dialog.dismiss();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.v("PdfError", e.toString());
// dialog.dismiss();
} catch (IOException e) {
e.printStackTrace();
}
Please note that this solution is working fine till Android (10)Q. I have gone through many solution and spend almost a week with this problem. I am testing Android (11)R scenario on Emulator.
Now PDF has created thanks to people who comment on this question
document.close();
// File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf");
File file = new File(dest+"/"+fileName1);
// File file = new File("/" +"Internal storage"+ "/" +"RTS" +"/" + fileName);
if (!file.exists()) {
file.mkdir();
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
((Activity) context).startActivity(intent);
listsOfListReportModelList.clear();
Now unable to open file like this. Saying to make name shorter.