Skip to main content

pdf_min/
lib.rs

1//! This crate implements minimal conversion from HTML to PDF.
2//!
3//! ToDo:
4//! Proper parsing of tag attibutes.
5//! Font sizing, html tables.
6//! Img tag in html, with support for jpegs ( using new image module ).
7
8//!# Test example
9//!
10//! ```
11//!    use pdf_min::*;
12//!    let source = format!("
13//!<html>
14//!<head>
15//!   <title>Rust is Great</title>
16//!</head>
17//!<body>
18//!<h1>Important Notice&excl;</h1>
19//!<p>Hello <b>something bold</b> ok</p>
20//!<p>Hi <i>italic test</i>
21//!<p>Hi <i><b>bold italic test</b> ok</i>
22//!<p>Hi <sup>sup test</sup> ok
23//!<p>Hi <sub>sub text</sub> ok
24//!<p>{}
25//!</body>
26//!</html>
27//!","Some words to cause Line and Page wrapping ".repeat(200));
28//!    let mut w = Writer::default();
29//!    w.b.nocomp = true;
30//!    w.line_pad = 8; // Other Writer default values could be adjusted here.
31//!    html(&mut w, source.as_bytes());
32//!    w.finish();
33//!
34//!    use std::fs::File;
35//!    use std::io::prelude::*;
36//!
37//!    let mut file = File::create("test.pdf").unwrap();
38//!    file.write_all(&w.b.b).unwrap();
39//! ```
40
41#![forbid(unsafe_code)]
42#![warn(missing_docs)]
43
44/// Low level PDF writer.
45pub mod basic;
46/// PDF fonts.
47pub mod font;
48/// PDF page.
49pub mod page;
50/// High level PDF writer.
51pub mod writer;
52/// PDF images.
53pub mod image;
54
55use basic::*;
56use font::*;
57use page::*;
58pub use writer::{html, Writer};
59
60#[test]
61fn image_test()
62{
63   use crate::image::Image;
64   
65   let mut w = Writer::default();
66   w.b.nocomp = true;
67   
68   let mut data = Vec::new();
69   for i in 0..3 * 16 * 16 { 
70      data.push( i as u8 );  // Red
71      data.push( ( i + 85 ) as u8 ); // Green
72      data.push( ( i + 85 + 85 ) as u8 ); // Blue
73   }
74   
75   let mut im = Image{ obj:0, data: &data, width:16, height:16, bits_per_component:8, color_space: b"/DeviceRGB", other: b"" };
76
77   // Write the image to the PDF.
78   im.init(&mut w.b);
79
80   // Draw some text on the current page.
81   html( &mut w, b"<p>Hello <b>there</b><p>Hello <i>again</i>" );
82
83   // Draw a rectangle on the current page.
84   w.p.rect( 100.0, 200.0, 160.0, 100.0 );
85
86   // Draw the image on the current page.
87   im.draw( &mut w.p, 100.0, 300.0, 10.0 );
88
89   // Flush text
90   w.output_line();
91
92   // Finish the page
93   w.save_page();
94
95   // Draw some more text on the next page.
96   html( &mut w, b"<p>Some <b>more</b> text" );
97
98   w.finish();
99
100   use std::fs::File;
101   use std::io::prelude::*;
102
103   let mut file = File::create("image_test.pdf").unwrap();
104   file.write_all(&w.b.b).unwrap();
105}
106
107#[test]
108fn image_jpg_test()
109{
110  // ToDo....
111}