A PDF whose header carries a Word- or Excel-style gradient background is not a picture the renderer can copy: the blend is a vector construct that has to be evaluated before it turns into pixels. HotPDF's page renderer honours the PDF sh (shading) operator for Type 2 axial and Type 3 radial gradients: it evaluates the shading's function along the gradient axis, paints an axial blend as a run of solid colour bands and a radial blend as smoothly shaded triangles. Those two shading types cover almost every office-document gradient, and this article walks through the function chain, the banding tradeoff and the bitmap call that sit behind them
Why can a PDF gradient render as a white box?
A PDF gradient is a vector construct, not a bitmap the renderer can blit. A shading dictionary (ISO 32000-1 §8.7.4.5) describes the geometry — an axis or a pair of circles in the Coords array — plus a colour function, and the sh operator paints that shading across the current clip region, the same graphics model HotPDF exposes when you draw paths and fills onto a page canvas. A page renderer walks the content stream operator by operator, and the usual policy for an operator without a code path is to skip it so the rest of the page still renders. That policy is exactly what turns a gradient into a white box: if sh lands in the skipped set, a header or full-page gradient contributes nothing to the output and the background shows through. The file is not corrupt. A white box is what a missing handler looks like, which is why HotPDF routes sh to a dedicated shading painter inside the same operator walk
The function evaluation chain behind a shading
A shading cannot be painted until its function is evaluated, so the function engine is the real foundation. Type 2 axial and Type 3 radial shadings both carry a /Function that maps a parametric position along the gradient into a colour (ISO 32000-1 §7.10), and HotPDF's function evaluator resolves the FunctionType and dispatches on it. Type 2 exponential interpolation (§7.10.3) computes C0 + t^N * (C1 - C0) with Domain and Range clamping; Type 0 sampled functions (§7.10.2) read a grid of 8-, 16-, or 32-bit samples and pick the nearest through the Encode map, the case covered in depth in our walkthrough of Type 0 sampled colour lookups; Type 3 stitching functions (§7.10.4) select a sub-function by the Bounds array and recurse into it. Type 4 PostScript calculator functions (§7.10.5) run through the same evaluator that drives Separation tint transforms, and a function that cannot be evaluated reports failure rather than a wrong colour, the conservative policy HotPDF takes across the render path. The shading painter is only as good as the function underneath it
How does HotPDF turn a continuous gradient into pixels?
HotPDF approximates an axial blend with a finite run of solid-colour bands. The shading painter projects the clip region onto the gradient axis, gives the visible stretch one band per device pixel of axis length — never fewer than 8 and never more than 512 — evaluates the function at each band's midpoint, and fills a strip perpendicular to the axis with a solid brush. The tradeoff is band count against fill cost: 512 is the deliberate ceiling, and below it the count tracks the axis length in device pixels, so resolution matters. Rendering the same page at a higher DPI lengthens the axis, so a short gradient gains bands and its stripes soften until the ceiling is reached. Radial shadings skip the stripes entirely: the painter splits the parameter range adaptively until each midpoint colour is within two 8-bit levels of the interpolated one, slices every ring into angular segments sized to its on-screen radius, and paints each segment as a pair of Gouraud-shaded triangles
// The axial discretiser uses one colour band per device pixel of visible
// axis, clamped to 8..512 bands. Rendering the same page at a higher DPI
// lengthens that axis, so a short gradient gains bands and the banding
// softens until the 512-band ceiling is hit. Radial shadings are painted
// as Gouraud-shaded triangles instead, so they show no band stripes
Thumb := Pdf.RenderLoadedPageToBitmap(PageIndex, 96); // coarser bands
Proof := Pdf.RenderLoadedPageToBitmap(PageIndex, 300); // up to 512 bands
Rendering a shaded page to a bitmap
The public entry point is unchanged: RenderLoadedPageToBitmap takes a zero-based page index and a DPI value, returns a caller-owned 24-bit bitmap, and hands back nil on failure rather than raising, so shading support needs no extra calls: a page with a gradient header comes back with the blend painted in. The one thing worth remembering is ownership: the caller frees the returned bitmap. The full rendering pipeline — content-stream interpretation, embedded glyphs, and page caching — is covered in the guide to rendering PDF pages to a bitmap in Delphi
var
Pdf: THotPDF;
Bmp: TBitmap;
begin
Pdf := THotPDF.Create(nil);
try
if Pdf.LoadFromFile('quarterly-report.pdf') > 0 then
begin
// Page 1 (zero-based) at 150 DPI. A gradient-filled header
// comes back with its colour blend painted in.
Bmp := Pdf.RenderLoadedPageToBitmap(0, 150);
if Assigned(Bmp) then
try
Bmp.SaveToFile('page1.bmp');
finally
Bmp.Free;
end;
end;
finally
Pdf.Free;
end;
end;
A cheap smoke check falls out of the same call. Render the page, sample a pixel where the gradient band belongs, and confirm it is not paper-white — a one-line check that the shading actually painted instead of letting the background show through
Bmp := Pdf.RenderLoadedPageToBitmap(0, 150);
if Assigned(Bmp) then
try
// True when the sh operator painted; False if the region fell back to white.
HeaderPainted := Bmp.Canvas.Pixels[Bmp.Width div 2, 8] <> clWhite;
finally
Bmp.Free;
end;
Which gradients the shading painter covers
Type 2 axial and Type 3 radial shadings are what office suites, reporting tools and slide exporters emit for gradient fills. For the documents most Delphi and C++Builder teams actually process — reports, invoices, statements, and slide decks exported to PDF — those two types cover essentially every gradient you will meet, and the banding and triangulation rules above are the ones that decide how smooth they look in the output bitmap. The same sh dispatch also routes Type 1 function-based shadings to their own painter and hands the four mesh types — free-form and lattice-form Gouraud triangle meshes (Types 4 and 5) and Coons and tensor-product patch meshes (Types 6 and 7) — to a dedicated mesh renderer, so design-heavy files with mesh gradients render through the same RenderLoadedPageToBitmap call
HotPDF's page renderer, the sh operator support described here, and the function evaluator underneath it ship as part of the HotPDF Delphi Component for Delphi and C++Builder — a native VCL library with no external DLL dependencies, covering PDF creation, editing, text extraction, and page rendering in one package