Add configurable PDF viewer options and improve rendering
Introduced `PdfViewerOptions` class to centralize PDF viewer settings such as scaling, HiDPI support, zoom transitions, and rendering delays. Bound these options to `appsettings.json` for dynamic configuration. Injected `PdfViewerOptions` into `EnvelopeViewer.razor` and updated `OnInitializedAsync` to pass settings to JavaScript. Replaced hardcoded values in `pdf-viewer.js` with configurable options, improving maintainability and flexibility. Enhanced rendering logic to respect HiDPI settings, maximum DPR, and smooth zoom transitions. Improved thumbnail rendering with configurable delays to optimize performance.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
@inject DocumentService DocumentService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IOptions<ApiOptions> AppOptions
|
||||
@inject IOptions<PdfViewerOptions> PdfViewerOptions
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject AnnotationService AnnotService
|
||||
@implements IAsyncDisposable
|
||||
@@ -236,6 +237,21 @@ protected override async Task OnInitializedAsync() {
|
||||
|
||||
try {
|
||||
_dotNetRef = DotNetObjectReference.Create(this);
|
||||
|
||||
// Send quality options to JavaScript
|
||||
var options = PdfViewerOptions.Value;
|
||||
await JSRuntime.InvokeVoidAsync("pdfViewer.setQualityOptions", new
|
||||
{
|
||||
options.ThumbnailBaseScale,
|
||||
options.ThumbnailEnableHiDPI,
|
||||
options.ThumbnailMaxDPR,
|
||||
options.MainCanvasEnableHiDPI,
|
||||
options.MainCanvasMaxDPR,
|
||||
options.EnableSmoothZoom,
|
||||
options.ZoomTransitionDuration,
|
||||
options.RenderingOpacity
|
||||
});
|
||||
|
||||
var success = await JSRuntime.InvokeAsync<bool>("pdfViewer.initialize", "pdf-canvas", _pdfDataUrl, _dotNetRef);
|
||||
|
||||
if (success) {
|
||||
@@ -337,13 +353,15 @@ protected override async Task OnInitializedAsync() {
|
||||
|
||||
async Task RenderThumbnailsAsync() {
|
||||
try {
|
||||
var delay = PdfViewerOptions.Value.ThumbnailRenderDelay;
|
||||
|
||||
// Sequential rendering to avoid overwhelming the browser
|
||||
for (int i = 1; i <= _totalPages; i++) {
|
||||
await JSRuntime.InvokeVoidAsync("pdfViewer.renderThumbnail", i, $"thumb-canvas-{i}");
|
||||
|
||||
// Small delay between renders to keep UI responsive
|
||||
// Configurable delay between renders
|
||||
if (i < _totalPages) {
|
||||
await Task.Delay(50);
|
||||
await Task.Delay(delay);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user