Skip to content

fix(pdf): apply color filters when exporting to PDF on android - #718

Merged
farfromrefug merged 1 commit into
ossappscollective:mainfrom
jvandenbroek:fix/695-pdf-export-color-filters
Sep 10, 2026
Merged

farfromrefug merged 1 commit into
ossappscollective:mainfrom
jvandenbroek:fix/695-pdf-export-color-filters

Conversation

@jvandenbroek

@jvandenbroek jvandenbroek commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Exported PDFs kept the original page colors even when a color adjustment (grayscale, b&w, sepia, invert, polaroid, or a brightness/contrast tweak — anything that produces a non-null colorMatrix) was applied in the app before exporting. Other adjustments like "improve" go through a different path and were unaffected. The linked issue reports it for grayscale/b&w specifically, but the bug is in the shared colorMatrix application, so it affects any filter/adjustment.

loadImage() in PDFUtils.kt applies the page's colorMatrix by building a Canvas backed by the same bitmap it then draws onto:

val canvas = android.graphics.Canvas(bmp)
canvas.drawBitmap(bmp, 0F, 0F, paint)

Source and destination bitmap being identical is undefined behavior on Android, so the color filter never reliably made it into the encoded output. Render into a separate bitmap instead and swap references.

Testing

  • Built a debug APK from this branch and installed it on a physical device: scanned a page, applied grayscale/b&w, exported to PDF — the exported PDF now correctly shows the filtered colors (previously showed the original colors).

Refs #695

loadImage() applied the page's colorMatrix (grayscale, b/w, ...) by
building a Canvas backed by the same bitmap it then drew onto:

    val canvas = android.graphics.Canvas(bmp)
    canvas.drawBitmap(bmp, 0F, 0F, paint)

Source and destination bitmap being identical is undefined behavior
on Android and effectively drops the color filter, so exported PDFs
kept the original colors even when a page had grayscale/b&w applied
in the app (other adjustments like "improve" go through a different
path and were unaffected). Render into a separate bitmap instead.

Refs ossappscollective#695
@farfromrefug
farfromrefug merged commit 3fbc89b into ossappscollective:main Sep 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants