@3sln/emon 0.0.0-stage → 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 3sln
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # emon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ emon converts PDFs and images into semantic HTML (and a JSON model of the same document) for scraping and
4
+ indexing: headings, paragraphs, lists, tables, figures, footnotes, reading order across columns, text in scans
5
+ by OCR. It is one specification implemented in Rust, Go, Java, C# and WebAssembly/JavaScript, generated from one
6
+ source tree, so every host gives the same bytes for the same input.
7
+
8
+ This package is one of them. The project, the documentation and the other hosts are at
9
+ <https://github.com/3sln/emon>; you can try it in your browser at <https://emon.3sln.com/>.
10
+
11
+ | Host | Registry | Install |
12
+ | --- | --- | --- |
13
+ | Rust | crates.io | `cargo add emon` |
14
+ | Go | Go modules | `go get github.com/3sln/emon/go` |
15
+ | Java | Maven Central | `com.3sln:emon` |
16
+ | C# | NuGet | `dotnet add package Emon` |
17
+ | JavaScript | npm | `npm install @3sln/emon` (and `@3sln/pdfium-wasm` for scans and figures) |
18
+ | C | GitHub Releases | `libemon` plus `emon.h`, with pdfium and Tesseract |
19
+ | babashka | GitHub Releases | the `emon-pod` archive, with pdfium and Tesseract |
20
+ | command line | GitHub Releases | `emon`, with pdfium and Tesseract bundled |
21
+
22
+ Born-digital PDFs (those with a real text layer) convert with nothing but the package. Drawing pages for scans, figures and OCR
23
+ needs pdfium, and reading scans needs Tesseract; neither is part of the Rust, Go, Java, C# and JavaScript packages, which take
24
+ them as ports you configure (an adapter for each is described in the host's page; for JavaScript pdfium is the npm package
25
+ `@3sln/pdfium-wasm`). The C library, the babashka pod and the command-line tool of the releases bundle both. See
26
+ <https://github.com/3sln/emon#what-each-host-needs-at-run-time>.
27
+
28
+ ## Rust
29
+
30
+ <!-- snippet: docs/snippets/rust/quickstart.rs -->
31
+ ```rust
32
+ use emon::{Config, Engine, HtmlOptions, Input, Options, Output};
33
+
34
+ fn main() -> Result<(), Box<dyn std::error::Error>> {
35
+ let engine = Engine::new(Config::default());
36
+ let model = engine.convert(Input::bytes(std::fs::read("report.pdf")?), &Options::default())?;
37
+ std::fs::write("report.html", model.serialize(&Output::Html(HtmlOptions::default())))?;
38
+ Ok(())
39
+ }
40
+ ```
41
+
42
+ ## Go
43
+
44
+ <!-- snippet: docs/snippets/go/quickstart.go -->
45
+ ```go
46
+ import (
47
+ "os"
48
+
49
+ emon "github.com/3sln/emon/go"
50
+ )
51
+
52
+ data, err := os.ReadFile("report.pdf")
53
+ if err != nil {
54
+ panic(err)
55
+ }
56
+ engine := emon.NewEngine(emon.DefaultConfig())
57
+ model, err := engine.Convert([]emon.Input{emon.BytesInput(data)}, emon.DefaultOptions())
58
+ if err != nil {
59
+ panic(err) // *emon.Error: err.(*emon.Error).Name() is the stable name
60
+ }
61
+ err = os.WriteFile("report.html", []byte(model.ToHTML(emon.DefaultHTMLOptions())), 0o644)
62
+ ```
63
+
64
+ ## Java
65
+
66
+ <!-- snippet: docs/snippets/java/Quickstart.java -->
67
+ ```java
68
+ import emon.api.*;
69
+ import java.nio.file.Files;
70
+ import java.nio.file.Path;
71
+ import java.util.List;
72
+
73
+ public class Quickstart {
74
+ public static void main(String[] args) throws Exception {
75
+ Engine engine = new Engine(Options.Config.defaults());
76
+ Model model = engine.convert(List.of(Input.bytes(Files.readAllBytes(Path.of("report.pdf")))), Options.defaults());
77
+ Files.writeString(Path.of("report.html"), model.toHtml(new Options.Html()));
78
+ }
79
+ }
80
+ ```
81
+
82
+ ## C#
83
+
84
+ <!-- snippet: docs/snippets/csharp/Quickstart.cs -->
85
+ ```csharp
86
+ using System.Collections.Generic;
87
+ using System.IO;
88
+
89
+ var engine = new emon.Api.Engine(emon.Api.Options.Config.Defaults());
90
+ var inputs = new List<emon.Api.Input> { emon.Api.Input.Bytes(File.ReadAllBytes("report.pdf")) };
91
+ var model = engine.Convert(inputs, emon.Api.Options.Defaults());
92
+ File.WriteAllText("report.html", model.ToHtml(new emon.Api.Options.Html()));
93
+ ```
94
+
95
+ ## JavaScript
96
+
97
+ <!-- snippet: docs/snippets/js/quickstart.mjs -->
98
+ ```js
99
+ import { readFile, writeFile } from 'node:fs/promises';
100
+ import { Emon } from '@3sln/emon';
101
+
102
+ const wasm = await readFile(new URL(import.meta.resolve('@3sln/emon/emon.wasm')));
103
+ const emon = await Emon.load(wasm);
104
+ const model = await emon.convert(await readFile('report.pdf'));
105
+ await writeFile('report.html', model.html());
106
+ model.dispose();
107
+ ```
108
+
109
+ Node below 25 needs `node --experimental-wasm-exnref`.
110
+
111
+ ## Licence
112
+
113
+ MIT. The third-party components these packages contain or load, and their licences, are listed in
114
+ `THIRD_PARTY_NOTICES.md`.