将活动另存为 PDF,但会生成空的 pdf 文件

如何解决将活动另存为 PDF,但会生成空的 pdf 文件

这是我的活动,我想将此活动另存为 pdf 或图像,任何人都可以帮助我解决这个问题我曾尝试另存为 pdf 代码,但它生成了空的 pdf 文件和我想要的活动代码生成PDF文件如下

package com.example.conceptsimilarity;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.print.PrintDocumentAdapter;
import android.print.PrintManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.chaquo.python.PyObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class result extends AppCompatActivity {
 TextView txtwords,txtspellmistake,txtper,txtper2,txtstop,txtwordper,totnumber,obtainnumber,spell,totalnumberofsenindoc,gr;
 Button savefile;
    @SuppressLint("ResourceType")
    @RequiresApi(api = Build.VERSION_CODES.M)
   // @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        txtwords=findViewById(R.id.textnowords);
        txtspellmistake=findViewById(R.id.textspell);
        txtper=findViewById(R.id.textpercentage);
        txtper2=findViewById(R.id.textpercentage2);
        txtstop=findViewById(R.id.textpercentage4);
        txtwordper=findViewById(R.id.textpercentage3);
        totnumber=findViewById(R.id.total);
        obtainnumber=findViewById(R.id.obtain);
        spell=findViewById(R.id.spellingmistake);
        savefile=findViewById(R.id.save);
        totalnumberofsenindoc=findViewById(R.id.totalnuberofsentencesindoc);
        gr=findViewById(R.id.grade);

        String sent;
        int wordsixty;
         int sentthirty,grammermistakes,spellmistakeinword,word = 0,sentence=0;
        int perword=0;
        int persent = 0;
        int i=100;
        int toalnumberindoc=0;
        int limitindoc=0;


        Intent intent=getIntent();
        String obje=intent.getStringExtra("numberwords");
        String grammerchecker=intent.getStringExtra("spellmistake");
        String wordsimilaritys=intent.getStringExtra("wordsimilarity");
        String countstop=intent.getStringExtra("stop");
        String sentence_count=intent.getStringExtra("sentence_count");
        String dfsimilarity=intent.getStringExtra("defitionsimilarity");
        String docsentencecount=intent.getStringExtra("docsentcount");
        String spellmistake=intent.getStringExtra("wordspelling");
        String docnumberwords=intent.getStringExtra("filenumberofwords");

        //word similarity percentage is in dbw
        String dbw=intent.getStringExtra("datacount");
        String totalnum=intent.getStringExtra("totalnumber");
        float word_value=Integer.parseInt(wordsimilaritys);
        float word_count=Integer.parseInt(countstop);
        float def_value=Integer.parseInt(dfsimilarity);
        float sent_count=Integer.parseInt(sentence_count);
        int spellint=Integer.parseInt(spellmistake);
        int grammerint=Integer.parseInt(grammerchecker);
        int totalnumber=Integer.parseInt(totalnum);
        float percentageofwords=Float.parseFloat(dbw);
        toalnumberindoc=Integer.parseInt(obje);
        limitindoc=Integer.parseInt(docnumberwords);

        double sentence_percentage = (double) Math.round((def_value/sent_count)*100);
        if (sentence_percentage>100){
            sentence_percentage=100;
        }


        sent=Double.toString(sentence_percentage);

        wordsixty= (int ) (percentageofwords*60)/i;
        sentthirty=(int) ((sentence_percentage*40)/i);
        //spelling mistakes (cuting from word percentage)
        //grammer mistakes (cutting from sentences)
        //grammar*100/total sent

        grammermistakes=  (grammerint*40/Integer.parseInt(docsentencecount));
        spellmistakeinword= (int) (spellint*60/word_count);

        Toast.makeText(this,""+docsentencecount+"",Toast.LENGTH_LONG).show();


        if (wordsixty!=0||sentthirty!=0){
             perword= (int) (percentageofwords-spellmistakeinword);
             persent= (int) (sentence_percentage-grammermistakes);
            word= (wordsixty-spellmistakeinword);
            sentence=(sentthirty- grammermistakes);
        }

               // Toast.makeText(this,""+wordsimilaritys,Toast.LENGTH_LONG).show();

        float scorefinal=((word+sentence)*totalnumber)/100;
        totnumber.setText(totalnum);

        float gradepercentage=0;

        if(toalnumberindoc >limitindoc)
        {
            txtwords.setText(obje);
            txtwords.setTextColor(getResources().getColor(R.color.Red));
        }
        else {
            txtwords.setText(obje);
        }

        gradepercentage=scorefinal*100/totalnumber;

        if(gradepercentage>=90)
        {
            gr.setText("A+");
        }
        else if(gradepercentage>=80 && gradepercentage<90)
        {
            gr.setText("A");
        }
        else if(gradepercentage>=70 && gradepercentage<80)
        {
            gr.setText("B");
        }
        else if(gradepercentage>=60 && gradepercentage<70)
        {
            gr.setText("C");
        }
        else if(gradepercentage>=50 && gradepercentage<60)
        {
            gr.setText("D");
        }
        else
        {
            gr.setText("F");
            gr.setTextColor(getResources().getColor(R.color.Red));
        }



        txtspellmistake.setText(grammerchecker);
        txtstop.setText(countstop);
        txtper.setText(wordsimilaritys);
        txtper2.setText(Integer.toString(persent)+"%");
        txtwordper.setText(Integer.toString(perword)+"%");
        obtainnumber.setText(Float.toString( scorefinal));
        spell.setText(Integer.toString(spellint));
        totalnumberofsenindoc.setText(docsentencecount);
//       Toast.makeText(this," "+totalnum,Toast.LENGTH_LONG).show();

    }

    @Override
    public void onBackPressed() {
        finish();
        startActivity(new Intent(this,documentupload.class));
    }

   @RequiresApi(api = Build.VERSION_CODES.KITKAT)
   private void createpdf()
   {

           PdfDocument myPdfDocument=new PdfDocument();
               Paint myPaint=new Paint();
               PdfDocument.PageInfo myPageInfo1=new PdfDocument.PageInfo.Builder(1200,2010,1).create();
               PdfDocument.Page myPage1=myPdfDocument.startPage(myPageInfo1);
               Canvas canvas=myPage1.getCanvas();

               myPdfDocument.finishPage(myPage1);

               File file=new File(Environment.getExternalStorageDirectory(),"result.pdf");
               try {
                   myPdfDocument.writeTo(new FileOutputStream(file));
               }catch (IOException e){
                   e.printStackTrace();
               }
               myPdfDocument.close();
               Toast.makeText(result.this,"Save "+file,Toast.LENGTH_SHORT).show();

           }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void save(View view) {
        createpdf();
    }

我在活动中创建了一个 createpdf() 方法,但它不起作用,并且此活动是滚动活动,活动的屏幕截图将位于

This is the activity and i want to save this activity data as pdf

这是活动,我想将此活动数据保存为 pdf

this activity is a scroll activity this is remaining part

此活动是滚动活动,这是剩余部分

This is the pdf file which is generated but it is empty

这是生成的pdf文件,但它是空的

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res