Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 2, 2024
1 parent 2f0304a commit 604bf12
Showing 1 changed file with 47 additions and 60 deletions.
107 changes: 47 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

`printpdf` is a Rust library for creating PDF documents.

[Crates.io](https://crates.io/crates/printpdf) | \
[Documentation](https://docs.rs/printpdf) | \
[Donate to this project](https://github.com/sponsors/fschutt)
[Crates.io](https://crates.io/crates/printpdf) | [Documentation](https://docs.rs/printpdf) | [Donate to this project](https://github.com/sponsors/fschutt)

## Features

Expand Down Expand Up @@ -164,64 +162,53 @@ let pdf_bytes: Vec<u8> = doc.with_pages(page1).save_to_bytes();
For creating tables, etc. printpdf uses a basic layout system using the `azul-layout` crate.

```rust
// --features="html"

// how to style footnote (empty = no footnotes)
footnotes: "{ font-family:serif;font-size:14px; }",
// how to style the header of a page (here: display the section-title attribute of a node + the page number)
// by default `.pagenum` is set to display:none, i.e. don't display the page number
header: "{
min-height: 8mm;
font-family:sans-serif;
.section-title { font-weight: bold; }
.pagenum { display:block; position:absolute; top:5mm; left: 5mm; }
}",
footer: "", // no footer
// needs --features="html"
use printpdf::*;

let html = r#"
<html>
<head>
<!-- optional: configure page header -->
<header>
<template>
<h4 class="section-header">Chapter {attr:chapter} * {attr:subsection}</h4>
<p class="pagenum">{builtin:pagenum}</p>
</template>
<style>
.section-header {
min-height: 8mm;
font-family: sans-serif;
color: #2e2e2e;
border-bottom: 1px solid black;
width: 100%;
}
.pagenum {
position: absolute;
top:
}
</style>
</header>
<!-- same for styling footers -->
<footer>
<template>
<hr/>
</template>
<footer/>
</head>
<!-- page content -->
<body margins="10mm">
<p style="color: red; font-family: sans-serif;" data-chapter="1" data-subsection="First subsection">Hello!</p>
<div style="width:200px;height:200px;background:red;" data-chapter="1" data-subsection="Second subsection">
<p>World!</p>
</div>
</body>
</html>
<html>
<head>
<!-- optional: configure page header -->
<header>
<template>
<h4 class="section-header">Chapter {attr:chapter} * {attr:subsection}</h4>
<p class="pagenum">{builtin:pagenum}</p>
</template>
<style>
.section-header {
min-height: 8mm;
font-family: sans-serif;
color: #2e2e2e;
border-bottom: 1px solid black;
width: 100%;
}
.pagenum {
position: absolute;
top:
}
</style>
</header>
<!-- same for styling footers -->
<footer>
<template>
<hr/>
</template>
<footer/>
</head>
<!-- page content -->
<body margins="10mm">
<p style="color: red; font-family: sans-serif;" data-chapter="1" data-subsection="First subsection">Hello!</p>
<div style="width:200px;height:200px;background:red;" data-chapter="1" data-subsection="Second subsection">
<p>World!</p>
</div>
</body>
</html>
"#;

let options = XmlRenderOptions {
Expand All @@ -236,7 +223,7 @@ let options = XmlRenderOptions {
};

let mut doc = PdfDocument::new("My PDF");
let pages = crate::html::xml_to_pages(html, &options, &mut doc.resources).unwrap_or_defaul();
let pages = printpdf::html::xml_to_pages(html, &options, &mut doc.resources).unwrap_or_defaul();
let pdf = doc.with_pages(pages).save_to_bytes();
```

Expand Down

0 comments on commit 604bf12

Please sign in to comment.