Annotate text in pdf

303 Views Asked by At
  • I am trying to edit an existing pdf in my Android App by adding text. For displaying a pdf I am using this PdfViewer library.

  • Here in this library I see one option enableAnnotationRendering which takes boolean value. No matter whatever value true or false I set, PDFViewer doesn't show annotation options anywhere.

  • How can I annotate a text in pdf?

Here is my code:

Dependency:

implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

MainActiity.java:

public class MainActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener,
        OnPageErrorListener  {

    PDFView pdfView;
    String pdfFileName;
    public static final String SAMPLE_FILE = "sample.pdf";
    Integer pageNumber = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pdfView = findViewById(R.id.pdfView);
        displayFromAsset(SAMPLE_FILE);
    }

    private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .spacing(10) // in dp
                .onPageError(this)
                .pageFitPolicy(FitPolicy.BOTH)
                .load();
    }

    @Override
    public void loadComplete(int nbPages) {

    }

    @Override
    public void onPageChanged(int page, int pageCount) {

    }

    @Override
    public void onPageError(int page, Throwable t) {

    }

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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" />

</RelativeLayout>
0

There are 0 best solutions below