我想在webview上显示pdf内容.这是我的代码:
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf");
Run Code Online (Sandbox Code Playgroud)
我得到一个空白的屏幕.我也设置了互联网许可.
我正在研究一些应该能够在我的应用程序中阅读PDF的东西,并且我希望将PDF视图放在我的自定义布局中.我更喜欢Android PDF Viewer但是当我执行zoomIn时,zoomOut需要花费太多时间.
所以目前我应该使用MuPDF开源项目集成到我的项目中,它基于JNI,我不习惯它.
我正在使用Cygwin为本机代码构建库.因此,我不清楚几件事情:
如何在我的项目中整合MuPDF(根据我的问题标题)?
一旦我成功整合它,那么如何将PDF阅读器放入我的自定义视图(在XML或programmaticaly中)?
我正在开发一个需要在设备中打开pdf文件的应用程序,
我实际上在网上获得了与大多数示例类似的代码.但是,问题是我无法打开文件,控件直接进入"异常"部分.
以下是代码:
public class MyPDFDemo extends Activity
{
/** Called when the activity is first created. */
@Override
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("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();
}
}
}
});
} …Run Code Online (Sandbox Code Playgroud) 尝试单击按钮从资源文件夹中打开 pdf 文件
public class CodSecreen extends AppCompatActivity {
PDFView pdfView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cod_secreen);
pdfView=(PDFView)findViewById(R.id.pdf);
Intent intent = getIntent();
String str = intent.getStringExtra("message");
if (str.equals(getResources().getString(R.string.introduction))){
pdfView.fromAsset("phpvariable.pdf").load();
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过传递按钮的字符串值
bttn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str = bttn1.getText().toString();
Intent i=new Intent(DetailSecreen.this,CodSecreen.class);
startActivity(i);
}
});
Run Code Online (Sandbox Code Playgroud)