-3
내 클라이언트 용 Android 용 epub 북 리더 앱을 만들고 있습니다. 내 응용 프로그램에서 현재 FolioReader을 사용하고 있지만 이미지를 표시하지 않습니다. .epub 파일을 Android에 표시하는 다른 방법이 있습니까?Android : 파싱 .epub 파일
미리 감사드립니다.
내 클라이언트 용 Android 용 epub 북 리더 앱을 만들고 있습니다. 내 응용 프로그램에서 현재 FolioReader을 사용하고 있지만 이미지를 표시하지 않습니다. .epub 파일을 Android에 표시하는 다른 방법이 있습니까?Android : 파싱 .epub 파일
미리 감사드립니다.
웹 뷰에서 데이터를로드하는 동안 이미지를 추출하고 해당 이미지에 대한 참조를 유지해야합니다. 이 코드를 사용해보십시오
outPutFolder=getDir("example", Context.MODE_PRIVATE) + "/"+fileName +"/" ;
//your directory name
try {
epubInputStream=new FileInputStream(filePath);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e) {
e.printStackTrace();
}
outPutFolder=getDir("example", Context.MODE_PRIVATE) + "/"+fileName +"/" ;
setOutPutFolder(outPutFolder);
DownloadResource(outPutFolder);
linezNew = "";
Spine spine = book.getSpine();
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
StringBuilder string = new StringBuilder();
for (int i = 0; count > i; i++) {
Resource res = spine.getResource(i);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
while ((line = reader.readLine()) != null) {
linezNew = string.append(line + "\n").toString();
}
} catch (IOException e) {e.printStackTrace();}
} catch (IOException e) {
e.printStackTrace();
}
}
linezNew = linezNew.replace("../", "");
finalDataToLoad="<head><style>img{max-width: 100%; width:50%; height: 50%;}</style></head> "+linezNew;
webView.loadDataWithBaseURL("file://" + outPutFolder, finalDataToLoad, "text/html", "utf-8", null);
및 DownloadResource 기능이 여기
private void DownloadResource(String directory) {
try {
Resources rst = book.getResources();
Collection<Resource> clrst = rst.getAll();
Iterator<Resource> itr = clrst.iterator();
while (itr.hasNext()) {
Resource rs = itr.next();
if ((rs.getMediaType() == MediatypeService.JPG)
|| (rs.getMediaType() == MediatypeService.PNG)
|| (rs.getMediaType() == MediatypeService.GIF)) {
Log.d("Href", rs.getHref());
File oppath1 = new File(directory, rs.getHref().replace("OEBPS/", ""));
oppath1.getParentFile().mkdirs();
oppath1.createNewFile();
System.out.println("Path : "+oppath1.getParentFile().getAbsolutePath());
FileOutputStream fos1 = new FileOutputStream(oppath1);
fos1.write(rs.getData());
fos1.close();
} else if (rs.getMediaType() == MediatypeService.CSS) {
File oppath = new File(directory, rs.getHref());
oppath.getParentFile().mkdirs();
oppath.createNewFile();
FileOutputStream fos = new FileOutputStream(oppath);
fos.write(rs.getData());
fos.close();
}
}
} catch (Exception e) {
}
}
적인 filePath이 ePub 파일 경로입니다 (EPUB lib 디렉토리 및 SLF4J 라이브러리를 추가), 파일 이름은 문자열
있는 당신의 ePub 파일의 이름입니다또한
을 문자열 outPutFolder, linezNew, finalDataToLoad는 여전히 표시 EpubParser https://github.com/mertakdut/EpubParser – AMB
@SpringBreaker하지보십시오 ying images – Ravi
@Redman 이미지가 잘못된 방식으로 표시됩니다. – Ravi