Import java. Io. file;
Import java. Io. fileoutputstream;
Import java. Io. outputstream;
Import org.xhtmlrenderer.pdf. itextfontresolver;
Import org.xhtmlrendererer. itextrenderer;
Import com.lowagie.text=. basefont;
Public class testflyingsauser
{
Public static void main (string [] ARGs) throws exception
{
// Demo_1 ();
Demo_2 ();
}
// Chinese characters are not supported
Public static void demo_1 () throws exception
{
String inputfile = "D:/test/flying.html ";
String url = new file (inputfile). touri (). tourl (). tostring ();
String outputfile = "D:/test/flyingdeletion ";
Outputstream OS = new fileoutputstream (outputfile );
Itextrenderer Renderer = new itextrenderer ();
Renderer. setdocument (URL );
Renderer. layout ();
Renderer. createpdf (OS );
OS. Close ();
}
// Supports Chinese Characters
Public static void demo_2 () throws exception {
String outputfile = "G:/demo_3.pdf ";
Outputstream OS = new fileoutputstream (outputfile );
Itextrenderer Renderer = new itextrenderer ();
Itextfontresolver fontresolver = Renderer. getfontresolver ();
Fontresolver. addfont ("C:/Windows/fonts/simsun. TTC", basefont. identity_h, basefont. not_embedded );
Stringbuffer html = new stringbuffer ();
// Doctype must be written. Otherwise, an error occurs when parsing a character similar to this one.
Html. append ("<! Doctype HTML public \ "-// W3C // dtd xhtml 1.0 transitional // en \" \ "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd\"> ");
Html. append ("<HTML xmlns = \" http://www.w3.org/5o/xhtml\ "> ").
Append (". Append ("<meta http-equiv = \" Content-Type \ "content = \" text/html; charset = UTF-8 \ "/> ")
. Append ("<style type = \" text/CSS \ "mce_bogus = \" 1 \ "> body {font-family: simsun ;}</style> ")
. Append (". Append ("<body> ");
Html. append ("<div> supports Chinese! </Div> ");
Html. append ("</body> Renderer. setdocumentfromstring (html. tostring ());
// Solve the relative path of the image
// Renderer. getsharedcontext (). setbaseurl ("file:/F:/teste/html /");
Renderer. layout ();
Renderer. createpdf (OS );
OS. Close ();
}}