Skip to content

fix(send): generate JPEGThumbnail for PDF documents sent via /send/media#84

Open
fernandopaes0 wants to merge 3 commits into
evolution-foundation:mainfrom
fernandopaes0:pr/pdf-thumbnail
Open

fix(send): generate JPEGThumbnail for PDF documents sent via /send/media#84
fernandopaes0 wants to merge 3 commits into
evolution-foundation:mainfrom
fernandopaes0:pr/pdf-thumbnail

Conversation

@fernandopaes0

Copy link
Copy Markdown

Problem

PDF documents sent via /send/media show no preview thumbnail in WhatsApp — the recipient sees a generic document icon.

Solution

Added a makePDFThumbnail helper that rasterizes the first page of the PDF using pdftoppm (poppler-utils) at 200px width, then encodes the result as JPEG via makeJPEGThumbnail.

  • Requires poppler-utils installed on the host (or Docker image)
  • Graceful fallback: if pdftoppm is unavailable or PDF is invalid, returns nil and send proceeds normally
  • No external network calls; entirely local processing

Dockerfile note

If using the official Docker image, add to your Dockerfile:

RUN apt-get update && apt-get install -y poppler-utils && rm -rf /var/lib/apt/lists/*

Testing

Unit tests added in pkg/sendMessage/service/thumbnail_test.go:

  • Graceful fallback on invalid PDF input
  • Real rasterization test (skipped when pdftoppm not present in CI)

Note: this PR builds on top of 82 (image JPEGThumbnail), since it reuses the makeJPEGThumbnail helper introduced there. Please merge that one first.

fernandopaes0 and others added 3 commits June 15, 2026 08:26
Images sent through SendMediaFile and SendMediaUrl were delivered without
a JPEGThumbnail, so clients (notably iOS) showed no inline preview until
the full image finished downloading.

This adds a reusable makeJPEGThumbnail helper that decodes the source
bytes, resizes to a 72px-wide preview preserving aspect ratio (never
upscaling), and JPEG-encodes it at quality 50. The helper is wired into
the image branch of both SendMediaFile and SendMediaUrl (newsletter and
normal paths). The existing inline thumbnail logic in SendCarousel is
refactored to reuse the same helper.

Thumbnail generation is best-effort: if decoding or encoding fails the
helper returns nil and the message is sent without a preview rather than
failing the request.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PDF documents sent through SendMediaFile and SendMediaUrl had no inline
preview thumbnail, so clients showed a generic document icon instead of a
preview of the first page.

This adds a makePDFThumbnail helper that rasterizes page 1 of the PDF
with the external pdftoppm tool (poppler-utils) and re-encodes the result
through makeJPEGThumbnail for a consistent preview. The thumbnail is wired
into the document branch of both SendMediaFile and SendMediaUrl when the
detected mime type is application/pdf.

The feature degrades gracefully: if pdftoppm is not installed or
rasterization fails, the helper returns nil and the document is sent
without a preview rather than panicking or returning an error.

Note: poppler-utils must be available in the runtime image for this to
take effect (see Dockerfile).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a custom Dockerfile that mirrors the upstream build and installs
poppler-utils (pdftoppm) in the runtime image, which is required for the
PDF document thumbnail feature. Kept separate from the upstream Dockerfile.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fernandopaes0, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

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.

1 participant