Add examples to readme
All checks were successful
CI Pipeline / build (pull_request) Successful in 18s
All checks were successful
CI Pipeline / build (pull_request) Successful in 18s
This commit is contained in:
48
README.md
48
README.md
@@ -112,6 +112,53 @@ Ezdoc::Document.create("output.docx") do |doc|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Images
|
||||||
|
|
||||||
|
Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Ezdoc::Document.create("output.docx") do |doc|
|
||||||
|
# Simple image (uses native dimensions)
|
||||||
|
doc.p do
|
||||||
|
doc.image "photo.png"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Image with explicit dimensions (inches, cm, or pixels)
|
||||||
|
doc.p do
|
||||||
|
doc.image "logo.png", width: "2in", height: "1in"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Specify only width (height auto-calculated to maintain aspect ratio)
|
||||||
|
doc.p do
|
||||||
|
doc.image "banner.jpg", width: "5cm"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Image with text in the same paragraph
|
||||||
|
doc.p do
|
||||||
|
doc.text "Company Logo: "
|
||||||
|
doc.image "logo.png", width: "0.5in", height: "0.5in"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Image in a table cell
|
||||||
|
doc.table do
|
||||||
|
doc.tr do
|
||||||
|
doc.td "Product"
|
||||||
|
doc.td do
|
||||||
|
doc.image "product.jpg", width: "1in", height: "1in"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Image in a list item
|
||||||
|
doc.ul do
|
||||||
|
doc.li do
|
||||||
|
doc.image "icon.png", width: "16px", height: "16px"
|
||||||
|
doc.text " List item with icon"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Complete Example
|
### Complete Example
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@@ -169,6 +216,7 @@ end
|
|||||||
| `tr { }` | Table row |
|
| `tr { }` | Table row |
|
||||||
| `td(text)` | Table cell with text |
|
| `td(text)` | Table cell with text |
|
||||||
| `td { }` | Table cell with block content |
|
| `td { }` | Table cell with block content |
|
||||||
|
| `image(path, width:, height:)` | Insert image (PNG/JPEG). Dimensions: `"2in"`, `"5cm"`, `"100px"`, or integer pixels |
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user