From be7672469929d9e884b07c25c90ae646a7f08cbe Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Sat, 28 Sep 2024 17:38:59 +0800 Subject: [PATCH] PDF: fix text selection --- pdf.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pdf.js b/pdf.js index 8e49a34..0ebfacb 100644 --- a/pdf.js +++ b/pdf.js @@ -47,6 +47,15 @@ const render = async (page, doc, zoom) => { display: 'none', }) + // fix text selection + // https://github.com/mozilla/pdf.js/blob/642b9a5ae67ef642b9a8808fd9efd447e8c350e2/web/text_layer_builder.js#L105-L107 + const endOfContent = document.createElement('div') + endOfContent.className = 'endOfContent' + container.append(endOfContent) + // TODO: this only works in Firefox; see https://github.com/mozilla/pdf.js/pull/17923 + container.onpointerdown = () => container.classList.add('selecting') + container.onpointerup = () => container.classList.remove('selecting') + const div = doc.querySelector('.annotationLayer') await new pdfjsLib.AnnotationLayer({ page, viewport, div }).render({ annotations: await page.getAnnotations(),