Add quality control for PDF rendering pipeline
Introduce a `qualityPercent` parameter to control the quality of rendered PDF page images. Updated `IPdfPageImageRenderer` and its implementation to support this parameter, normalizing it within defined bounds and dynamically adjusting rendering DPI. Updated `PdfRenderController` to accept an optional `qualityPercent` query parameter, propagate it through the pipeline, and include it in cache keys. Modified `PdfRenderService` to construct API requests with the quality parameter. Added `CreateEnvelopeWizardRenderOptions` with a default `PreviewQualityPercent` of 55% for rendering previews in `CreateEnvelopeWizardPopup`. Adjusted caching logic and cache key format to account for quality-specific results.
This commit is contained in:
@@ -10,8 +10,10 @@ namespace EnvelopeGenerator.Infrastructure.Doc;
|
||||
public class PdfPageImageRenderer : IPdfPageImageRenderer
|
||||
{
|
||||
private const float RenderDpi = 110f;
|
||||
private const int MinQualityPercent = 10;
|
||||
private const int MaxQualityPercent = 100;
|
||||
|
||||
public Task<IReadOnlyList<PdfPageImageDto>> RenderPagesAsImagesAsync(byte[] pdfBytes, CancellationToken cancellationToken = default)
|
||||
public Task<IReadOnlyList<PdfPageImageDto>> RenderPagesAsImagesAsync(byte[] pdfBytes, int qualityPercent = 100, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(pdfBytes);
|
||||
|
||||
@@ -26,7 +28,9 @@ public class PdfPageImageRenderer : IPdfPageImageRenderer
|
||||
if (pages.Count == 0)
|
||||
return Task.FromResult<IReadOnlyList<PdfPageImageDto>>(Array.Empty<PdfPageImageDto>());
|
||||
|
||||
var renderOptions = PdfPageRenderingParameters.CreateWithResolution(RenderDpi);
|
||||
var normalizedQuality = Math.Clamp(qualityPercent, MinQualityPercent, MaxQualityPercent);
|
||||
var effectiveDpi = RenderDpi * (normalizedQuality / 100f);
|
||||
var renderOptions = PdfPageRenderingParameters.CreateWithResolution(effectiveDpi);
|
||||
var results = new List<PdfPageImageDto>(pages.Count);
|
||||
|
||||
for (var i = 0; i < pages.Count; i++)
|
||||
|
||||
Reference in New Issue
Block a user