2

I am working on an application in which a user is allowed to fill up the form only once and next time when ever user views that form it should be in doc type and can be downloaded on its phone.

I do not have any idea on this link is this possible or not .And if its possible then how can it be done.Please suggest me a option or provide some useful links with code

I searched but couldn't find anything useful.

I have used code from following questions

Download and show the Thumbnail

File download on button click?

How to download a pdf file in Android?

But the point where i am lagging is i am not getting a way to convert whole screen into a doc/pdf.

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95

2 Answers2

1

Check out this code to save your screen as image.

private void saveImages() {
    View v = findViewById(R.id.view_images);
    v.setDrawingCacheEnabled(true);

    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will
    // be null
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache

    SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyyMMddHHmmss");
    Date date = new Date();
    String name ="data"+"-"+dateFormat.format(date) + ".png";
    // String imageName = "TEST" + (String) name;

    File folder = new File(Environment.getExternalStorageDirectory()
            + "/.TEST");
    // boolean success = false;
    if (!folder.exists()) {
        folder.mkdir();
    }

    File file = new File(folder + "/TEST" + name);
    try {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        b.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
        Log.d("Done", "Yes");
        Toast.makeText(getApplicationContext(),
                "Images" + name + "save in Sd card", Toast.LENGTH_SHORT)
                .show();
    } catch (Exception e) {
        e.printStackTrace();
        Log.d("Done", "No");
        Toast.makeText(getApplicationContext(),
                "Images in Sd card", Toast.LENGTH_SHORT).show();
    }
    finish();

}
Mitesh Jain
  • 673
  • 1
  • 7
  • 20
0

There have been similar questions in StackOverflow. This should help:

Create PDF / Word (Doc) file within app

This too: Android - creating word document

Community
  • 1
  • 1
Sahand Seifi
  • 225
  • 3
  • 11