Java 在项目中实现pdf阅读器时获取空白pdf
我试图通过git hub的pdf库实现pdf阅读器,但是当我实现代码时。。我得到的只是一张空白页。。url是正确的pdf有内容,这与此q类似 我的代码由多个方法组成,主方法用于选择要显示的pdf。然后将pdf名称传递给方法“copyreadassets” openpdfintentmethod用于打开值Java 在项目中实现pdf阅读器时获取空白pdf,java,android,pdf,Java,Android,Pdf,我试图通过git hub的pdf库实现pdf阅读器,但是当我实现代码时。。我得到的只是一张空白页。。url是正确的pdf有内容,这与此q类似 我的代码由多个方法组成,主方法用于选择要显示的pdf。然后将pdf名称传递给方法“copyreadassets” openpdfintentmethod用于打开值 private void openPdfIntent(String path) { // TODO Auto-generated method stub try {
private void openPdfIntent(String path) {
// TODO Auto-generated method stub
try {
final Intent intent = new Intent(Question_Point_Main.this, Pdf.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
类包含以下内容
public class Pdf extends Activity{
public int getPreviousPageImageResource() {
return R.drawable.left_arrow; }
public int getNextPageImageResource() {
return R.drawable.right_arrow; }
public int getZoomInImageResource() {
return R.drawable.zoom_in; }
public int getZoomOutImageResource() {
return R.drawable.zoom_out; }
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password; }
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber; }
public int getPdfPasswordEditField() {
return R.id.etPassword; }
public int getPdfPasswordOkButton() {
return R.id.btOK; }
public int getPdfPasswordExitButton() {
return R.id.btExit; }
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit; }
}在您的AndroidManifest.xml文件中
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<activity android:name="com.example.readassetpdf.myPDFActivity"></activity>
并将其命名如下
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
CopyReadAssets("mypdf.pdf");
}
copyfile的功能如下所示
private void copyFile(InputStream in, OutputStream out) throws IOException{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
替代品是
out = getApplicationContext().openFileOutput(file.getName(),
Context.MODE_WORLD_READABLE);
到
[您可以尝试此示例,它对我有效][1][1]:抱歉,我的系统登录设备的聊天被阻止,因为它可能会因为以下原因发生:memory@poojagupta是的,在它的设备上显示一个xml,其中包含我在绘图文件夹中的所有图像,我没有创建…嗨,我按照你的要求做了,但它显示正在加载pdf页面,并继续加载,没有任何更改。。(在emulator上)在我的设备上加载一段时间后,会显示一个页面,该页面基本上是我所有xml的组合。。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
CopyReadAssets("mypdf.pdf");
}
private void copyFile(InputStream in, OutputStream out) throws IOException{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
out = getApplicationContext().openFileOutput(file.getName(),
Context.MODE_WORLD_READABLE);
out=new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/mypdf.pdf");