資源簡介
不用再找了,這就是你想要的!java生成PDF實例代碼,包含jar包,下載即運行

代碼片段和文件信息
package?tools;
import?java.io.BufferedReader;
import?java.io.DataOutputStream;
import?java.io.File;
import?java.io.FileNotFoundException;
import?java.io.FileOutputStream;
import?java.io.FileReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.OutputStream;
import?java.io.UnsupportedEncodingException;
import?java.math.BigDecimal;
import?java.net.HttpURLConnection;
import?java.net.URL;
import?java.text.BreakIterator;
import?java.text.DecimalFormat;
import?java.text.NumberFormat;
import?java.text.ParseException;
import?java.text.SimpleDateFormat;
import?java.util.Calendar;
import?java.util.Date;
import?java.util.GregorianCalendar;
import?java.util.Locale;
import?java.util.Random;
import?java.util.Vector;
import?java.util.regex.Matcher;
import?java.util.regex.Pattern;
/**
?*?Miscellaneous?utility?methods
?*/
public?class?Utils?{
public?static?String?encodeUrl(String?url)?{
try?{
url?=?Utils.replaceSubstringAll(url?“‘“?“-“);
url?=?Utils.replaceSubstringAll(url?“\““?“-“);
url?=?Utils.replaceSubstringAll(url?“/“?“-“);
url?=?Utils.replaceSubstringAll(url?““?“-“);
url?=?Utils.replaceSubstringAll(url?“.“?“-“);
url?=?Utils.replaceSubstringAll(url?“*“?“-“);
String?retCode?=?java.net.URLEncoder.encode(url?“UTF-8“);
retCode?=?Utils.replaceSubstringAll(retCode?“?“?“-“);
retCode?=?Utils.replaceSubstringAll(retCode?“?“?“-“);
retCode?=?Utils.replaceSubstringAll(retCode?“%“?““);
retCode?=?Utils.replaceSubstringAll(retCode?“+“?“-“);
retCode?=?retCode.trim().toLowerCase();
return?retCode;
}?catch?(Exception?ex)?{
return?url;
}
}
/**
?*?get?file?to?string
?*?
?*?@param?fileName
?*?@return?The?string?of?the?file?content
?*/
public?static?String?getFileContent(String?fileName)?{
BufferedReader?reader?=?null;
StringBuilder?fileContent?=?new?StringBuilder();
try?{
File?f?=?new?File(fileName);
new?FileReader(f);
reader?=?new?BufferedReader(new?FileReader(f));
String?line?=?““;
while?((line?=?reader.readLine())?!=?null)?{
fileContent.append(line);
}
}?catch?(Exception?e)?{
e.printStackTrace();
}?finally?{
try?{
if?(reader?!=?null)?{
reader.close();
reader?=?null;
}
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
return?fileContent.toString();
}
public?static?boolean?setFileContent(String?path?String?content)?{
boolean?flag?=?false;
OutputStream?dos?=?null;
try?{
if?(content.length()?>=?0)?{
byte?abyte[]?=?content.getBytes();
dos?=?
new?FileOutputStream(path);
dos.write(abyte?0?abyte.length);
dos.flush();
flag?=?true;
}
}?catch?(FileNotFoundException?e)?{
e.printStackTrace();
}?catch?(IOException?e)?{
e.printStackTrace();
}?finally?{
if?(dos?!=?null){
try?{
dos.close();
}?catch?(IOException?e)?{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-08-22?22:39??生成PDF\
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\
?????文件?????????557??2017-08-22?21:45??生成PDF\Html2Pdf\.classpath
?????文件?????????384??2017-08-22?21:42??生成PDF\Html2Pdf\.project
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\.settings\
?????文件?????????598??2017-08-22?21:42??生成PDF\Html2Pdf\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\fonts\
?????文件??????133000??2017-08-22?21:45??生成PDF\Html2Pdf\bin\fonts\LiberationSans-Bold.ttf
?????文件??????155304??2017-08-22?21:45??生成PDF\Html2Pdf\bin\fonts\LiberationSans-Italic.ttf
?????文件??????133088??2017-08-22?21:45??生成PDF\Html2Pdf\bin\fonts\LiberationSans-Regular.ttf
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\tools\
?????文件???????21508??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\Utils.class
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\tools\pdf\
?????文件????????3575??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\FlyingSaucerTest.class
?????文件????????7055??2017-08-22?21:47??生成PDF\Html2Pdf\bin\tools\pdf\ITextTest.class
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\
?????文件????????5087??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\bookmark.xhtml
?????目錄???????????0??2017-08-22?22:39??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\
?????文件??????120832??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\Thumbs.db
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\a.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\b.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\c.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\d.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\e.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\f.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\r_a.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\r_b.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\r_c.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\r_d.bmp
?????文件??????581120??2017-08-22?21:45??生成PDF\Html2Pdf\bin\tools\pdf\xhtmlrenderer\images\r_e.bmp
............此處省略42個文件信息
評論
共有 條評論