我想在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,所以我无法直接在webview中打开它.
默认情况下,android不支持pdf.
有没有适用于android的API(MuPdf除外)?
我的设备没有安装任何pdf阅读器,因此ACTION VIEW对我没用
以下不工作.......
你可以建议我任何好的api ...
提前致谢...
我们需要一台可以通过蓝牙或wifi连接到Android手机的便携式打印机(手持设备,这很重要).
我需要将PDF文件(PDF页面)转换为Android中的位图(或图像文件).
1.使用Apache的Pdfbox jar.但是它使用了android中不支持的一些java类.2.尝试将图像转换为pdf的Itext jar(我需要它的反向操作)就像我尝试了很多罐子一样.但没有积极的结果.
byte[] bytes;
try {
File file = new File(this.getFilesDir().getAbsolutePath()+"/2010Q2_SDK_Overview.pdf");
FileInputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
ByteBuffer buffer = ByteBuffer.NEW(bytes);
String data = Base64.encodeToString(bytes, Base64.DEFAULT);
PDFFile pdf_file = new PDFFile(buffer);
PDFPage page = pdf_file.getPage(2);
RectF rect = new RectF(0, …Run Code Online (Sandbox Code Playgroud) 目前,我有一个PDF url,我想简单地使用意向来打开它,但是,如果我把它不起作用url在intent
我的代码是这样的,它总是抛出 ActivityNotFoundException 错误
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(law.url), "application/pdf");
try {
startActivity(intent);
} catch (ActivityNotFoundException e){
Utility.showErrorDialog(
ctx,ctx.getResources().getString(R.string.sys_in,
ctx.getResources().getString(R.string.err_no_pdf_reader),
ctx.getResources().getString(R.string.close));
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了goolge doc方法,但是我的客户拒绝了这个,所以我没有使用这种方法
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://docs.google.com/viewer?url="
+ publish.get(Integer.parseInt((String) view.getTag())).pdfURL), "text/html");
ctx.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
感谢帮助
Log cat错误更新
04-23 18:18:50.487: E/AndroidRuntime(17161): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://oshc.zizsoft.com/oshc_testing.pdf typ=application/pdf }
04-23 18:18:50.487: E/AndroidRuntime(17161): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1568)
04-23 18:18:50.487: E/AndroidRuntime(17161): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1439)
04-23 18:18:50.487: E/AndroidRuntime(17161): at android.app.Activity.startActivityForResult(Activity.java:3356)
04-23 18:18:50.487: E/AndroidRuntime(17161): at android.app.Activity.startActivityForResult(Activity.java:3317)
04-23 …Run Code Online (Sandbox Code Playgroud) 我正在开发一个需要在设备中打开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阅读器,我找到了几个API,但它们都不是开源的.
你们中的任何人都知道一个好的免费替代品吗?
头等舱
package android.pdf.reader;
import java.io.File;
import java.io.FilenameFilter;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class First extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
File[] imagelist = images.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return ((name.endsWith(".pdf")));
}
});
String[] pdflist = new String[imagelist.length];
for(int i = 0;i<imagelist.length;i++)
{
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new …Run Code Online (Sandbox Code Playgroud) 我使用下面的链接里面WebView展现出pdf file在我的Android应用程序:
这可以工作,并显示PDF,如附图中所示.我遇到的问题是
我想禁用缩放控件,桌面和下载链接.
这是可能的,如果是的话,怎么样?


我在Android WebView中使用mozilla pdf.js来显示PDF文件.
代码在Android API Level 19中运行良好.
Uri path = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/test.pdf");
webView.loadUrl("file:///android_asset/pdfviewer/index.html?file=" + path);
Run Code Online (Sandbox Code Playgroud)
但它不适用于Android API 16级及以下版本.
设备上显示白色空白屏幕.
有什么方法可以解决这个问题吗?
我有一个 android 应用程序,它基本上是一个接受用户输入的表单。此输入存储在数据库中。但我想用用户输入的信息创建一个 pdf 文件并显示它,以便用户可以打印文件或将文件保存到他们的 android 笔记选项卡。最好的方法是什么。我已经看到了 iText,但这不会呈现文件。我在网上找到了这段代码,并对其进行了测试以了解pdf创建的概念。这使用了 Lowagie 2.1.7
package com.example.sweetiean.androidpdfdemo;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Image;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
private Button createPDF , openPDF;
@Override
protected void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) android ×10
pdf ×7
webview ×2
bluetooth ×1
google-docs ×1
itext ×1
pdf-reader ×1
printers ×1
printing ×1
wifi ×1