DEV Community

nikoo li
nikoo li

Posted on

Designing a PDF Compressor Around a Constraint, Not a Percentage

Most PDF compressor interfaces expose a quality slider or a compression percentage. That is easy to explain, but it does not match the constraint users meet in real upload flows: a form accepts files only up to a fixed number of megabytes.

I built a small tool around that constraint. The user provides a PDF and a target size, and the server searches compression configurations until it finds the closest result it can produce. The important product decision is not the slider; it is making the acceptance limit the primary input.

The workflow

The request contains two values:

  • the uploaded PDF;
  • targetMB, the maximum size the user needs to meet.

The compression pipeline first tries a vector-preserving path. If the target cannot be reached, it can fall back to a rasterized PDF with a lower resolution or image quality. The UI reports when a very small target may reduce visible quality, and it does not pretend that every PDF can reach every target.

The result is evaluated by bytes, not by a claimed percentage:

reachedTarget = resultBytes <= targetBytes
Enter fullscreen mode Exit fullscreen mode

That boolean is more useful to a submitting user than “compressed by 62%,” because it answers the question the upload form will ask next.

Failure modes matter

The less visible part of the implementation is the job lifecycle. PDF processing invokes external tools, so a request can fail in several ways:

  • the input is malformed;
  • the target is too aggressive for the source document;
  • an external process takes too long;
  • the hosting instance restarts during a job.

For that reason, each compression task has a queue, a phase, an overall timeout, and a terminal success or error state. A timed-out child process is terminated instead of leaving the UI in an endless “processing” state. Server-side analytics also treats an old start event without a terminal event as an interrupted job rather than a successful conversion.

This is a small example of a broader product lesson: when a workflow ends at an external constraint, the constraint should be represented directly in the interface and in the job model.

TinyPDF is available at https://tinypdf.cn/?utm_source=devto&utm_medium=designer_promo&utm_campaign=portfolio_upload_limits&utm_content=devto_target_size_20260824

It is a focused tool rather than a public API. Users open the website and upload their own file; the temporary upload is automatically deleted after about an hour.

Top comments (0)