我想将 html 文件转换为 pdf 我的代码是
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 标头签名”......任何人都可以帮助我