Skip to content

Commit e99bac9

Browse files
committed
paper-muncher: Remove subcommands and improve configuration of pagination and crop behavior.
1 parent 3b446b1 commit e99bac9

File tree

6 files changed

+285
-371
lines changed

6 files changed

+285
-371
lines changed

doc/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cd paper-muncher
1414
export PATH=$PATH:$HOME/.local/bin
1515

1616
# Render a webpage to PDF
17-
paper-muncher --unsecure print index.html -o output.pdf
17+
paper-muncher index.html -o output.pdf
1818

1919
# For more options, run
2020
paper-muncher --help

doc/usage.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
**Paper-Muncher** is a document rendering tool that converts web documents into high-quality **PDFs** or **rasterized images** using the Vaev layout engine. It supports HTTP and local I/O, and CSS units for layout configuration.
44

5-
## Commands
6-
7-
---
8-
9-
### `print`
105

116
```
12-
paper-muncher --unsecure print <input> -o <output> [options]
7+
paper-muncher <input> -o <output> [options]
138
```
149

1510
Renders a web document to a print-ready file (typically PDF).
@@ -24,47 +19,16 @@ Renders a web document to a print-ready file (typically PDF).
2419
- `-h,--height <length>`: Override paper height
2520
- `-f,--format <uti>`: Output format (default: `public.pdf`)
2621
- `-o,--output <output>`: Output file or URL (default: stdout)
27-
- `--unsecure`: Allows paper-muncher to access local files and the network. If omitted it will only get access to stdin and stdout.
28-
- `--timeout <duration>`: Adds a timeout to the document generation, when reached exits with a failure code.
29-
- `-v,--verbose`: Makes paper-muncher be more talkative, it might yap about how its day's going
30-
31-
**Examples:**
32-
33-
```sh
34-
paper-muncher --unsecure print article.html -o out.pdf
35-
paper-muncher --unsecure print article.html -o out.pdf --paper Letter --orientation landscape
36-
paper-muncher --unsecure print article.html -o https://example.com/doc.pdf --output-mime application/pdf
37-
```
38-
39-
---
40-
41-
### `render`
42-
43-
```
44-
paper-muncher --unsecure render <input> -o <output> [options]
45-
```
46-
47-
Renders a web document to a raster image (BMP, PNG, etc.).
48-
49-
**Options:**
50-
51-
- `--scale <scale>`: CSS resolution (default: `96dpi`)
52-
- `--density <density>`: Pixel density (default: `96dpi`)
53-
- `-w,--width <length>`: Viewport width (default: `800px`)
54-
- `-h,--height <length>`: Viewport height (default: `600px`)
55-
- `-f,--format <uti>`: Output format (default: `public.bmp`)
56-
- `--wireframe`: Show wireframe overlay of the layout
57-
- `-o,--output <output>`: Output file or URL (default: stdout)
58-
- `--unsecure`: Allows paper-muncher to access local files and the network. If omitted it will only get access to stdin and stdout.
22+
- `--sandboxed`: Disallows paper-muncher to access local files and the network.
5923
- `--timeout <duration>`: Adds a timeout to the document generation, when reached exits with a failure code.
6024
- `-v,--verbose`: Makes paper-muncher be more talkative, it might yap about how its day's going
6125

6226
**Examples:**
6327

6428
```sh
65-
paper-muncher --unsecure render page.html -o out.bmp
66-
paper-muncher --unsecure render page.html -o out.png --width 1024px --height 768px --density 192dpi
67-
paper-muncher --unsecure render page.html -o out.png --wireframe
29+
paper-muncher article.html -o out.pdf
30+
paper-muncher article.html -o out.pdf --paper Letter --orientation landscape
31+
paper-muncher article.html -o https://example.com/doc.pdf --output-mime application/pdf
6832
```
6933

7034
*NOTE: `<scale>`, `<density>`, `<orientation>`, `<length>`, `<duration>` all use [CSS unit synthax](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units#units)*

meta/plugins/reftest.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def fetchMessage(args: model.TargetArgs, type: str) -> str:
3131

3232

3333
def compareImages(
34-
lhs: bytes,
35-
rhs: bytes,
36-
lowEpsilon: float = 0.05,
37-
highEpsilon: float = 0.1,
38-
strict=False,
34+
lhs: bytes,
35+
rhs: bytes,
36+
lowEpsilon: float = 0.05,
37+
highEpsilon: float = 0.1,
38+
strict=False,
3939
) -> bool:
4040
if strict:
4141
return lhs == rhs
@@ -62,7 +62,10 @@ def compareImages(
6262

6363

6464
def runPaperMuncher(executable, type, xsize, ysize, page, outputPath, inputPath):
65-
command = ["--feature", "*=on", "--verbose", "--unsecure", type or "render"]
65+
command = ["--feature", "*=on", "--verbose"]
66+
67+
if type == "print":
68+
command.extend(["--flow", "paginate"])
6669

6770
if xsize or not page:
6871
command.extend(["--width", (xsize or 200) + "px"])
@@ -197,7 +200,7 @@ def getInfo(txt):
197200
expected_image_url = ref_image
198201

199202
for tag, info, rendering in re.findall(
200-
r"""<(rendering|error)([^>]*)>([\w\W]+?)</(?:rendering|error)>""", test
203+
r"""<(rendering|error)([^>]*)>([\w\W]+?)</(?:rendering|error)>""", test
201204
):
202205
renderingProps = getInfo(info)
203206
test_skipped = category_skipped or "skip" in renderingProps
@@ -222,7 +225,9 @@ def getInfo(txt):
222225
xsize = "800"
223226
ysize = "600"
224227

225-
runPaperMuncher(paperMuncher, type, xsize, ysize, page, img_path, input_path)
228+
runPaperMuncher(
229+
paperMuncher, type, xsize, ysize, page, img_path, input_path
230+
)
226231

227232
with img_path.open("rb") as imageFile:
228233
output_image: bytes = imageFile.read()
@@ -233,7 +238,7 @@ def getInfo(txt):
233238
if not expected_image:
234239
expected_image = output_image
235240
with (TEST_REPORT / f"{counter}.expected.bmp").open(
236-
"wb"
241+
"wb"
237242
) as imageWriter:
238243
imageWriter.write(expected_image)
239244
continue

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Paper-Muncher is now in early alpha. We're currently focused on improving stabil
3232
# Basic usage
3333

3434
```bash
35-
paper-muncher --unsecure print index.html -o output.pdf
35+
paper-muncher index.html -o output.pdf
3636
```
3737

3838
# Introduction
@@ -62,7 +62,7 @@ cd paper-muncher
6262
export PATH=$PATH:$HOME/.local/bin
6363

6464
# Render a webpage to PDF
65-
paper-muncher --unsecure --timeout=10s print index.html -o output.pdf
65+
paper-muncher index.html -o output.pdf
6666

6767
# For more options, run
6868
paper-muncher --help

0 commit comments

Comments
 (0)