【问题标题】:Convert Screen contents to Doc format and then let user download that doc on phone将屏幕内容转换为文档格式,然后让用户在手机上下载该文档
【发布时间】:2012-04-08 15:32:18
【问题描述】:

我正在开发一个应用程序,在该应用程序中,当用户查看该表单时,它应该是文档类型,并且可以在手机上下载。

我不知道此链接是否可能。如果可能,那么如何完成。请建议我一个选项或提供一些有用的代码链接

我搜索了但找不到任何有用的东西。

我使用了以下问题的代码

Download and show the Thumbnail

File download on button click?

How to download a pdf file in Android?

但我落后的地方是我没有办法将整个屏幕转换为 doc/pdf。

【问题讨论】:

    标签: android download doc


    【解决方案1】:

    查看此代码以将您的屏幕另存为图像。

    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();
    
    }
    

    【讨论】:

      【解决方案2】:

      StackOverflow 中也有类似的问题。这应该会有所帮助:

      Create PDF / Word (Doc) file within app

      这也是: Android - creating word document

      【讨论】:

        猜你喜欢
        • 2015-02-19
        • 2021-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多