简体   繁体   中英

Android (4.4 - API 19) App: Print existing PDF without print preview

I am not sure this is a duplicate because all what I found wasn't exactly what I am looking for.

I have an App that has an Activity where the user fills a form (Table layout with textviews and edittexts)

At the bottom there is a Print button which (As of right now) it generates a pdf file using itextpdf and saves it in "/storage/emulated/0/client pqr/pqr.pdf"

What I want to achieve is on that button click, the PDF is generated then sent to a network printer and print without a print preview.

Is this possible? At least possible with print preview?

I am new to this, and not familiar on how to implement the printing custom documents ( https://developer.android.com/training/printing/custom-docs.html#print-adapter ). I am not sure how to implement the print adapter/manager. I saw some pages with code snippet solution but I was not sure which class they go in.

I would really appreciate any help here as I have spent days googling and did not get anywhere.

I created a MyPrintDocumentAdapter, however I am not sure where to do the printing call. From what I gather, it should be done in the onWrite method, but all examples show printing into a file. How and where can I connect to an IP printer and print to it?

A PrintDocumentAdapter and associated PrintJobs are for printing to the user's choice of printer from the available printers on their device.

The simplest solution, therefore, is for you to install the Android "print driver" app from the printer manufacturer. Then, you can use the Android printing framework (eg, PrintDocumentAdapter ) to that printer. Whether there will be print preview or not is up to Android and, possibly, the printer manufacturer.

If the printer manufacturer does not have an Android app that makes their printers available for printing, you would need to either:

  • Create a PrintService yourself that can work with those printers (and that is where you would connect to the IP address and do... something...), so you can use the Android printing framework with those printers, or

  • Bypass Android's printing framework entirely, and just write your own code to send the print job to the printer by one means or another.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM