I am trying to open local Pdf file from Assest folder in android studio platform using [barteksc] library. I downloaded the library and managed to open the pdf file. However, when I orient the emulator to landscape mode the pdf width will not fit the screen. I googled the issue and the solution is to use the following piece of code.
Configurator.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int pages, float pageWidth, float pageHeight) {
pdfView.fitToWidth(); // optionally pass page number
}
});
But, I do not know how to implement this code. I wrote the following :
public class Pdf extends AppCompatActivity {
PDFView pdfview;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pdf);
pdfview=(PDFView)findViewById(R.id.pdfView);
pdfview.fromAsset("h.pdf").load();
PDFView.Configurator.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int pages, float pageWidth, float pageHeight) {
pdfview.fitToWidth(); // optionally pass page number
}
});
}
}
And I got this error ...
Non-static method 'onRender(com.github.barteksc.pdfviewer.listener.OnRenderListener)' cannot be referenced from a static context
Plese show me how can I fix this issue. Loads of thanks in advance for any help you may lend.
The code below shows how to use that method
pdfView.fromAsset(SAMPLE_FILE)
.defaultPage(pageNumber)
.enableSwipe(true)
.enableDoubletap(true)
.swipeVertical(false)
.showMinimap(false)
.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int pages, float pageWidth,
float pageHeight) {
pdfview.fitToWidth(); // optionally pass page number
}
});
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.load();