开发者

How PDf file can be read through android via coding

开发者 https://www.devze.com 2023-04-03 09:35 出处:网络
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    Button OpenPDF = (Button) findViewById(R.id.button);
    OpenPDF.setOnClickListener(new View.OnClickListener()
    { 
        public void onClick(View v) 
        {
            File pdfFile = new File("res/raw/comic.pdf");
            if(pdfFile.exists()) 
            {
               //Uri path = Uri.fromFile(pdfFile); 
            Uri path = Uri.parse("android.resource://" + getPackageName() + "/ R.raw.comic.pdf");

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(path, "application/pdf");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

               // Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
               // Intent pdfIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://package.name/" + pdfFile));
              //  pdfIntent.setDataAndType(path, "/assets/arduino-comic-latest.pdf");
               // pdfIntent.setType("application/pdf");
               // pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                try
                {
                    startActivity(intent);
                }
                catch(ActivityNotFoundException e)
                {
                    Toast.makeText(MainActivity.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
                }开发者_运维技巧
            }

        }
    });

I have done this code but this is not find the path of the file.what I have to do??can Anyone help me

Thankyou


you cant do that directly, you have to use Native Library for reading PDF... library may be iText, jPedal, Mupdf, Pdfbox... etc. Google it

0

精彩评论

暂无评论...
验证码 换一张
取 消