@@ -13,6 +13,7 @@ import java.io.File
13
13
internal class PDFRegionDecoder (private val view : PDFView ,
14
14
private val file : File ,
15
15
private val scale : Float ,
16
+ private val borderSize : Float = 0.0f , // size in mm, zero to skip drawing
16
17
@param:ColorInt private val backgroundColorPdf : Int = Color .WHITE ) : ImageRegionDecoder {
17
18
18
19
private lateinit var descriptor: ParcelFileDescriptor
@@ -41,12 +42,6 @@ internal class PDFRegionDecoder(private val view: PDFView,
41
42
val numPageAtEnd = Math .ceil(rect.bottom.toDouble() / pageHeight).toInt() - 1
42
43
val bitmap = Bitmap .createBitmap(rect.width() / sampleSize, rect.height() / sampleSize, Bitmap .Config .ARGB_8888 )
43
44
val canvas = Canvas (bitmap)
44
- val pageBorderPaint = Paint ().apply () {
45
- color = Color .BLACK
46
- style = Paint .Style .STROKE
47
- isAntiAlias = true // for lines thinner than 1
48
- strokeWidth = 0.5f * 160f / 25.4f / sampleSize // = 0.5 mm
49
- }
50
45
canvas.drawColor(backgroundColorPdf)
51
46
canvas.drawBitmap(bitmap, 0f , 0f , null )
52
47
for ((iteration, pageIndex) in (numPageAtStart.. numPageAtEnd).withIndex()) {
@@ -58,9 +53,16 @@ internal class PDFRegionDecoder(private val view: PDFView,
58
53
(- rect.left / sampleSize).toFloat(), - ((rect.top - pageHeight * numPageAtStart) / sampleSize).toFloat() + (pageHeight.toFloat() / sampleSize) * iteration)
59
54
page.render(bitmap,null , matrix, PdfRenderer .Page .RENDER_MODE_FOR_DISPLAY )
60
55
page.close()
61
- val pageBorderRect = RectF (0f , 0f , page.width.toFloat(), page.height.toFloat())
62
- matrix.mapRect(pageBorderRect)
63
- canvas.drawRect(pageBorderRect, pageBorderPaint)
56
+ if (borderSize > 0 ) {
57
+ val pageBorderRect = RectF (0f , 0f , page.width.toFloat(), page.height.toFloat())
58
+ matrix.mapRect(pageBorderRect)
59
+ canvas.drawRect(pageBorderRect, Paint ().apply () {
60
+ color = Color .BLACK
61
+ style = Paint .Style .STROKE
62
+ isAntiAlias = true // for lines thinner than 1
63
+ strokeWidth = borderSize * 160f / 25.4f / sampleSize // = 0.5 mm
64
+ })
65
+ }
64
66
}
65
67
}
66
68
return bitmap
0 commit comments