In my application, I have a view with customer details, I want to save that view as image or PDF to SD card then print the view through third party application (Otherwise print that view directly through printer is possible).
I have no idea of how to save view as image or PDF. Can any one know please help me to solve this problem?
Add permission in the manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Use the code below
LinearLayout content = findViewById(R.id.rlid);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file,f;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
if(!file.exists())
{
file.mkdirs();
}
f = new File(file.getAbsolutePath()+file.seperator+ "filename"+".png");
}
FileOutputStream ostream = new FileOutputStream(f);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
}
catch (Exception e){
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With