简体   繁体   English

Android中的PDF渲染

[英]PDF rendering in android

I am newbie to android and development world. 我是android和开发世界的新手。 I need help to solve this problem.(scenario as follows) 我需要帮助来解决此问题。(方案如下)

I have created one android app using HTML5 and CSS and bundle it out using phonegap. 我使用HTML5和CSS创建了一个Android应用,并使用phonegap将其捆绑了。 Now I need to display PDF file in this app with two options for user whether first download and then read or second read online 现在,我需要在此应用程序中显示PDF文件,并为用户提供两个选项: 首先下载然后 在线 阅读还是第二次在线阅读

So My problem is, I am not able to dispaly PDF in app. 所以我的问题是,我无法在应用程序中显示PDF。 How could I achieve this? 我怎样才能做到这一点? please help . 请帮忙 。 I am trying to solve it from last 4 days and tried out each and solution which is already given in forum , but still no success. 我正在尝试从最近的4天开始解决它,并尝试了已经在论坛中给出的每个解决方案,但仍然没有成功。

It would be great for me if someone ans step by step procedure or one example to refer. 如果有人一步一步地举个例子或举个例子,对我来说太好了。

Thank You Minal 谢谢你

This may help: How to open a PDF via Intent from SD card 这可能会有所帮助: 如何通过SD卡中的Intent打开PDF

The basic idea is to get a pdf app to render the pdf for you, and your app just kicks off an intent to do that. 基本思想是获得一个pdf应用程序来为您呈现pdf,而您的应用程序正是以此为出发点的。

try this code 试试这个代码

private void openBook() {
    File file = new File(mRealPath);
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setDataAndType(path, getString(R.string.application_type));
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(FirstTab.this, 
                getString(R.string.no_application_found), 
                Toast.LENGTH_SHORT).show();
    }
}

您可以通过这样的意图打开pdf文件

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file),”application/pdf”); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM