When I print my pdf made with iText the resolution is so low. I tried set compress to increment quality with: pdfWritter.compressionLevel = 0 but no lucky. I look for better quality of the pdf to print. Actually only it has letters and it won't change.
CreatePDF.kt
val folder = File(context.externalCacheDir?.absolutePath.toString())
if (!folder.exists()) folder.mkdirs()
pdfFile = File(folder, "$fileName.pdf")
document = Document(PageSize.LETTER, 0F, 0F, 0F, 0F)
pdfWritter.compressionLevel = 0
pdfWritter = PdfWriter.getInstance(document,FileOutputStream(pdfFile))
document.open()
document.add(Paragraph("Dra. Mariana Castro", DefaultFont)
document.close()
val intent = Intent(context, ViewPDFActivity::class.java)
intent.putExtra("path",pdfFile.absolutePath)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
ViewPDFActivity.kt
class ViewPDFActivity : AppCompatActivity() {
private lateinit var file:File
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view_pdf)
val bundle: Bundle? = intent.extras
if(bundle != null){
file = File(bundle.getString("path",""))
}
pdfViewAct.fromFile(file)
.enableSwipe(true)
.swipeHorizontal(false)
.enableDoubletap(true)
.enableAntialiasing(true)
.load()
printPDF.setOnClickListener {
val v: View = pdfViewAct
val bmp =
Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888)
val c = Canvas(bmp)
v.draw(c)
val photoPrinter = PrintHelper(this)
photoPrinter.scaleMode = PrintHelper.SCALE_MODE_FIT
if (bundle != null) {
bundle.getString("path")?.let { it1 -> photoPrinter.printBitmap(it1, bmp) }
}
}
backButton.setOnClickListener {
finish()
}
}
activity_view_pdf.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.subactivities.ViewPDFActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/printPDF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Imprimir" />
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.google.android.material.button.MaterialButton
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cm_button_back" />
</LinearLayout>
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfViewAct"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.github.barteksc.pdfviewer.PDFView>
</LinearLayout>
The pdf created is this:PDF Result. The quality is poor even if I increase the page size with pageSize.A0.
Some idea of fix this? I've tried everything. Thanks in advance.