Skip to content

Commit b4cb9d0

Browse files
committed
Remove visible pages and change priorities, and set default rendering encoding to PNG instead of WebP
1 parent d3af7d5 commit b4cb9d0

3 files changed

Lines changed: 40 additions & 63 deletions

File tree

packages/engines/src/lib/orchestrator/pdf-engine.ts

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
119119
return chunks;
120120
}
121121

122-
/**
123-
* Update visible pages for visibility-based task ranking
124-
*/
125-
setVisiblePages(pages: Array<{ pageIndex: number; visibility: number }>): void {
126-
this.workerQueue.setVisiblePages(pages);
127-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, `Updated visible pages: ${pages.length} pages`);
128-
}
129-
130122
// ========== IPdfEngine Implementation ==========
131123

132124
isSupport(feature: PdfEngineFeature): PdfTask<PdfEngineOperation[]> {
@@ -217,7 +209,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
217209
execute: () => this.executor.getMetadata(doc),
218210
meta: { docId: doc.id, operation: 'getMetadata' },
219211
},
220-
{ priority: Priority.LOW },
212+
{ priority: Priority.MEDIUM },
221213
);
222214
}
223215

@@ -227,7 +219,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
227219
execute: () => this.executor.setMetadata(doc, metadata),
228220
meta: { docId: doc.id, operation: 'setMetadata' },
229221
},
230-
{ priority: Priority.LOW },
222+
{ priority: Priority.MEDIUM },
231223
);
232224
}
233225

@@ -237,7 +229,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
237229
execute: () => this.executor.getDocPermissions(doc),
238230
meta: { docId: doc.id, operation: 'getDocPermissions' },
239231
},
240-
{ priority: Priority.LOW },
232+
{ priority: Priority.MEDIUM },
241233
);
242234
}
243235

@@ -247,7 +239,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
247239
execute: () => this.executor.getDocUserPermissions(doc),
248240
meta: { docId: doc.id, operation: 'getDocUserPermissions' },
249241
},
250-
{ priority: Priority.LOW },
242+
{ priority: Priority.MEDIUM },
251243
);
252244
}
253245

@@ -257,7 +249,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
257249
execute: () => this.executor.getSignatures(doc),
258250
meta: { docId: doc.id, operation: 'getSignatures' },
259251
},
260-
{ priority: Priority.LOW },
252+
{ priority: Priority.MEDIUM },
261253
);
262254
}
263255

@@ -267,7 +259,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
267259
execute: () => this.executor.getBookmarks(doc),
268260
meta: { docId: doc.id, operation: 'getBookmarks' },
269261
},
270-
{ priority: Priority.LOW },
262+
{ priority: Priority.MEDIUM },
271263
);
272264
}
273265

@@ -277,7 +269,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
277269
execute: () => this.executor.setBookmarks(doc, bookmarks),
278270
meta: { docId: doc.id, operation: 'setBookmarks' },
279271
},
280-
{ priority: Priority.LOW },
272+
{ priority: Priority.MEDIUM },
281273
);
282274
}
283275

@@ -287,7 +279,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
287279
execute: () => this.executor.deleteBookmarks(doc),
288280
meta: { docId: doc.id, operation: 'deleteBookmarks' },
289281
},
290-
{ priority: Priority.LOW },
282+
{ priority: Priority.MEDIUM },
291283
);
292284
}
293285

@@ -303,7 +295,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
303295
options,
304296
doc.id,
305297
page.index,
306-
Priority.HIGH,
298+
Priority.CRITICAL,
307299
);
308300
}
309301

@@ -318,7 +310,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
318310
options,
319311
doc.id,
320312
page.index,
321-
Priority.MEDIUM,
313+
Priority.HIGH,
322314
);
323315
}
324316

@@ -332,7 +324,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
332324
options,
333325
doc.id,
334326
page.index,
335-
Priority.LOW,
327+
Priority.MEDIUM,
336328
);
337329
}
338330

@@ -347,7 +339,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
347339
options,
348340
doc.id,
349341
page.index,
350-
Priority.LOW,
342+
Priority.MEDIUM,
351343
);
352344
}
353345

@@ -359,7 +351,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
359351
options?: PdfRenderPageOptions | PdfRenderThumbnailOptions | PdfRenderPageAnnotationOptions,
360352
docId?: string,
361353
pageIndex?: number,
362-
priority: Priority = Priority.HIGH,
354+
priority: Priority = Priority.CRITICAL,
363355
): PdfTask<T> {
364356
const resultTask = new Task<T, PdfErrorReason>();
365357

@@ -430,7 +422,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
430422
execute: () => this.executor.getPageAnnotations(doc, page),
431423
meta: { docId: doc.id, pageIndex: page.index, operation: 'getPageAnnotations' },
432424
},
433-
{ priority: Priority.LOW },
425+
{ priority: Priority.MEDIUM },
434426
);
435427
}
436428

