prawn-html 0.1.0 → 0.1.4
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/README.md +40 -4
- data/lib/prawn-html.rb +8 -1
- data/lib/prawn_html/tags/a.rb +1 -3
- data/lib/prawn_html/tags/base.rb +1 -1
- data/lib/prawn_html/tags/small.rb +1 -0
- data/lib/prawn_html/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a2fb462a91991cadb770f8bbee7d07c99f670d46eeb62d2a3b467b1839e5364
|
4
|
+
data.tar.gz: 1710135c8ca94e2de836e913ce8e177b9bc47b4ee37725a23729912b086aff25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceec4ef90b155ea23f659771ab4e6275f12c9c5d4dd29a5da11b4d7f23512320ec71246623ff3c0eb82e0bed9a5e837292c40ac5a8d82585eaa4cb64cdc0653b
|
7
|
+
data.tar.gz: efea6fe48069d63b56c8c2e7a0142ed959af8cb200e8bc6ff03f8b252614379130feed7bd54942d59a97689c43f3b8a407e739db2b3c9fd1087f10c75fe0ca35
|
data/README.md
CHANGED
@@ -1,29 +1,37 @@
|
|
1
1
|
# Prawn HTML
|
2
|
+
[](https://badge.fury.io/rb/prawn-html)
|
2
3
|
[](https://github.com/blocknotes/prawn-html/actions/workflows/linters.yml)
|
3
4
|
[](https://github.com/blocknotes/prawn-html/actions/workflows/specs.yml)
|
4
5
|
|
5
6
|
HTML to PDF renderer using [Prawn PDF](https://github.com/prawnpdf/prawn).
|
6
7
|
|
7
|
-
|
8
|
+
Features:
|
9
|
+
- support a [good set](#supported-tags--attributes) of HTML tags and CSS properties;
|
10
|
+
- handle [document styles](#document-styles);
|
11
|
+
- no extra settings: it just parses an input HTML and output to a Prawn PDF document.
|
8
12
|
|
9
13
|
**Notice**: render HTML documents properly is not an easy task, this gem support only some HTML tags and a small set of CSS attributes. If you need more rendering accuracy take a look at other projects like WickedPDF.
|
10
14
|
|
15
|
+
> [prawn-styled-text](https://github.com/blocknotes/prawn-styled-text) rewritten from scratch, finally!
|
16
|
+
|
11
17
|
Please :star: if you like it.
|
12
18
|
|
13
19
|
## Install
|
14
20
|
|
15
|
-
- Add to your Gemfile: `gem 'prawn-html'
|
16
|
-
-
|
21
|
+
- Add to your Gemfile: `gem 'prawn-html'` (and execute `bundle`)
|
22
|
+
- Just call `PrawnHtml.append_html` on a `Prawn::Document` instance (see the examples)
|
17
23
|
|
18
24
|
## Examples
|
19
25
|
|
20
26
|
```rb
|
21
27
|
require 'prawn-html'
|
22
28
|
pdf = Prawn::Document.new(page_size: 'A4')
|
23
|
-
PrawnHtml
|
29
|
+
PrawnHtml.append_html(pdf, '<h1 style="text-align: center">Just a test</h1>')
|
24
30
|
pdf.render_file('test.pdf')
|
25
31
|
```
|
26
32
|
|
33
|
+
To check some examples with the PDF output see [examples](examples/) folder.
|
34
|
+
|
27
35
|
## Supported tags & attributes
|
28
36
|
|
29
37
|
HTML tags:
|
@@ -69,6 +77,34 @@ CSS attributes (dimensional units are ignored and considered in pixel):
|
|
69
77
|
- **text-decoration**: `underline`, ex. `style="text-decoration: underline"`
|
70
78
|
- **width**: for *img* tag, support also percentage, ex. `<img src="image.jpg" style="width: 50%; height: 200px"/>`
|
71
79
|
|
80
|
+
## Document styles
|
81
|
+
|
82
|
+
[Experimental feature] You can define document CSS rules inside an _head_ tag, but with a limited support for now.
|
83
|
+
Only single CSS selectors and basic ones are supported. Example:
|
84
|
+
|
85
|
+
```html
|
86
|
+
<!DOCTYPE html>
|
87
|
+
<html>
|
88
|
+
<head>
|
89
|
+
<title>A test</title>
|
90
|
+
<style>
|
91
|
+
body { color: #abbccc }
|
92
|
+
.green {
|
93
|
+
color: #0f0;
|
94
|
+
font-family: Courier;
|
95
|
+
}
|
96
|
+
#test-1 { font-weight: bold }
|
97
|
+
</style>
|
98
|
+
</head>
|
99
|
+
<body>
|
100
|
+
<div class="green">
|
101
|
+
Div content
|
102
|
+
<span id="test-1">Span content</span>
|
103
|
+
</div>
|
104
|
+
</body>
|
105
|
+
</html>
|
106
|
+
```
|
107
|
+
|
72
108
|
## Do you like it? Star it!
|
73
109
|
|
74
110
|
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
data/lib/prawn-html.rb
CHANGED
@@ -13,5 +13,12 @@ require 'prawn_html/document_renderer'
|
|
13
13
|
require 'prawn_html/html_handler'
|
14
14
|
|
15
15
|
module PrawnHtml
|
16
|
-
PX = 0.66 # conversion
|
16
|
+
PX = 0.66 # conversion constant for pixel sixes
|
17
|
+
|
18
|
+
def append_html(pdf, html)
|
19
|
+
handler = PrawnHtml::HtmlHandler.new(pdf)
|
20
|
+
handler.process(html)
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :append_html
|
17
24
|
end
|
data/lib/prawn_html/tags/a.rb
CHANGED
data/lib/prawn_html/tags/base.rb
CHANGED
data/lib/prawn_html/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oga
|