13 releases

0.1.12 Nov 20, 2023
0.1.11 Nov 13, 2023
0.1.8 Sep 16, 2022

#1459 in Text processing

Download history 21/week @ 2024-07-23 11/week @ 2024-07-30 2/week @ 2024-08-27 1/week @ 2024-09-10 3/week @ 2024-09-17 21/week @ 2024-09-24 7/week @ 2024-10-01

126 downloads per month
Used in rustweb2

MIT/Apache

25KB
662 lines

This crate implements minimal conversion from HTML to PDF.

ToDo: Proper parsing of tag attibutes. Font sizing, html tables. A whole lot more.

Test example

   use pdf_min::*;
   let source = format!("
<html>
<head>
  <title>Rust is Great</title>
</head>
<body>
<h1>Important Notice&excl;</h1>
<p>Hello <b>something bold</b> ok</p>
<p>Hi <i>italic test</i>
<p>Hi <i><b>bold italic test</b> ok</i>
<p>Hi <sup>sup test</sup> ok
<p>Hi <sub>sub text</sub> ok
<p>{}
</body>
</html>
","Some words to cause Line and Page wrapping ".repeat(200));
   let mut w = Writer::default();
   w.b.nocomp = true;
   w.line_pad = 8; // Other Writer default values could be adjusted here.
   html(&mut w, source.as_bytes());
   w.finish();

   use std::fs::File;
   use std::io::prelude::*;

   let mut file = File::create("test.pdf").unwrap();
   file.write_all(&w.b.b).unwrap();

Dependencies

~5MB
~161K SLoC