@@ -445,7 +437,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
445437
execute: () => this.executor.createPageAnnotation(doc, page, annotation, context),
446438
meta: { docId: doc.id, pageIndex: page.index, operation: 'createPageAnnotation' },
447439
},
448-
{ priority: Priority.LOW },
440+
{ priority: Priority.MEDIUM },
449441
);
450442
}
451443

@@ -459,7 +451,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
459451
execute: () => this.executor.updatePageAnnotation(doc, page, annotation),
460452
meta: { docId: doc.id, pageIndex: page.index, operation: 'updatePageAnnotation' },
461453
},
462-
{ priority: Priority.LOW },
454+
{ priority: Priority.MEDIUM },
463455
);
464456
}
465457

@@ -473,7 +465,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
473465
execute: () => this.executor.removePageAnnotation(doc, page, annotation),
474466
meta: { docId: doc.id, pageIndex: page.index, operation: 'removePageAnnotation' },
475467
},
476-
{ priority: Priority.LOW },
468+
{ priority: Priority.MEDIUM },
477469
);
478470
}
479471

@@ -534,7 +526,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
534526
meta: { docId: doc.id, pageIndex: page.index, operation: 'getPageTextRects' },
535527
},
536528
{
537-
priority: Priority.LOW,
529+
priority: Priority.MEDIUM,
538530
},
539531
);
540532
}
@@ -607,7 +599,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
607599
execute: () => this.executor.getAttachments(doc),
608600
meta: { docId: doc.id, operation: 'getAttachments' },
609601
},
610-
{ priority: Priority.LOW },
602+
{ priority: Priority.MEDIUM },
611603
);
612604
}
613605

@@ -617,7 +609,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
617609
execute: () => this.executor.addAttachment(doc, params),
618610
meta: { docId: doc.id, operation: 'addAttachment' },
619611
},
620-
{ priority: Priority.LOW },
612+
{ priority: Priority.MEDIUM },
621613
);
622614
}
623615

@@ -627,7 +619,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
627619
execute: () => this.executor.removeAttachment(doc, attachment),
628620
meta: { docId: doc.id, operation: 'removeAttachment' },
629621
},
630-
{ priority: Priority.LOW },
622+
{ priority: Priority.MEDIUM },
631623
);
632624
}
633625

@@ -640,7 +632,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
640632
execute: () => this.executor.readAttachmentContent(doc, attachment),
641633
meta: { docId: doc.id, operation: 'readAttachmentContent' },
642634
},
643-
{ priority: Priority.LOW },
635+
{ priority: Priority.MEDIUM },
644636
);
645637
}
646638

@@ -657,7 +649,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
657649
execute: () => this.executor.setFormFieldValue(doc, page, annotation, value),
658650
meta: { docId: doc.id, pageIndex: page.index, operation: 'setFormFieldValue' },
659651
},
660-
{ priority: Priority.LOW },
652+
{ priority: Priority.MEDIUM },
661653
);
662654
}
663655

@@ -671,7 +663,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
671663
execute: () => this.executor.flattenPage(doc, page, options),
672664
meta: { docId: doc.id, pageIndex: page.index, operation: 'flattenPage' },
673665
},
674-
{ priority: Priority.LOW },
666+
{ priority: Priority.MEDIUM },
675667
);
676668
}
677669

@@ -683,7 +675,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
683675
execute: () => this.executor.extractPages(doc, pageIndexes),
684676
meta: { docId: doc.id, pageIndexes: pageIndexes, operation: 'extractPages' },
685677
},
686-
{ priority: Priority.LOW },
678+
{ priority: Priority.MEDIUM },
687679
);
688680
}
689681

@@ -693,7 +685,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
693685
execute: () => this.executor.extractText(doc, pageIndexes),
694686
meta: { docId: doc.id, pageIndexes: pageIndexes, operation: 'extractText' },
695687
},
696-
{ priority: Priority.LOW },
688+
{ priority: Priority.MEDIUM },
697689
);
698690
}
699691

@@ -708,7 +700,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
708700
execute: () => this.executor.redactTextInRects(doc, page, rects, options),
709701
meta: { docId: doc.id, pageIndex: page.index, operation: 'redactTextInRects' },
710702
},
711-
{ priority: Priority.LOW },
703+
{ priority: Priority.MEDIUM },
712704
);
713705
}
714706

@@ -718,7 +710,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
718710
execute: () => this.executor.getTextSlices(doc, slices),
719711
meta: { docId: doc.id, slices: slices, operation: 'getTextSlices' },
720712
},
721-
{ priority: Priority.LOW },
713+
{ priority: Priority.MEDIUM },
722714
);
723715
}
724716

@@ -728,7 +720,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
728720
execute: () => this.executor.getPageGlyphs(doc, page),
729721
meta: { docId: doc.id, pageIndex: page.index, operation: 'getPageGlyphs' },
730722
},
731-
{ priority: Priority.LOW },
723+
{ priority: Priority.MEDIUM },
732724
);
733725
}
734726

