我已将docx转换为html,并能够在带有图像的webview中显示它。但是,当我尝试将从webview中提取的html保存到内部存储时,图像不可见,而是在保存的html文件中留下空白区域。
执行此操作的代码如下:
view = (WebView) findViewById(R.id.webpage);
final long startTime = System.currentTimeMillis();
final long endTime;
try {
final LoadFromZipNG loader = new LoadFromZipNG();
WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage)loader.get(new FileInputStream(new File(Environment.getExternalStorageDirectory()+"/"+getIntent().getStringExtra("textReportFileName"))));
String IMAGE_DIR_NAME = "images";
String baseURL = this.getDir(IMAGE_DIR_NAME, Context.MODE_WORLD_READABLE).toURL().toString();
System.out.println(baseURL); // file:/data/data/com.example.HelloAndroid/app_images/
// Uncomment this to write image files to file system
ConversionImageHandler conversionImageHandler = new AndroidFileConversionImageHandler( IMAGE_DIR_NAME, // <-- don't use a path separator here
baseURL, false, this);
Toast.makeText(getApplicationContext(),基本URL,Toast.LENGTH_SHORT).show();
HtmlExporterNonXSLT withoutXSLT = new HtmlExporterNonXSLT(wordMLPackage, conversionImageHandler);
html = XmlUtils.w3CDomNodeToString(withoutXSLT.export());
File filex = new File(Environment.getExternalStorageDirectory()+"/temp/"+getIntent().getStringExtra("textReportFileName").replace("docx","html"));
if(filex.exists()) {
Toast.makeText(getApplicationContext(),"File exists",Toast.LENGTH_SHORT).show();
InputStream iss = new FileInputStream(filex);
int size = iss.available();
byte[] buffer = new byte[size];
iss.read(buffer);
iss.close();
html = new String(buffer);
//html = html.substring(html.indexOf("0\" rows=\"9\">") + 16);
}
else{
}
} catch (Exception e) {
e.printStackTrace();
finish();
} finally {
endTime = System.currentTimeMillis();
}
突出显示的toast消息给出了输出:file:/data/data/com.tek.teksmartlab/app_images /
最后的html文件还有带src =&#34;文件的图像标签:/ data / data / com.tek.teksmartlab / app_images / image1.jpg&#34; (比如表格)
现在我了解路径文件:/data/data/com.tek.teksmartlab/app_images/在内部存储中不存在,因此HOW DO I SAVE THE IMAGES FROM THIS PATH TO INTERNAL STORAGE??
我尝试将图像从资源文件夹复制到内部存储代码,但这对我没有用。
答案 0 :(得分:0)
url
未完成,您需要以file://
开头,所以整个事情将是
file:///data/data/com.tek.teksmartlab/app_images/image1.jpg