Android Question How to get BipMap from PDfFile

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have an Pdfviewer control in my application.I would like to make bitpmap for first page of pdf file.I have tried below code but its not working.Please check below code and advise how to do that....


B4X:
Dim pdfv As PDFViewer
pdfv.init
pdfv.getpdf("\mnt\sdcard\Test.pdf")
ImageView1.Bitmap= pdfv.getPageBitmap(1, 1.0, 0, 0, 0, 100, 100)
 

DonManfred

Expert
Licensed User
Longtime User
below code but its not working
Did you get any error?
B4X:
getPageBitmap (page As Int, zoom As Int, x As Int, y As Int, rotation As Int, prefXSize As Int, prefYSize As Int)
At first i would try to change the size units. Try to use 100dip, 100dip instead of just 100

You can try to use PDFRenderer. There is an Example showing the pages as Bitmap....
 
Last edited:
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
sorry again..

it works fine in Android 5.1 but when I run the same application in Android 7.1.2 it shows an error message as

Logger connected to: Xiaomi Redmi 4
--------- beginning of system
--------- beginning of crash
--------- beginning of main
** Activity (main) Create, isFirst = true **
autoversion: 290.0
compilation time: 02/22/2018 18:11:38
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
** Activity (main) Create, isFirst = true **
autoversion: 290.0
compilation time: 02/22/2018 18:11:38
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
entry_cmdbrowse_click (java line: 561)
java.lang.IllegalArgumentException: Invalid page index
at android.graphics.pdf.PdfRenderer.throwIfPageNotInDocument(PdfRenderer.java:266)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:219)
at de.donmanfred.PDFRendererwrapper.renderPageforDisplay(PDFRendererwrapper.java:79)
at com.cabinet.entry._cmdbrowse_click(entry.java:561)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
java.lang.IllegalArgumentException: Invalid page index
** Activity (main) Create, isFirst = true **
autoversion: 290.0
compilation time: 02/22/2018 18:11:38
** Activity (main) Resume **
Copying updated assets files (3)
** Activity (main) Create, isFirst = true **
autoversion: 292.0
compilation time: 02/22/2018 18:14:03
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
** Activity (entry) Pause, UserClosed = false **
** Activity (entry) Resume **
Error occurred on line: 448 (Main)
java.lang.IllegalArgumentException: Invalid page index
at android.graphics.pdf.PdfRenderer.throwIfPageNotInDocument(PdfRenderer.java:266)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:219)
at de.donmanfred.PDFRendererwrapper.renderPageforDisplay(PDFRendererwrapper.java:79)
at com.cabinet.entry._cmdbrowse_click(entry.java:740)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 293.0
compilation time: 02/22/2018 18:15:41
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 295.0
compilation time: 02/22/2018 18:16:48
** Activity (main) Resume **
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 296.0
compilation time: 02/22/2018 18:17:25
** Activity (main) Resume **
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 297.0
compilation time: 02/22/2018 18:17:38
** Activity (main) Resume **
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 298.0
compilation time: 02/22/2018 18:18:13
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
Error occurred on line: 176 (Entry)
java.lang.IllegalArgumentException: Invalid page index
at android.graphics.pdf.PdfRenderer.throwIfPageNotInDocument(PdfRenderer.java:266)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:219)
at de.donmanfred.PDFRendererwrapper.renderPageforDisplay(PDFRendererwrapper.java:79)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
** Activity (main) Create, isFirst = true **
autoversion: 299.0
compilation time: 02/22/2018 18:20:11
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
entry_cmdbrowse_click (java line: 561)
java.lang.IllegalArgumentException: Invalid page index
at android.graphics.pdf.PdfRenderer.throwIfPageNotInDocument(PdfRenderer.java:266)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:219)
at de.donmanfred.PDFRendererwrapper.renderPageforDisplay(PDFRendererwrapper.java:79)
at com.cabinet.entry._cmdbrowse_click(entry.java:561)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
java.lang.IllegalArgumentException: Invalid page index
** Activity (main) Create, isFirst = true **
autoversion: 299.0
compilation time: 02/22/2018 18:20:11
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
autoversion: 299.0
compilation time: 02/22/2018 18:20:11
** Activity (main) Resume **
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
autoversion: 302.0
compilation time: 02/22/2018 18:24:41
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (entry) Create, isFirst = true **
** Activity (entry) Resume **
Error occurred on line: 176 (Entry)
java.lang.IllegalArgumentException: Invalid page index
at android.graphics.pdf.PdfRenderer.throwIfPageNotInDocument(PdfRenderer.java:266)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:219)
at de.donmanfred.PDFRendererwrapper.renderPageforDisplay(PDFRendererwrapper.java:79)
at com.cabinet.entry._cmdbrowse_click(entry.java:740)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…