尝试使用pdfviewer.jar打开时,没有获得pdf的所有内容

时间:2014-03-06 04:24:45

标签: android pdf

enter image description here我尝试使用pdfviewer.jar打开pdf,我收到pdf文件,但显示的内容不完整。我不明白为什么会这样?

我的代码是:

public class PdfActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pdfviewer);

    AssetManager assetManager = getAssets();

    InputStream in = null;
    OutputStream out = null;
    File file = new File(getFilesDir(), "ABC.pdf");

    try {
        in = assetManager.open("ABC.pdf");
        out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    } catch (Exception e) {
        Log.e("tag", e.getMessage());
    }

    Intent intent = new Intent(this, MyPdfViewerActivity.class);
    intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, getFilesDir()
            + "/ABC.pdf");
    startActivity(intent);

}

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);
    }
}
}

pdfViewer的第二课程:

public class MyPdfViewerActivity extends PdfViewerActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // TODO Auto-generated method stub
}

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;
}
}

0 个答案:

没有答案