Commit 601c4280 authored by 楊慶堂's avatar 楊慶堂

add android code

parent 189f57df
......@@ -21,14 +21,14 @@
let pdfDoc = null;
function createPage() {
const div = document.createElement('canvas');
document.body.appendChild(div);
return div;
const div = document.createElement('canvas');
document.body.appendChild(div);
return div;
}
function renderPage(num) {
pdfDoc.getPage(num).then((page) => {
let scale = 1;
let scale = 2;
let viewport = page.getViewport(scale);
let canvas = createPage();
let ctx = canvas.getContext('2d');
......
package pdfjs.scott.idv.androidpdfjs;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
String pdfUrl = "file:///android_asset/pdf-js-demo.pdf";
mWebView.loadUrl("file:///android_asset/index.html?" + pdfUrl);
}
@SuppressLint("SetJavaScriptEnabled")
private void initView() {
mWebView = findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setSupportZoom(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
}
}
......@@ -4,15 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment