1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! A from-scratch Rust HTML/CSS to PDF renderer inspired by WeasyPrint.
//!
//! # Examples
//!
//! ## Convert an HTML file to a PDF
//!
//! Load a local HTML document and write its PDF to a local file:
//!
//! ```no_run
//! use spindrift::{Html, PdfOptions, RenderOptions};
//! use std::fs::File;
//!
//! # async fn convert() -> spindrift::Result<()> {
//! let mut output = File::create("document.pdf")?;
//! Html::from_file("document.html")
//! .await?
//! .write_pdf(
//! &mut output,
//! &RenderOptions::default(),
//! &PdfOptions::default(),
//! )
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Render a report with explicit resource handling
//!
//! The rendering pipeline keeps document and stylesheet loading, CSS layout,
//! and PDF serialization separate. This lets an application share a resource
//! policy, supply a user-origin stylesheet, inspect the rendered document, and
//! choose its PDF output settings:
//!
//! ```no_run
//! use spindrift::{
//! Css, FetchErrorPolicy, Html, HttpRequestTimeout, PdfOptions, RenderOptions,
//! ResourcePolicy,
//! };
//! use std::{fs::File, time::Duration};
//!
//! # async fn render_report() -> spindrift::Result<()> {
//! let resource_policy = ResourcePolicy {
//! follow_http_redirects: false,
//! http_timeout: HttpRequestTimeout::try_from(Duration::from_secs(5))
//! .expect("five seconds is non-zero"),
//! error_policy: FetchErrorPolicy::Allow,
//! };
//!
//! let stylesheet = Css::from_file("print.css")
//! .await?
//! .with_user_origin()
//! .with_resource_policy(resource_policy);
//! let html = Html::from_file("report.html")
//! .await?
//! .with_resource_policy(resource_policy)
//! .with_stylesheet(stylesheet);
//!
//! let document = html.render(&RenderOptions::default()).await?;
//! if let Some(title) = document.metadata().title() {
//! println!("Rendered {title}");
//! }
//! for bookmark in document.bookmarks() {
//! println!("Bookmark: {}", bookmark.label());
//! }
//!
//! let mut output = File::create("report.pdf")?;
//! document.write_pdf(&mut output, &PdfOptions::default())?;
//! # Ok(())
//! # }
//! ```
pub use CssColor;
pub use ;
pub use Page;
pub use PaintStrokeWidth;
pub use ;
pub use ;
pub use ;
pub use RenderOptions;
pub use ;
pub use LayoutSize;
/// A parsed URL used as an HTML or stylesheet source.
///
/// ```no_run
/// use spindrift::{Html, PdfOptions, RenderOptions, Url};
/// use std::fs::File;
///
/// # async fn render() -> Result<(), Box<dyn std::error::Error>> {
/// let source = Url::parse("https://example.test/report.html")?;
/// let html = Html::from_url(source).await?;
/// let mut output = File::create("report.pdf")?;
/// html.write_pdf(&mut output, &RenderOptions::default(), &PdfOptions::default())
/// .await?;
/// # Ok(())
/// # }
/// ```
pub use Url;