DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.13k stars 1.9k forks source link

How to add background image in every page? #612

Open bleedweedsuz opened 6 years ago

bleedweedsuz commented 6 years ago

How to add background image in every page? [small question]

[elaborate question] I'm doing a project where i need to change background, default we have white background instead of that i want to add image or bitmap. I read this issue #299 but ArvidNy said that we need to customize the source code. But i want to use onDrawAll(onDrawListener) to set background image. i can't convert the canvas to bitmap. i only can draw in it, if i do that it will replace render data. (here is some snippet code)

pdfView.fromUri(Uri.parse(path))
.enableAntialiasing(true)
.onDrawAll(new OnDrawListener() {
    @Override
    public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
        Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.RGB_565); //low res

        Paint paint = new Paint();
        paint.setColor(Color.RED);
        //....
        //Do something with bitmap [colorfilter, ColorMatrixColorFilter....]
        //..
        canvas.drawBitmap(bitmap, 0,0, paint);
    }
})
.load();

PDFView pdfView; [it is just a view]

i know it's a beta but if you could just add bitmap in that parameter it would be awesome. OR am i missing something. It's been 8 hours i just can't figure it out. any help would be awesome. :smiley_cat: :metal:

1stmetro commented 6 years ago

just alter the alpha and have a bitmap below the viewer or watermark it both are simple enough to implement.

bleedweedsuz commented 6 years ago

that thought came into my mind and i already did that but doing that page became weird, so i go with the color. but if i have a bitmap that would be awesome i can manipulate raw bitmap and can also switch color like a night mode [other color effects]. any way my problem is solved i didn't go with image just the color. thanks for the reply :metal: