Skip to content

Commit c02aedc

Browse files
authored
Merge pull request #7 from anthrax63/feature/text
feat: implemented methods for extracting text from page and also search text on the page
2 parents 315fc40 + 9a453bd commit c02aedc

20 files changed

+352
-10490
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node_modules
22
tmp
3-
dist
3+
dist
4+
.idea
5+
examples/html/*
6+
examples/png/*
7+
examples/svg/*

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ Arguments:
114114

115115
Returns: *an HTML file that uses absolute positioned elements for layout.*
116116

117+
## Text operations
118+
119+
### Get text from page
120+
121+
```js
122+
mupdf.getPageText(document, page);
123+
```
124+
125+
Arguments:
126+
- document: *a MuPdf document object*
127+
- page: *the page number to be rendered, starting from 1*
128+
129+
Returns: *string containing all text collected from page*
130+
131+
### Search on the page
132+
133+
```js
134+
mupdf.searchPageText(document, page, searchString, maxHits);
135+
```
136+
137+
Arguments:
138+
- document: *a MuPdf document object*
139+
- page: *the page number to be rendered, starting from 1*
140+
- searchString: *string to search*
141+
- maxHits: *the maximum possible number of matches (it stops search when reaches this limit)*
142+
143+
Returns: *array of found rectangles of text matches ({x: number, y: number, w: number, h: number}[])*
144+
117145
# License
118146

119147
AGPL, subject to the [MuPDF license](https://www.mupdf.com/license.html).

bin/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
cp /opt/mupdf-js/overrides/* /src/platform/wasm/
4+
35
echo 'Running apt-get update'
46
apt-get update
57

@@ -17,4 +19,4 @@ cp /src/platform/wasm/libmupdf.js /opt/mupdf-js/dist
1719
cp /src/platform/wasm/libmupdf.wasm /opt/mupdf-js/dist
1820

1921
echo 'Updating fs permissions'
20-
chown "$HOST_USER" /opt/mupdf-js/dist/libmupdf.*
22+
chown "$HOST_USER" /opt/mupdf-js/dist/libmupdf.*

bin/build.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ async function runDockerBuildCommand() {
5757
Binds: [
5858
`${resolve(`./tmp/mupdf-${MUPDF_VERSION}-source`)}:/src`,
5959
`${resolve(`.`)}:/opt/mupdf-js`,
60-
`${resolve(`./overrides/Makefile`)}:/src/platform/wasm/Makefile`,
61-
`${resolve(`./overrides/wrap.js`)}:/src/platform/wasm/wrap.js`,
6260
],
6361
},
6462
Env: [`HOST_USER=${user}`],

examples/html/example-1.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/html/example-2.html

Lines changed: 0 additions & 24 deletions
This file was deleted.

examples/html/example-3.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/html/example-4.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/png/example-1.png

-1.57 MB
Binary file not shown.

examples/png/example-2.png

-868 KB
Binary file not shown.

0 commit comments

Comments
 (0)