Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cd paper-muncher
export PATH=$PATH:$HOME/.local/bin

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

# For more options, run
paper-muncher --help
Expand Down
46 changes: 5 additions & 41 deletions doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

**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.

## Commands

---

### `print`

```
paper-muncher --unsecure print <input> -o <output> [options]
paper-muncher <input> -o <output> [options]
```

Renders a web document to a print-ready file (typically PDF).
Expand All @@ -24,47 +19,16 @@ Renders a web document to a print-ready file (typically PDF).
- `-h,--height <length>`: Override paper height
- `-f,--format <uti>`: Output format (default: `public.pdf`)
- `-o,--output <output>`: Output file or URL (default: stdout)
- `--unsecure`: Allows paper-muncher to access local files and the network. If omitted it will only get access to stdin and stdout.
- `--timeout <duration>`: Adds a timeout to the document generation, when reached exits with a failure code.
- `-v,--verbose`: Makes paper-muncher be more talkative, it might yap about how its day's going

**Examples:**

```sh
paper-muncher --unsecure print article.html -o out.pdf
paper-muncher --unsecure print article.html -o out.pdf --paper Letter --orientation landscape
paper-muncher --unsecure print article.html -o https://example.com/doc.pdf --output-mime application/pdf
```

---

### `render`

```
paper-muncher --unsecure render <input> -o <output> [options]
```

Renders a web document to a raster image (BMP, PNG, etc.).

**Options:**

- `--scale <scale>`: CSS resolution (default: `96dpi`)
- `--density <density>`: Pixel density (default: `96dpi`)
- `-w,--width <length>`: Viewport width (default: `800px`)
- `-h,--height <length>`: Viewport height (default: `600px`)
- `-f,--format <uti>`: Output format (default: `public.bmp`)
- `--wireframe`: Show wireframe overlay of the layout
- `-o,--output <output>`: Output file or URL (default: stdout)
- `--unsecure`: Allows paper-muncher to access local files and the network. If omitted it will only get access to stdin and stdout.
- `--sandboxed`: Disallows paper-muncher to access local files and the network.
- `--timeout <duration>`: Adds a timeout to the document generation, when reached exits with a failure code.
- `-v,--verbose`: Makes paper-muncher be more talkative, it might yap about how its day's going

**Examples:**

```sh
paper-muncher --unsecure render page.html -o out.bmp
paper-muncher --unsecure render page.html -o out.png --width 1024px --height 768px --density 192dpi
paper-muncher --unsecure render page.html -o out.png --wireframe
paper-muncher article.html -o out.pdf
paper-muncher article.html -o out.pdf --paper Letter --orientation landscape
paper-muncher article.html -o https://example.com/doc.pdf --output-mime application/pdf
```

*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)*
Expand Down
23 changes: 14 additions & 9 deletions meta/plugins/reftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def fetchMessage(args: model.TargetArgs, type: str) -> str:


def compareImages(
lhs: bytes,
rhs: bytes,
lowEpsilon: float = 0.05,
highEpsilon: float = 0.1,
strict=False,
lhs: bytes,
rhs: bytes,
lowEpsilon: float = 0.05,
highEpsilon: float = 0.1,
strict=False,
) -> bool:
if strict:
return lhs == rhs
Expand All @@ -62,7 +62,10 @@ def compareImages(


def runPaperMuncher(executable, type, xsize, ysize, page, outputPath, inputPath):
command = ["--feature", "*=on", "--verbose", "--unsecure", type or "render"]
command = ["--feature", "*=on", "--verbose"]

if type == "print":
command.extend(["--flow", "paginate"])

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

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

runPaperMuncher(paperMuncher, type, xsize, ysize, page, img_path, input_path)
runPaperMuncher(
paperMuncher, type, xsize, ysize, page, img_path, input_path
)

with img_path.open("rb") as imageFile:
output_image: bytes = imageFile.read()
Expand All @@ -233,7 +238,7 @@ def getInfo(txt):
if not expected_image:
expected_image = output_image
with (TEST_REPORT / f"{counter}.expected.bmp").open(
"wb"
"wb"
) as imageWriter:
imageWriter.write(expected_image)
continue
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Paper-Muncher is now in early alpha. We're currently focused on improving stabil
# Basic usage

```bash
paper-muncher --unsecure print index.html -o output.pdf
paper-muncher index.html -o output.pdf
```

# Introduction
Expand Down Expand Up @@ -62,7 +62,7 @@ cd paper-muncher
export PATH=$PATH:$HOME/.local/bin

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

# For more options, run
paper-muncher --help
Expand Down
Loading
Loading