Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Print report from app with Google Cloud Print

I am developing an android application in eclipse to print a report via Google Cloud Print. This tutorial from Google has me on the right track.
I have already installed itext to generate the Report.pdf

My problem is in the "print" element of my applications UI. Google supplies this code:

Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);

With the message:

"In the code above, replace the three parameters as follows: docUri - URI of the document to be printed docMimeType - MIME type of the document to be printed. We recommend that you use PDF (application/pdf) format docTitle - title of the printed document, arbitrary string that will be shown on the GCP management console as the print job's title

My PDF is saved at /data/Student/StudentReportPDF.pdf

I have tried changing the docUri, docMimeType and docTitle has follows: With no luck

Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(StudentReportPDF, .pdf);
printIntent.putExtra("title", Student Report);
startActivity(printIntent);

All 3 elements result in red squigglies.

Can someone spot my mistake or I guess clarify these 3 elements for me?

printing eclipse-plugin pdf-generation itext google-cloud-print

like image 659
UPGRAYEDD Avatar asked Jan 26 '26 13:01

UPGRAYEDD


1 Answers

Big thanks to DragonRancher via Reddit

dragonrancher 1 point 1 hour ago When using the Java language, you need to put your strings between double quotes, otherwise they are interpreted as identifiers. Your putExtra line should probably look like:

printIntent.putExtra("title", "Student Report");

The setDataAndType line has other issues though. According to the documentation, the setDataAndType method requires a Uri object and a string containing a MIME type. In this case, you might be able to use the Uri.fromFile or Uri.parse methods to get a Uri object from your filename, and the MIME type for PDFs is application/pdf:

printIntent.setDataAndType(Uri.fromFile(new File("Report.pdf")), "application.pdf");

I don't actually have any experience with Android, so someone else might be able to better comment on determining the path for your report file.

like image 124
UPGRAYEDD Avatar answered Jan 28 '26 07:01

UPGRAYEDD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!