use pdfsmith::{FooterConfig, HeaderConfig, PdfBuilder};
fn main() {
env_logger::init();
let markdown = r##"
# Wildlife Photography Gallery
A curated collection of public-domain wildlife photographs, demonstrating
how `pdfsmith` renders images from URLs inside a PDF. Images are fetched
by the headless Chrome browser during rendering.
## African Savanna
### Lion

The African lion (*Panthera leo*) is the second-largest living cat after the
tiger. Males are easily recognised by their mane. Lions are social cats,
living in groups called **prides** that typically consist of related females,
their cubs, and a small number of adult males.
| Fact | Detail |
|---------------|--------------------------------|
| Scientific name | *Panthera leo* |
| Weight | 150–250 kg (males) |
| Lifespan | 10–14 years (wild) |
| Diet | Carnivore |
| Habitat | Savanna, grassland |
| Conservation | Vulnerable (IUCN) |
### Elephant

The African bush elephant (*Loxodonta africana*) is the largest living
terrestrial animal. Bulls can reach 6 tonnes and stand 3.5 metres at the
shoulder. They are highly intelligent, display complex social behaviours,
and have excellent long-term memory.
Key characteristics:
- Largest brain of any land animal (~5 kg)
- Can live up to 70 years
- Communicate via infrasound over several kilometres
- Matriarchal family groups of 10–15 individuals
## Marine Life
### Sea Turtle

The green sea turtle (*Chelonia mydas*) is one of the largest sea turtles
and the only herbivore among the different species. Named for the green
colour of its cartilage and fat (not its shell), it can weigh up to 315 kg.
### Coral Reef

Coral reefs support approximately **25% of all marine species** despite
covering less than 1% of the ocean floor. They are sometimes called the
"rainforests of the sea."
| Fact | Detail |
|------------------|----------------------------------|
| Total area | ~284,300 km² |
| Species supported| ~1 million |
| Growth rate | 1–3 cm per year (hard coral) |
| Threat level | Critical (climate, acidification)|
## Mountain & Forest
### Red Fox

The red fox (*Vulpes vulpes*) has the widest geographical range of any
member of the order Carnivora, spanning across the Northern Hemisphere.
They are remarkably adaptable and can thrive in urban environments.
Behavioural notes:
1. **Solitary hunter** — unlike wolves, foxes hunt alone
2. **Omnivorous diet** — rodents, berries, insects, garbage
3. **Excellent hearing** — can locate prey under 60 cm of snow
4. **Cache food** — buries surplus prey for later retrieval
### Bald Eagle

The bald eagle (*Haliaeetus leucocephalus*) is the national bird and symbol
of the United States. With a wingspan of up to 2.3 metres, it is one of
the most impressive raptors in North America.
Conservation success story:
- 1963: Only **417 breeding pairs** left in the lower 48 states
- DDT ban (1972) + Endangered Species Act (1973)
- 2007: Removed from endangered species list
- 2020: Estimated **316,700 individuals** — a remarkable recovery
## Summary
This example demonstrates:
- **Image rendering** from public URLs (Wikipedia Commons)
- Images automatically **scaled to page width** (`max-width: 100%`)
- Mixed content: images + tables + lists + paragraphs
- Header and footer with page numbers
- Heading numbers for clear structure
---
> In every walk with nature, one receives far more than he seeks. — John Muir
"##;
let pdf = PdfBuilder::new()
.title("Wildlife Gallery")
.display_header_footer(true)
.header(HeaderConfig {
center: Some("Wildlife Photography Gallery".into()),
font_size: Some("9px".into()),
color: Some("#2e7d32".into()),
..Default::default()
})
.footer(FooterConfig {
left: Some("Images: Wikimedia Commons (Public Domain)".into()),
right: Some(
r#"Page <span class="pageNumber"></span> of <span class="totalPages"></span>"#
.into(),
),
font_size: Some("7px".into()),
color: Some("#888".into()),
..Default::default()
})
.heading_numbers(true)
.extra_css(r#"
img {
display: block;
margin: 16px auto; /* centred horizontally */
width: 250px; /* small fixed size */
height: 250px; /* square */
object-fit: cover; /* crop to fill square */
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
h1 { color: #2e7d32; }
"#)
.page_load_wait_secs(5) .from_markdown(markdown)
.expect("Failed to generate PDF");
std::fs::write("examples/output_pdfs/with_images.pdf", &pdf).expect("Failed to write PDF");
println!("PDF saved to examples/output_pdfs/with_images.pdf ({} bytes)", pdf.len());
}