mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Unify the ReadableStream
and TextContent
code-paths in src/display/text_layer.js
The only reason that this code still accepts `TextContent` is for backward-compatibility purposes, so we can simplify the implementation by always using a `ReadableStream` internally.
This commit is contained in:
parent
b6765403a1
commit
049848ba00
3 changed files with 88 additions and 51 deletions
|
@ -58,5 +58,47 @@ describe("textLayer", function () {
|
|||
"",
|
||||
"page 1 / 3",
|
||||
]);
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("creates textLayer from TextContent", async function () {
|
||||
if (isNodeJS) {
|
||||
pending("document.createElement is not supported in Node.js.");
|
||||
}
|
||||
const loadingTask = getDocument(buildGetDocumentParams("basicapi.pdf"));
|
||||
const pdfDocument = await loadingTask.promise;
|
||||
const page = await pdfDocument.getPage(1);
|
||||
|
||||
const textContentItemsStr = [];
|
||||
|
||||
const textLayerRenderTask = renderTextLayer({
|
||||
textContentSource: await page.getTextContent(),
|
||||
container: document.createElement("div"),
|
||||
viewport: page.getViewport({ scale: 1 }),
|
||||
textContentItemsStr,
|
||||
});
|
||||
expect(textLayerRenderTask instanceof TextLayerRenderTask).toEqual(true);
|
||||
|
||||
await textLayerRenderTask.promise;
|
||||
expect(textContentItemsStr).toEqual([
|
||||
"Table Of Content",
|
||||
"",
|
||||
"Chapter 1",
|
||||
" ",
|
||||
"..........................................................",
|
||||
" ",
|
||||
"2",
|
||||
"",
|
||||
"Paragraph 1.1",
|
||||
" ",
|
||||
"......................................................",
|
||||
" ",
|
||||
"3",
|
||||
"",
|
||||
"page 1 / 3",
|
||||
]);
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue