在我的应用程序,我有客户的详细信息视图,我要救这个观点作为图像或PDF格式的SD卡,然后打印通过第三方应用程序的视图(否则打印视图直接通过打印机是可能的)。
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).
我不知道如何保存查看图片或PDF格式。任何人能知道,请帮我解决这个问题呢?
I have no idea of how to save view as image or PDF. Can any one know please help me to solve this problem?
添加权限清单文件
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用以下
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();
}