我想一個html文件轉換爲PDF 我的代碼是將HTML轉換成PDF android系統
Document document = new Document();
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
mExternalStorageAvailable = mExternalStorageWriteable = false;
}
String file = null;
if (mExternalStorageWriteable) {
file = Environment.getExternalStorageDirectory() + "/abcd.pdf";
}
document.open();
PdfCopy writer = new PdfCopy(document, new FileOutputStream(file));
InputStream is = new FileInputStream(Environment.getExternalStorageDirectory()+"/new1.html");
PdfReader reader = new PdfReader(is);
PdfImportedPage page;
int n = reader.getNumberOfPages();
page = writer.getImportedPage(reader, n);
Image instance = Image.getInstance(page);
document.add(instance);
document.close();
Toast.makeText(this, "pdf created", Toast.LENGTH_LONG).show();
我已經使用itextpdf-5.4.3.jar。 同時運行此代碼我得到一個異常「找不到PDF頭標識」 ......任何一個可以幫助我