- Posts: 36
- Thank you received: 1
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
convert pdf to image and print issue
9 years 3 weeks ago - 9 years 3 weeks ago #11919
by manwon
convert pdf to image and print issue was created by manwon
First, I have a list view to show all pdf document. And I want to show the pdf first page image in the list view.
For example:
[test,png] test.pdf
[test2.png] test2.pdf
How can I convert the first page to png ?
Second, I clicked the print button. I got a error message.
E/PrintManagerīš Error announcing destroyed state
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.print.IPrintDocumentAdapterObserver$Stub$Proxy.onDestroy(IPrintDocumentAdapterObserver.java:79)
at android.print.PrintManager$PrintDocumentAdapterDelegate.onActivityDestroyed(PrintManager.java:682)
at android.app.Application.dispatchActivityDestroyed(Application.java:245)
at android.app.Activity.onDestroy(Activity.java:1455)
at com.radaee.reader.PDFViewAct.onDestroy(PDFViewAct.java:315)
at android.app.Activity.performDestroy(Activity.java:5403)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3588)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3619)
at android.app.ActivityThread.access$1400(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1299)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5151)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
at dalvik.system.NativeStart.main(Native Method)
How can I fix it?
Thanks.
For example:
[test,png] test.pdf
[test2.png] test2.pdf
How can I convert the first page to png ?
Second, I clicked the print button. I got a error message.
E/PrintManagerīš Error announcing destroyed state
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.print.IPrintDocumentAdapterObserver$Stub$Proxy.onDestroy(IPrintDocumentAdapterObserver.java:79)
at android.print.PrintManager$PrintDocumentAdapterDelegate.onActivityDestroyed(PrintManager.java:682)
at android.app.Application.dispatchActivityDestroyed(Application.java:245)
at android.app.Activity.onDestroy(Activity.java:1455)
at com.radaee.reader.PDFViewAct.onDestroy(PDFViewAct.java:315)
at android.app.Activity.performDestroy(Activity.java:5403)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3588)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3619)
at android.app.ActivityThread.access$1400(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1299)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5151)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
at dalvik.system.NativeStart.main(Native Method)
How can I fix it?
Thanks.
Last edit: 9 years 3 weeks ago by manwon.
9 years 3 weeks ago #11926
by nermeen
Replied by nermeen on topic convert pdf to image and print issue
To show the thumbnail of the first page, please check PDFGridItem.render()
For the print issue, what are the steps to reproduce it?
For the print issue, what are the steps to reproduce it?
9 years 3 weeks ago #11928
by manwon
Replied by manwon on topic convert pdf to image and print issue
Hello
I pressed the print button to call printPDF function. I saw the print UI in the device a few seconds. It crashed.
I put some log for debug.
It cannot call onLayout and onWrite method.
private void printPDF() {
Log.e("print", "printpdf");
PrintManager mPrintManager = (PrintManager) m_parent.getContext().getSystemService(Context.PRINT_SERVICE);
Log.e("print", "printmanager");
mPrintManager.print(m_parent.getContext().getString(R.string.app_name) + " PDF Document", new PrintDocumentAdapter() {
int mTotalPages = 0;
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal,
LayoutResultCallback callback, Bundle extras) {
mTotalPages = m_view.PDFGetDoc().GetPageCount();
Log.e("print", "onLayout");
if (cancellationSignal.isCanceled() ) { // Respond to cancellation request
callback.onLayoutCancelled();
return;
}
if (mTotalPages > 0) { // Return print information to print framework
PrintDocumentInfo info = new PrintDocumentInfo
.Builder("print_output.pdf")
.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
.setPageCount(mTotalPages)
.build();
// Content layout reflow is complete
callback.onLayoutFinished(info, true);
} else { // Otherwise report an error to the print framework
callback.onLayoutFailed("Page count calculation failed.");
}
}
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal,
WriteResultCallback callback) {
Log.e("print", "onWrite");
InputStream input;
OutputStream output;
try {
String mDocPath = m_view.PDFGetDoc().getDocPath();
if(!TextUtils.isEmpty(mDocPath)) {
input = new FileInputStream(mDocPath);
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
// check for cancellation
if (cancellationSignal.isCanceled()) {
callback.onWriteCancelled();
input.close();
output.close();
return;
}
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
input.close();
output.close();
} else
callback.onWriteFailed("PDF File is not available");
} catch (Exception e) {
e.printStackTrace();
callback.onWriteFailed(e.toString());
}
}
}, null);
}
I pressed the print button to call printPDF function. I saw the print UI in the device a few seconds. It crashed.
I put some log for debug.
It cannot call onLayout and onWrite method.
private void printPDF() {
Log.e("print", "printpdf");
PrintManager mPrintManager = (PrintManager) m_parent.getContext().getSystemService(Context.PRINT_SERVICE);
Log.e("print", "printmanager");
mPrintManager.print(m_parent.getContext().getString(R.string.app_name) + " PDF Document", new PrintDocumentAdapter() {
int mTotalPages = 0;
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal,
LayoutResultCallback callback, Bundle extras) {
mTotalPages = m_view.PDFGetDoc().GetPageCount();
Log.e("print", "onLayout");
if (cancellationSignal.isCanceled() ) { // Respond to cancellation request
callback.onLayoutCancelled();
return;
}
if (mTotalPages > 0) { // Return print information to print framework
PrintDocumentInfo info = new PrintDocumentInfo
.Builder("print_output.pdf")
.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
.setPageCount(mTotalPages)
.build();
// Content layout reflow is complete
callback.onLayoutFinished(info, true);
} else { // Otherwise report an error to the print framework
callback.onLayoutFailed("Page count calculation failed.");
}
}
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal,
WriteResultCallback callback) {
Log.e("print", "onWrite");
InputStream input;
OutputStream output;
try {
String mDocPath = m_view.PDFGetDoc().getDocPath();
if(!TextUtils.isEmpty(mDocPath)) {
input = new FileInputStream(mDocPath);
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
// check for cancellation
if (cancellationSignal.isCanceled()) {
callback.onWriteCancelled();
input.close();
output.close();
return;
}
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
input.close();
output.close();
} else
callback.onWriteFailed("PDF File is not available");
} catch (Exception e) {
e.printStackTrace();
callback.onWriteFailed(e.toString());
}
}
}, null);
}
9 years 3 weeks ago #11934
by nermeen
Replied by nermeen on topic convert pdf to image and print issue
Are you facing this issue with certain pdfs, or all?
Can you replicate this issue with the latest demo project ?
Are you facing this issue with certain devices, or all?
Can you replicate this issue with the latest demo project ?
Are you facing this issue with certain devices, or all?
9 years 3 weeks ago #11942
by manwon
Replied by manwon on topic convert pdf to image and print issue
Hello
I used the latest radaeepdf sample 3.10. I used the open from assets(read only) option. And call the print function. The apps also be crash.
I used the latest radaeepdf sample 3.10. I used the open from assets(read only) option. And call the print function. The apps also be crash.
9 years 3 weeks ago #11944
by nermeen
Replied by nermeen on topic convert pdf to image and print issue
The problem is in case of assets(read only), the print is not supported.
Does it happen also with files from the device?
If yes, please send us a file, and indicate the print driver you are using..
If you want to print file from assets, you need to change the implementation of PrintManager and provide the content of the file to it.
Does it happen also with files from the device?
If yes, please send us a file, and indicate the print driver you are using..
If you want to print file from assets, you need to change the implementation of PrintManager and provide the content of the file to it.
Time to create page: 0.425 seconds