Reputation: 612
I am super new to Kotlin app development and I am trying to make an app which generates & sends a PDF to print directly to the once chosen printer... I'm using PdfDocument
library to generate a PDF using my printPDF
function -
//necessary imports
private fun generatePDF(text: String) {
val fileName = "badge.pdf"
val pdfDocument = PdfDocument()
val pageInfo = PdfDocument.PageInfo.Builder(288, 432, 1).create()
// .... pdf building code here
val downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
val badgesDir = File(downloadsDir, "Badges")
if (!badgesDir.exists()) {
badgesDir.mkdirs()
}
val file = File(badgesDir, fileName)
pdfDocument.writeTo(file.outputStream())
pdfDocument.close()
Toast.makeText(this, "success: ${file.path}", Toast.LENGTH_LONG).show()
//toast prints like - "success: /storage/emulated/0/Download/Badges/badge.pdf"
}
The above generatePDF
function creates & stores the PDF in/as Download > Badges > badge.pdf
, which I can access by going into the Download folder in my phone's file manager.
After the toast, I want to send it directly to the printer to get printed, without any page-setup/confirmation/customisation dialogs intervening the process. It would be like I choose the printer once & for all at the very first print, and then it should just directly print the document without asking for choosing printers. So far I've read some stuff about PrintDocumentAdapter
, but can't wrap my head around it if it's the one I want and how to implement it....
Is this possible to do in Kotlin, sending a document to be directly printed?
Upvotes: 0
Views: 175