@@ -738,7 +730,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
738730
execute: () => this.executor.getPageGeometry(doc, page),
739731
meta: { docId: doc.id, pageIndex: page.index, operation: 'getPageGeometry' },
740732
},
741-
{ priority: Priority.LOW },
733+
{ priority: Priority.MEDIUM },
742734
);
743735
}
744736

@@ -750,7 +742,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
750742
execute: () => this.executor.merge(files),
751743
meta: { docId: files.map((file) => file.id).join(','), operation: 'merge' },
752744
},
753-
{ priority: Priority.LOW },
745+
{ priority: Priority.MEDIUM },
754746
);
755747
}
756748

@@ -763,7 +755,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
763755
operation: 'mergePages',
764756
},
765757
},
766-
{ priority: Priority.LOW },
758+
{ priority: Priority.MEDIUM },
767759
);
768760
}
769761

@@ -773,7 +765,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
773765
execute: () => this.executor.preparePrintDocument(doc, options),
774766
meta: { docId: doc.id, operation: 'preparePrintDocument' },
775767
},
776-
{ priority: Priority.LOW },
768+
{ priority: Priority.MEDIUM },
777769
);
778770
}
779771

@@ -783,7 +775,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
783775
execute: () => this.executor.saveAsCopy(doc),
784776
meta: { docId: doc.id, operation: 'saveAsCopy' },
785777
},
786-
{ priority: Priority.LOW },
778+
{ priority: Priority.MEDIUM },
787779
);
788780
}
789781

@@ -793,7 +785,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
793785
execute: () => this.executor.closeDocument(doc),
794786
meta: { docId: doc.id, operation: 'closeDocument' },
795787
},
796-
{ priority: Priority.LOW },
788+
{ priority: Priority.MEDIUM },
797789
);
798790
}
799791

@@ -803,7 +795,7 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
803795
execute: () => this.executor.closeAllDocuments(),
804796
meta: { operation: 'closeAllDocuments' },
805797
},
806-
{ priority: Priority.LOW },
798+
{ priority: Priority.MEDIUM },
807799
);
808800
}
809801
}

packages/engines/src/lib/orchestrator/task-queue.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class WorkerTaskQueue {
6868
private queue: QueuedTask<any>[] = [];
6969
private running = 0;
7070
private resultTasks = new Map<string, Task<any, any, any>>();
71-
private visiblePages = new Map<number, number>();
7271
private logger: Logger;
7372
private opts: Required<Omit<WorkerTaskQueueOptions, 'comparator' | 'ranker' | 'logger'>> & {
7473
comparator?: TaskComparator;
@@ -364,22 +363,8 @@ export class WorkerTaskQueue {
364363
});
365364
}
366365

367-
private defaultRank(task: QueuedTask<any>): number {
368-
const pageIndex = task.meta?.pageIndex as number | undefined;
369-
if (pageIndex === undefined) return 0;
370-
371-
const visibility = this.visiblePages.get(pageIndex) ?? 0;
372-
return visibility * 1000;
373-
}
374-
375-
setVisiblePages(pages: Array<{ pageIndex: number; visibility: number }>): void {
376-
this.visiblePages.clear();
377-
for (const { pageIndex, visibility } of pages) {
378-
this.visiblePages.set(pageIndex, visibility);
379-
}
380-
if (this.queue.length > 0 && !this.opts.comparator) {
381-
this.sortQueue();
382-
}
366+
private defaultRank(_task: QueuedTask<any>): number {
367+
return 0;
383368
}
384369

385370
private generateId(): string {

packages/plugin-render/src/lib/render-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapabilit
6868
...(options ?? {}),
6969
withForms: options?.withForms ?? this.config.withForms ?? false,
7070
withAnnotations: options?.withAnnotations ?? this.config.withAnnotations ?? false,
71-
imageType: options?.imageType ?? this.config.defaultImageType ?? 'image/webp',
71+
imageType: options?.imageType ?? this.config.defaultImageType ?? 'image/png',
7272
imageQuality: options?.imageQuality ?? this.config.defaultImageQuality ?? 0.92,
7373
};
7474

@@ -92,7 +92,7 @@ export class RenderPlugin extends BasePlugin<RenderPluginConfig, RenderCapabilit
9292
...(options ?? {}),
9393
withForms: options?.withForms ?? this.config.withForms ?? false,
9494
withAnnotations: options?.withAnnotations ?? this.config.withAnnotations ?? false,
95-
imageType: options?.imageType ?? this.config.defaultImageType ?? 'image/webp',
95+
imageType: options?.imageType ?? this.config.defaultImageType ?? 'image/png',
9696
imageQuality: options?.imageQuality ?? this.config.defaultImageQuality ?? 0.92,
9797
};
9898

0 commit comments

Comments
 (0)