Document display scheme arrangement in Android App

Posted by CoffeeOD on Wed, 11 Dec 2019 16:51:02 +0100

I. Word, Excel, PPT display

1. Microsoft Office open Api interface

If the document content is not very confidential or just needs to preview the document, you can consider using Microsoft's public Api interface.

Microsoft Office public Api address: https://view.officeapps.live.com/op/view.aspx?

The implementation on Android is as follows:

First, splice the preview address URL:

https://view.officeapps.live.com/op/view.aspx?src=http://xxx.pptx

Then use WebView to load the URL. The recommended configuration is as follows:

WebSettings settings = mWebView.getSettings();
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setSaveFormData(true);
settings.setSavePassword(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportZoom(true);

/*
 * Support HTTPS and HTTP mixed mode
 * http://blog.csdn.net/qq_16472137/article/details/54346078
 */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}

// Priority rendering interface
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

// Technical settings
settings.setSupportMultipleWindows(true);

settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAppCacheEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheMaxSize(8 * 1024 * 1024); // Cache can be up to 8 M

/* Mobile phones that support cookies above 5.0 do not support automatic synchronization of third-party cookies
 *(Generally, the page in iframe should store the settings of cookies.)
 * http://blog.sina.com.cn/s/blog_6e73239a0102viku.html
 */
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
}

// WebView Supported by default cookies
CookieManager.getInstance().setAcceptCookie(true);

Note: this way of use is to splice the URL of the document to the connection to realize online preview of the office file without downloading the file.

But there are the following problems:

  • If you use Microsoft's preview interface, your document url address will be exposed and the so-called document security will be lost.
  • If the file is too large, the loading speed is very slow, sometimes it can't be loaded out.

2. Browse Paas service with documents

The service representatives are: Tencent TBS browsing service (free), baidu DOC service (charging).

Corresponding address: https://x5.tencent.com,https://cloud.baidu.com/doc/DOC/s/hjwvypsgp

Tencent TBS needs to download files ourselves, and then invoke the TbsReadView method to load.

Problems:

a) the loading function is not stable, some models are loaded normally, and some models are loaded with problems. The most common problem is not supported by:xxx, which greatly affects the user experience.

b) if Tencent products are not installed, TBS service cannot be used, because Tencent products are all based on X5 kernel, and TBS service is also based on X5 kernel.

Baidu DOC service does not need to download by itself. The logic is relatively simple, but it needs to be charged.

Existing problems: unknown (/ / TODO has not done anything to try to access at present, and it will be sorted out after the subsequent access experience)

II. PDF display

1. Use Tencent TBS service

This scheme is basically the same as the scheme of office file loading, and the existing problems are the same. Here is more details.

2. AndroidPdfViewer

Open source project address: https://github.com/barteksc/AndroidPdfViewer

Development reference article: https://www.cnblogs.com/qixingchao/p/11658226.html

3. PdfViewPager

Open source project address: https://github.com/voghDev/PdfViewPager

Topics: Android github Excel Mobile