Can we use it on PDF?
I want to use it on PDF file can i do that?
@ashvinstech Yes
Is there a sample project with pdf?
Sorry, I don't have sample for PDF, if someone has that, please share, thanks a lot!
I had implemented it with Android PdfRenderer But it was having glitch issues. So I used https://github.com/harism/android-pagecurl it worked real smooth with pdf.
You can modify this method to use it with pdf. private void drawPage(final int number) It's in SinglePageRender
private void drawPage(final int number) {
int width = canvas.getWidth();
int height = canvas.getHeight();
Paint p = new Paint();
p.setFilterBitmap(true);
Bitmap background = PdfRendererUtility.pdfToBitmap(context, pdfLocation, number - 1);
Rect rect = new Rect(0, 0, width, height);
canvas.drawBitmap(background, null, rect, p);
background.recycle();
}
The Utility Class is used to convert the pdf pages to bitmap.
public class PdfRendererUtility {
/**
* Calculate Total PDF File Pages Number
*
* @param pdfFile File object to pdf file
* @return 0 if failed to open the pdf file
*/
public static int pdfTotalPages(String pdfFile) {
int pages = 0;
try {
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(new File(pdfFile), ParcelFileDescriptor.MODE_READ_ONLY));
pages = renderer.getPageCount();
renderer.close();
} catch (Exception e) {
e.printStackTrace();
}
return pages;
}
/**
* Generate Bitmap of PDF Specified Page.
*
* @param context context to read the file
* @param pdfFile File object to pdf file
* @return null if couldn't Read pdf file.
*/
public static Bitmap pdfToBitmap(Context context, String pdfFile, int pageNumber) {
Bitmap bitmap = null;
try {
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(new File(pdfFile), ParcelFileDescriptor.MODE_READ_ONLY));
Page page = renderer.openPage(pageNumber);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
bitmap = Bitmap.createBitmap(displayMetrics.widthPixels, displayMetrics.heightPixels, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap, 0, 0, null);
page.render(bitmap, null, null, RENDER_MODE_FOR_DISPLAY);
page.close();
renderer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return bitmap;
}
}
check out my implementation here, https://github.com/shittu33/Dynamic-Page-Flip. it's built on eschao pageFlip. with this you can use an xml layout or use pdfium library.
I want to use double page rendering to read txt files. Is there a similar example?
Oops, I have not cater for that at the moment.
On Mon, 19 Jun 2023, 04:15 CoolChimpanzee, @.***> wrote:
I want to use double page rendering to read txt files. Is there a similar example?
— Reply to this email directly, view it on GitHub https://github.com/eschao/android-PageFlip/issues/64#issuecomment-1596431592, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGGK7RJZX4HGXH6UVHUKSLDXL673RANCNFSM42N6XZRQ . You are receiving this because you commented.Message ID: @.***>