我正在尝试在我的应用程序中打开一个 pdf 文件。我的问题是我无法阅读该文档,因为它出现了奇怪的字符。另外,如果我显示一个 txt 文件,我可以阅读它,但它的文本并不像我想要的那样对齐。所有的线都居中。我的问题是我做错了什么,我该如何纠正这些错误?
我的 xml
<!-- Demonstrates styled string resources.
     See corresponding Java code com.android.sdk.content.StyledText -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="normal" />
</LinearLayout>
</ScrollView>
和班级
public class PrimulAjutor2A extends MainActivity2A
{
    @Override
  protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
       // See assets/res/any/layout/styled_text.xml for this
       // view layout definition.
        setContentView(R.layout.primulajutor2);
        // Programmatically load text from an asset and place it into the
       // text view.  Note that the text we are loading is ASCII, so we
       // need to convert it to UTF-16.
       try {
           InputStream is = getAssets().open("abc.pdf");
            // We guarantee that the available method returns the total
            // size of the asset...  of course, this does mean that a single
           // asset can't be more than 2 gigs.
            int size = is.available();
            // Read the entire asset into a local byte buffer.
            byte[] buffer = new byte[size];
           is.read(buffer);
            is.close();
           // Convert the buffer into a string.
           String text = new String(buffer);
            // Finally stick the string into the text view.
           TextView tv = (TextView)findViewById(R.id.text);
            tv.setText(text);
        } catch (IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }
    }}
