Next I will talk about how to process PDF files. Here I use PD4ML for processing. There are several reasons: (1) it supports CSS very well; (2), Can process pictures (very refreshing) (3), can process Chinese, but a little trouble. For the basic process, see my other post. java programming converts HTML files into PDF files: http://blog.csdn.net/w397090770/article/details/7754256. The following is my processing process:
/*****/Package com.wyp.html 2pdf; import Java. io. file; import Java. io. fileoutputstream; import Java. io. stringreader; import Org. zefer. pd4ml. pd4constants; import Org. zefer. pd4ml. pd4ml; import Org. zefer. pd4ml. pd4pagemark;/*** @ author w397090770 * create data: 2012-7-18 * Email: wyphao.2007@163.com ** All Rights Reserved. Skip this article, but add these notes when modifying this program. Thank you * for learning and communicating only. ** Save the webpage as PDF */public class saveaspdf {// the HTML code is from the HTML file public void generate0000_2 (File outputpdffile, string contents, String title) throws exception {file savefilename = new file (outputpdffile. getabsolutefile () + file. separator + title + ". PDF "); If (! Savefilename. exists () {savefilename. createnewfile () ;}else {return;} fileoutputstream Fos = new fileoutputstream (savefilename); pd4ml pd4ml = new pd4ml (); // header export headermark = new pd4pagemark (); headermark. setareaheight (30); headermark. setinitialpagenumber (1); headermark. setpagestoskip (1); headermark. settitlealignment (pd4pagemark. center_align); headermark. sethtmltemplate (title); // autocomputepd4ml. setpageheader (headermark); // footer pd4pagemark footermark = new pd4pagemark (); footermark. setareaheight (30); footermark. setinitialpagenumber (10); footermark. sethtmltemplate ("Wuhan University"); pd4ml. setpagefooter (footermark); // select the paper size, font directory, Font, and other pd4ml. setpagesize (pd4constants. a4); pd4ml. usettf ("file: fonts", true); pd4ml. setdefaultttfs ("youyuan", "Arial", "Courier New"); pd4ml. enabledebuginfo (); pd4ml. render (New stringreader (contents), FOS );}}
The code page is very simple.