How can I display a pdf document into a TextView?

徘徊边缘 提交于 2020-01-07 05:31:05

问题


I want to read pdf files and display contents on TextView. is it possible ? or just show pdf into WebView or pdfViewer?

i want to do like it,

public class MainActivity extends Activity {

private TextView showText;
String url="http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    showText= (TextView)this.findViewById(R.id.showtext);
    showText.setText( ++ convertPdfTotext ++);


}


public void convertPdfTotext(View view)
{

}

}

回答1:


If you want to use it in text view you can convert it with itext as string,but you'll loose formatting:

    PdfTextExtractor parser =new PdfTextExtractor(new PdfReader("C:/Text.pdf"));
parser.getTextFromPage(3);

Use WebView instead and you can enable even zoom.

WebView mWebView=new WebView(MyPdfViewActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+LinkTo);


来源:https://stackoverflow.com/questions/25739313/how-can-i-display-a-pdf-document-into-a-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!