kp_anydoc 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/Cargo.lock +61 -7
- data/README.md +1 -1
- data/THIRD-PARTY-LICENSES.txt +119 -3
- data/ext/anydoc/Cargo.toml +2 -1
- data/ext/anydoc/src/lib.rs +67 -1
- data/lib/anydoc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eadab434ed208aff7df4128d475167146af033293cee801f4600486b6d1dcc02
|
|
4
|
+
data.tar.gz: 88aed4b6b33a87d11a1f7ea5ae9f8ae116045eedca184eba04e38de397687c5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccaaba0d425575bd13922d1a1eecbbe118ac560032574687fdd6b3e196921fe7cee04facb8105a1073d20226b6af8089188b461b41f90fd5566af250e2fdea71
|
|
7
|
+
data.tar.gz: 19a9a60e3f72920d3ad3c8136185127443647d03738b34f5fff0dd8d818c65bf43d5eef451de884e69b11015a7a6e99bb5e66bfb2d2eb7c493597b1e8249689d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
Versions track the [`anydoc`](https://crates.io/crates/anydoc) Rust crate this gem wraps: `kp_anydoc` 0.2.
|
|
3
|
+
Versions track the [`anydoc`](https://crates.io/crates/anydoc) Rust crate this gem wraps: `kp_anydoc` 0.2.5 wraps `anydoc` 0.2.5.
|
|
4
|
+
|
|
5
|
+
## [0.2.5] - 2026-12-01
|
|
6
|
+
|
|
7
|
+
Wraps `anydoc` 0.2.5, back on the current crate after the 0.2.3 pin, so dependency fixes like `zip` 9.5.1 come through again.
|
|
8
|
+
|
|
9
|
+
- When some pages of a PDF are scanned or image-only, the readable pages convert as on 0.2.3, and each page left out is replaced in place by a note, e.g. `> Page 2 of 3 is scanned or image-only and could not be converted.` `anydoc` 0.2.4 and later refuse the whole document in that case, so the gem catches that refusal and extracts the text itself through `pdf-inspector`.
|
|
10
|
+
- A PDF with no readable text raises `Anydoc::UnsupportedError`, as on 0.2.3.
|
|
11
|
+
- No network calls: hosted OCR through Firecrawl Parse exists only in the upstream Node and Python bindings, not in the Rust API this gem wraps.
|
|
4
12
|
|
|
5
13
|
## [0.2.3] - 2026-09-09
|
|
6
14
|
|
data/Cargo.lock
CHANGED
|
@@ -91,16 +91,17 @@ dependencies = [
|
|
|
91
91
|
name = "anydoc"
|
|
92
92
|
version = "0.1.0"
|
|
93
93
|
dependencies = [
|
|
94
|
-
"anydoc 0.2.
|
|
94
|
+
"anydoc 0.2.5",
|
|
95
95
|
"magnus",
|
|
96
|
+
"pdf-inspector",
|
|
96
97
|
"rb-sys",
|
|
97
98
|
]
|
|
98
99
|
|
|
99
100
|
[[package]]
|
|
100
101
|
name = "anydoc"
|
|
101
|
-
version = "0.2.
|
|
102
|
+
version = "0.2.5"
|
|
102
103
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
103
|
-
checksum = "
|
|
104
|
+
checksum = "ae154cb7eea57f6844f090210f08b3609daf6bceea680daab472c54eb8a9bf56"
|
|
104
105
|
dependencies = [
|
|
105
106
|
"cfb",
|
|
106
107
|
"csv",
|
|
@@ -217,6 +218,12 @@ version = "1.0.4"
|
|
|
217
218
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
218
219
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
219
220
|
|
|
221
|
+
[[package]]
|
|
222
|
+
name = "cfg_aliases"
|
|
223
|
+
version = "0.2.2"
|
|
224
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
+
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
|
226
|
+
|
|
220
227
|
[[package]]
|
|
221
228
|
name = "chacha20"
|
|
222
229
|
version = "0.10.1"
|
|
@@ -266,6 +273,15 @@ version = "1.0.5"
|
|
|
266
273
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
267
274
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
|
268
275
|
|
|
276
|
+
[[package]]
|
|
277
|
+
name = "constant_time_eq"
|
|
278
|
+
version = "0.6.2"
|
|
279
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
280
|
+
checksum = "144e7f1de087984240b7816d47f698b414979faa6f40839c5b86d6bd47db57b7"
|
|
281
|
+
dependencies = [
|
|
282
|
+
"rustversion",
|
|
283
|
+
]
|
|
284
|
+
|
|
269
285
|
[[package]]
|
|
270
286
|
name = "core-foundation-sys"
|
|
271
287
|
version = "0.8.7"
|
|
@@ -800,6 +816,18 @@ dependencies = [
|
|
|
800
816
|
"simd-adler32",
|
|
801
817
|
]
|
|
802
818
|
|
|
819
|
+
[[package]]
|
|
820
|
+
name = "nix"
|
|
821
|
+
version = "0.32.0"
|
|
822
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
823
|
+
checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc"
|
|
824
|
+
dependencies = [
|
|
825
|
+
"bitflags 2.13.1",
|
|
826
|
+
"cfg-if",
|
|
827
|
+
"cfg_aliases",
|
|
828
|
+
"libc",
|
|
829
|
+
]
|
|
830
|
+
|
|
803
831
|
[[package]]
|
|
804
832
|
name = "nom"
|
|
805
833
|
version = "7.1.3"
|
|
@@ -1217,9 +1245,9 @@ checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
|
|
1217
1245
|
|
|
1218
1246
|
[[package]]
|
|
1219
1247
|
name = "typed-path"
|
|
1220
|
-
version = "0.
|
|
1248
|
+
version = "0.13.0"
|
|
1221
1249
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1222
|
-
checksum = "
|
|
1250
|
+
checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
|
|
1223
1251
|
|
|
1224
1252
|
[[package]]
|
|
1225
1253
|
name = "typenum"
|
|
@@ -1405,17 +1433,43 @@ dependencies = [
|
|
|
1405
1433
|
"windows-link",
|
|
1406
1434
|
]
|
|
1407
1435
|
|
|
1436
|
+
[[package]]
|
|
1437
|
+
name = "zeroize"
|
|
1438
|
+
version = "1.9.2"
|
|
1439
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1440
|
+
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
|
|
1441
|
+
dependencies = [
|
|
1442
|
+
"zeroize_derive",
|
|
1443
|
+
]
|
|
1444
|
+
|
|
1445
|
+
[[package]]
|
|
1446
|
+
name = "zeroize_derive"
|
|
1447
|
+
version = "1.5.0"
|
|
1448
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1449
|
+
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
|
|
1450
|
+
dependencies = [
|
|
1451
|
+
"proc-macro2",
|
|
1452
|
+
"quote",
|
|
1453
|
+
"syn 2.0.119",
|
|
1454
|
+
]
|
|
1455
|
+
|
|
1408
1456
|
[[package]]
|
|
1409
1457
|
name = "zip"
|
|
1410
|
-
version = "
|
|
1458
|
+
version = "9.9.0"
|
|
1411
1459
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1412
|
-
checksum = "
|
|
1460
|
+
checksum = "07db37dec4a7c468df4723fba4cadb4822d1d0f10dbea367100b6a6881b2a9c9"
|
|
1413
1461
|
dependencies = [
|
|
1462
|
+
"constant_time_eq",
|
|
1414
1463
|
"crc32fast",
|
|
1415
1464
|
"flate2",
|
|
1465
|
+
"getrandom",
|
|
1416
1466
|
"indexmap",
|
|
1467
|
+
"libc",
|
|
1417
1468
|
"memchr",
|
|
1469
|
+
"nix",
|
|
1418
1470
|
"typed-path",
|
|
1471
|
+
"windows-sys",
|
|
1472
|
+
"zeroize",
|
|
1419
1473
|
"zopfli",
|
|
1420
1474
|
]
|
|
1421
1475
|
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The gem is published on RubyGems as **`kp_anydoc`** but is required as **`anydoc
|
|
|
10
10
|
gem "kp_anydoc"
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Requires **Ruby 3.4 or newer**. The gem version tracks the [`anydoc`](https://crates.io/crates/anydoc) Rust crate it wraps — `kp_anydoc` 0.2.
|
|
13
|
+
Requires **Ruby 3.4 or newer**. The gem version tracks the [`anydoc`](https://crates.io/crates/anydoc) Rust crate it wraps — `kp_anydoc` 0.2.5 wraps `anydoc` 0.2.5. Precompiled native gems are published for the platforms below, each carrying a Ruby 3.4 and 4.0 extension, so installs need no Rust toolchain:
|
|
14
14
|
|
|
15
15
|
- `x86_64-linux`
|
|
16
16
|
- `aarch64-linux`
|
data/THIRD-PARTY-LICENSES.txt
CHANGED
|
@@ -424,6 +424,7 @@ Applies to:
|
|
|
424
424
|
Apache License 2.0 (Apache-2.0)
|
|
425
425
|
|
|
426
426
|
Applies to:
|
|
427
|
+
- constant_time_eq 0.6.2
|
|
427
428
|
- ryu 1.0.23
|
|
428
429
|
--------------------------------------------------------------------------------
|
|
429
430
|
Apache License
|
|
@@ -654,6 +655,40 @@ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE US
|
|
|
654
655
|
THIS SOFTWARE.
|
|
655
656
|
|
|
656
657
|
|
|
658
|
+
================================================================================
|
|
659
|
+
MIT License (MIT)
|
|
660
|
+
|
|
661
|
+
Applies to:
|
|
662
|
+
- cfg_aliases 0.2.2
|
|
663
|
+
--------------------------------------------------------------------------------
|
|
664
|
+
# 3rd Party Notices
|
|
665
|
+
|
|
666
|
+
The `cfg_aliases!` macro uses a lot of the code from [`tectonic_cfg_support::target_cfg!`] macro which is under the following license:
|
|
667
|
+
|
|
668
|
+
[`tectonic_cfg_support::target_cfg!`]: https://github.com/tectonic-typesetting/tectonic/blob/f2439b936470ad27bdf92882064bc4702ee01899/cfg_support/src/lib.rs#L166
|
|
669
|
+
|
|
670
|
+
tectonic_cfg_support is licensed under the MIT License.
|
|
671
|
+
|
|
672
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
673
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
674
|
+
in the Software without restriction, including without limitation the rights
|
|
675
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
676
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
677
|
+
furnished to do so, subject to the following conditions:
|
|
678
|
+
|
|
679
|
+
The above copyright notice and this permission notice shall be included in all
|
|
680
|
+
copies or substantial portions of the Software.
|
|
681
|
+
|
|
682
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
683
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
684
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
685
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
686
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
687
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
688
|
+
SOFTWARE.
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
|
|
657
692
|
================================================================================
|
|
658
693
|
MIT License (MIT)
|
|
659
694
|
|
|
@@ -1514,6 +1549,39 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
1514
1549
|
DEALINGS IN THE SOFTWARE.
|
|
1515
1550
|
|
|
1516
1551
|
|
|
1552
|
+
================================================================================
|
|
1553
|
+
MIT License (MIT)
|
|
1554
|
+
|
|
1555
|
+
Applies to:
|
|
1556
|
+
- zeroize 1.9.2
|
|
1557
|
+
--------------------------------------------------------------------------------
|
|
1558
|
+
Copyright (c) 2018-2026 The RustCrypto Project Developers
|
|
1559
|
+
|
|
1560
|
+
Permission is hereby granted, free of charge, to any
|
|
1561
|
+
person obtaining a copy of this software and associated
|
|
1562
|
+
documentation files (the "Software"), to deal in the
|
|
1563
|
+
Software without restriction, including without
|
|
1564
|
+
limitation the rights to use, copy, modify, merge,
|
|
1565
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
1566
|
+
the Software, and to permit persons to whom the Software
|
|
1567
|
+
is furnished to do so, subject to the following
|
|
1568
|
+
conditions:
|
|
1569
|
+
|
|
1570
|
+
The above copyright notice and this permission notice
|
|
1571
|
+
shall be included in all copies or substantial portions
|
|
1572
|
+
of the Software.
|
|
1573
|
+
|
|
1574
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
1575
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
1576
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
1577
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
1578
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
1579
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
1580
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
1581
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
1582
|
+
DEALINGS IN THE SOFTWARE.
|
|
1583
|
+
|
|
1584
|
+
|
|
1517
1585
|
================================================================================
|
|
1518
1586
|
MIT License (MIT)
|
|
1519
1587
|
|
|
@@ -1586,6 +1654,7 @@ MIT License (MIT)
|
|
|
1586
1654
|
|
|
1587
1655
|
Applies to:
|
|
1588
1656
|
- chacha20 0.10.1
|
|
1657
|
+
- zeroize_derive 1.5.0
|
|
1589
1658
|
--------------------------------------------------------------------------------
|
|
1590
1659
|
Copyright (c) 2019-2026 The RustCrypto Project Developers
|
|
1591
1660
|
|
|
@@ -2093,6 +2162,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2093
2162
|
SOFTWARE.
|
|
2094
2163
|
|
|
2095
2164
|
|
|
2165
|
+
================================================================================
|
|
2166
|
+
MIT License (MIT)
|
|
2167
|
+
|
|
2168
|
+
Applies to:
|
|
2169
|
+
- cfg_aliases 0.2.2
|
|
2170
|
+
--------------------------------------------------------------------------------
|
|
2171
|
+
MIT License
|
|
2172
|
+
|
|
2173
|
+
Copyright (c) 2020 Katharos Technology
|
|
2174
|
+
|
|
2175
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
2176
|
+
|
|
2177
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
2178
|
+
|
|
2179
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
2180
|
+
|
|
2181
|
+
|
|
2096
2182
|
================================================================================
|
|
2097
2183
|
MIT License (MIT)
|
|
2098
2184
|
|
|
@@ -2214,7 +2300,7 @@ SOFTWARE.
|
|
|
2214
2300
|
MIT License (MIT)
|
|
2215
2301
|
|
|
2216
2302
|
Applies to:
|
|
2217
|
-
- anydoc 0.2.
|
|
2303
|
+
- anydoc 0.2.5
|
|
2218
2304
|
--------------------------------------------------------------------------------
|
|
2219
2305
|
MIT License
|
|
2220
2306
|
|
|
@@ -2428,13 +2514,14 @@ Applies to:
|
|
|
2428
2514
|
- once_cell 1.21.4
|
|
2429
2515
|
- proc-macro2 1.0.107
|
|
2430
2516
|
- quote 1.0.47
|
|
2517
|
+
- rustversion 1.0.23
|
|
2431
2518
|
- seq-macro 0.3.6
|
|
2432
2519
|
- serde_core 1.0.229
|
|
2433
2520
|
- syn 2.0.119
|
|
2434
2521
|
- syn 3.0.3
|
|
2435
2522
|
- thiserror-impl 2.0.20
|
|
2436
2523
|
- thiserror 2.0.20
|
|
2437
|
-
- typed-path 0.
|
|
2524
|
+
- typed-path 0.13.0
|
|
2438
2525
|
- unicode-ident 1.0.24
|
|
2439
2526
|
--------------------------------------------------------------------------------
|
|
2440
2527
|
Permission is hereby granted, free of charge, to any
|
|
@@ -2479,7 +2566,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
2479
2566
|
MIT License (MIT)
|
|
2480
2567
|
|
|
2481
2568
|
Applies to:
|
|
2482
|
-
- zip
|
|
2569
|
+
- zip 9.9.0
|
|
2483
2570
|
--------------------------------------------------------------------------------
|
|
2484
2571
|
The MIT License (MIT)
|
|
2485
2572
|
|
|
@@ -2567,6 +2654,35 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
2567
2654
|
THE SOFTWARE.
|
|
2568
2655
|
|
|
2569
2656
|
|
|
2657
|
+
================================================================================
|
|
2658
|
+
MIT License (MIT)
|
|
2659
|
+
|
|
2660
|
+
Applies to:
|
|
2661
|
+
- nix 0.32.0
|
|
2662
|
+
--------------------------------------------------------------------------------
|
|
2663
|
+
The MIT License (MIT)
|
|
2664
|
+
|
|
2665
|
+
Copyright (c) 2015 Carl Lerche + nix-rust Authors
|
|
2666
|
+
|
|
2667
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2668
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
2669
|
+
in the Software without restriction, including without limitation the rights
|
|
2670
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
2671
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
2672
|
+
furnished to do so, subject to the following conditions:
|
|
2673
|
+
|
|
2674
|
+
The above copyright notice and this permission notice shall be included in
|
|
2675
|
+
all copies or substantial portions of the Software.
|
|
2676
|
+
|
|
2677
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2678
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
2679
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
2680
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
2681
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
2682
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
2683
|
+
THE SOFTWARE.
|
|
2684
|
+
|
|
2685
|
+
|
|
2570
2686
|
================================================================================
|
|
2571
2687
|
MIT License (MIT)
|
|
2572
2688
|
|
data/ext/anydoc/Cargo.toml
CHANGED
data/ext/anydoc/src/lib.rs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
use anydoc_core::{ConvertError, Format};
|
|
2
2
|
use magnus::{function, prelude::*, Error, ExceptionClass, RString, Ruby};
|
|
3
|
+
use pdf_inspector::{MarkdownOptions, PdfOptions};
|
|
4
|
+
use std::collections::BTreeMap;
|
|
3
5
|
|
|
4
6
|
fn error_class_name(error: &ConvertError) -> &'static str {
|
|
5
7
|
match error {
|
|
@@ -28,7 +30,71 @@ fn to_markdown(ruby: &Ruby, data: RString, filename: Option<String>) -> Result<S
|
|
|
28
30
|
.and_then(Format::from_extension);
|
|
29
31
|
|
|
30
32
|
let bytes = unsafe { data.as_slice() };
|
|
31
|
-
anydoc_core::to_markdown_bytes(bytes, format)
|
|
33
|
+
match anydoc_core::to_markdown_bytes(bytes, format) {
|
|
34
|
+
Err(ConvertError::NeedsOcr { pages, page_count }) => {
|
|
35
|
+
readable_pdf_markdown(bytes, &pages, page_count)
|
|
36
|
+
}
|
|
37
|
+
result => result,
|
|
38
|
+
}
|
|
39
|
+
.map_err(|error| convert_error(ruby, error))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn readable_pdf_markdown(
|
|
43
|
+
bytes: &[u8],
|
|
44
|
+
unreadable_pages: &[u32],
|
|
45
|
+
page_count: u32,
|
|
46
|
+
) -> Result<String, ConvertError> {
|
|
47
|
+
let options = PdfOptions::new().markdown(MarkdownOptions {
|
|
48
|
+
include_page_numbers: true,
|
|
49
|
+
..MarkdownOptions::default()
|
|
50
|
+
});
|
|
51
|
+
let markdown = pdf_inspector::process_pdf_mem_with_options(bytes, options)
|
|
52
|
+
.map_err(|error| ConvertError::Unsupported(format!("PDF needs OCR: {error}")))?
|
|
53
|
+
.markdown
|
|
54
|
+
.unwrap_or_default();
|
|
55
|
+
|
|
56
|
+
let mut pages: BTreeMap<u32, String> = BTreeMap::new();
|
|
57
|
+
let mut page = 0;
|
|
58
|
+
for line in markdown.lines() {
|
|
59
|
+
match page_marker(line) {
|
|
60
|
+
Some(number) => page = number,
|
|
61
|
+
None => {
|
|
62
|
+
let content = pages.entry(page).or_default();
|
|
63
|
+
content.push_str(line);
|
|
64
|
+
content.push('\n');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for &number in unreadable_pages {
|
|
69
|
+
pages.insert(
|
|
70
|
+
number,
|
|
71
|
+
format!("> Page {number} of {page_count} is scanned or image-only and could not be converted."),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let readable = pages
|
|
76
|
+
.iter()
|
|
77
|
+
.any(|(number, content)| !unreadable_pages.contains(number) && !content.trim().is_empty());
|
|
78
|
+
if !readable {
|
|
79
|
+
return Err(ConvertError::Unsupported(format!(
|
|
80
|
+
"PDF has no extractable text ({page_count} pages): OCR is required"
|
|
81
|
+
)));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let markdown = pages
|
|
85
|
+
.values()
|
|
86
|
+
.map(|content| content.trim())
|
|
87
|
+
.filter(|content| !content.is_empty())
|
|
88
|
+
.collect::<Vec<_>>()
|
|
89
|
+
.join("\n\n");
|
|
90
|
+
Ok(markdown + "\n")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn page_marker(line: &str) -> Option<u32> {
|
|
94
|
+
line.strip_prefix("<!-- Page ")?
|
|
95
|
+
.strip_suffix(" -->")?
|
|
96
|
+
.parse()
|
|
97
|
+
.ok()
|
|
32
98
|
}
|
|
33
99
|
|
|
34
100
|
#[magnus::init]
|
data/lib/anydoc/version.rb
CHANGED