Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF

TOPIC:

convert pdf to image and print issue 7 years 1 month ago #11919

  • manwon
  • manwon's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 1
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.
Last edit: by manwon.
The topic has been locked.

convert pdf to image and print issue 7 years 1 month ago #11926

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
To show the thumbnail of the first page, please check PDFGridItem.render()

For the print issue, what are the steps to reproduce it?
The topic has been locked.

convert pdf to image and print issue 7 years 1 month ago #11928

  • manwon
  • manwon's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 1
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);
}
The topic has been locked.

convert pdf to image and print issue 7 years 1 month ago #11934

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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?
The topic has been locked.

convert pdf to image and print issue 7 years 1 month ago #11942

  • manwon
  • manwon's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 1
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.
The topic has been locked.

convert pdf to image and print issue 7 years 1 month ago #11944

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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.
The topic has been locked.
Powered by Kunena Forum