<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
 
</LinearLayout>
cs

 

 

public class PdfViewerActivity extends AppCompatActivity {
 
    PDFView mPDFView;
 
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdfviewer);
 
        mPDFView = findViewById(R.id.pdfView);
        // assets 폴더에 있는 pdf 파일읽기
        mPDFView.fromAsset("SampleTest.pdf")
                .enableSwipe(true)      // 스와이프로 페이지 넘김
                .swipeHorizontal(false// true-가로로 넘김, false-세로로 넘김
                .enableDoubletap(true)  // 화면을 두번 탭하여 확대/축소
                .load();
 
    }
}
cs

 - assets폴더에 SampleTest.pdf 파일을 포함시키고 로드

 

 

implementation ("com.github.mhiew:android-pdf-viewer:3.2.0-beta.3")
 
cs

 

 

결과

 

+ Recent posts