Search in sources :

Example 1 with MuPdfDocument

use of org.ebookdroid.droids.mupdf.codec.MuPdfDocument in project LibreraReader by foobnix.

the class HtmlContext method openDocumentInner.

@Override
public CodecDocument openDocumentInner(String fileName, String password) {
    Map<String, String> notes = null;
    try {
        FooterNote extract = HtmlExtractor.extract(fileName, CacheZipUtils.CACHE_BOOK_DIR.getPath());
        fileName = extract.path;
        notes = extract.notes;
        LOG.d("new file name", fileName);
    } catch (Exception e) {
        LOG.e(e);
    }
    MuPdfDocument muPdfDocument = new MuPdfDocument(this, MuPdfDocument.FORMAT_PDF, fileName, password);
    muPdfDocument.setFootNotes(notes);
    return muPdfDocument;
}
Also used : FooterNote(com.foobnix.ext.FooterNote) MuPdfDocument(org.ebookdroid.droids.mupdf.codec.MuPdfDocument)

Example 2 with MuPdfDocument

use of org.ebookdroid.droids.mupdf.codec.MuPdfDocument in project LibreraReader by foobnix.

the class CbrContext method openDocumentInner.

@Override
public CodecDocument openDocumentInner(String fileName, String password) {
    if (!cacheFile.isFile()) {
        LOG.d("Type no cache file");
        try {
            if (CbzCbrExtractor.isZip(fileName)) {
                CacheZipUtils.copyFile(new File(fileName), cacheFile);
            } else {
                String extractDir = CacheZipUtils.CACHE_BOOK_DIR + "/" + "CBR_" + fileName.hashCode();
                File cbrDir = new File(extractDir);
                cbrDir.mkdirs();
                try {
                    ExtractArchive.extractArchive(fileName, extractDir, password);
                } catch (OutOfMemoryError e) {
                    LOG.e(e);
                }
                CacheZipUtils.zipFolder(extractDir, cacheFile.getPath());
                CacheZipUtils.deleteDir(cbrDir);
            }
        } catch (Exception e) {
            LOG.e(e);
        }
    }
    MuPdfDocument muPdfDocument = new MuPdfDocument(this, MuPdfDocument.FORMAT_PDF, cacheFile.getPath(), password);
    return muPdfDocument;
}
Also used : MuPdfDocument(org.ebookdroid.droids.mupdf.codec.MuPdfDocument) File(java.io.File)

Example 3 with MuPdfDocument

use of org.ebookdroid.droids.mupdf.codec.MuPdfDocument in project LibreraReader by foobnix.

the class Fb2Context method openDocumentInner2.

public CodecDocument openDocumentInner2(final String fileName1, String password) {
    final String fileName = cacheFile1.getPath();
    Fb2Extractor.get().convertFB2(fileName1, fileName);
    MuPdfDocument muPdfDocument2 = new MuPdfDocument(this, MuPdfDocument.FORMAT_PDF, fileName, password) {

        @Override
        public java.util.List<OutlineLink> getOutline() {
            List<OutlineLink> res = new ArrayList<OutlineLink>();
            try {
                String encoding = Fb2Extractor.findHeaderEncoding(fileName1);
                List<String> titles = Fb2Extractor.getFb2Titles(fileName1, encoding);
                for (int i = 0; i < titles.size(); i++) {
                    String string = titles.get(i).replace("~@~[title]", "###");
                    String[] full = string.split("###");
                    int level = Integer.parseInt(full[0]);
                    String title = full[1];
                    String linkUri = "#" + (i + 1);
                    res.add(new OutlineLink(title + linkUri, "", level, getDocumentHandle(), linkUri));
                }
            } catch (Exception e) {
                LOG.e(e);
            }
            return res;
        }
    };
    return muPdfDocument2;
}
Also used : OutlineLink(org.ebookdroid.core.codec.OutlineLink) MuPdfDocument(org.ebookdroid.droids.mupdf.codec.MuPdfDocument) ArrayList(java.util.ArrayList)

Example 4 with MuPdfDocument

use of org.ebookdroid.droids.mupdf.codec.MuPdfDocument in project LibreraReader by foobnix.

the class MobiContext method openDocumentInner.

@Override
public CodecDocument openDocumentInner(String fileName, String password) {
    LOG.d("Context", "MobiContext", fileName);
    if (cacheFile.isFile()) {
        fileNameEpub = cacheFile.getPath();
        LOG.d("Context", "MobiContext cache", fileNameEpub);
    } else {
        try {
            int outName = BookCSS.get().isAutoHypens ? "temp".hashCode() : originalHashCode;
            FooterNote extract = MobiExtract.extract(fileName, CacheZipUtils.CACHE_BOOK_DIR.getPath(), outName + "");
            fileNameEpub = extract.path;
            if (BookCSS.get().isAutoHypens) {
                EpubExtractor.proccessHypens(fileNameEpub, cacheFile.getPath());
                fileNameEpub = cacheFile.getPath();
            }
            LOG.d("Context", "MobiContext extract", fileNameEpub);
        } catch (Exception e) {
            LOG.e(e);
        }
    }
    final MuPdfDocument muPdfDocument = new MuPdfDocument(this, MuPdfDocument.FORMAT_PDF, fileNameEpub, password);
    final File jsonFile = new File(cacheFile + ".json");
    if (jsonFile.isFile()) {
        muPdfDocument.setFootNotes(JsonHelper.fileToMap(jsonFile));
        LOG.d("Load notes from file", jsonFile);
    } else {
        new Thread() {

            @Override
            public void run() {
                Map<String, String> notes = null;
                try {
                    notes = EpubExtractor.get().getFooterNotes(fileNameEpub);
                    LOG.d("new file name", fileNameEpub);
                    muPdfDocument.setFootNotes(notes);
                    JsonHelper.mapToFile(jsonFile, notes);
                    LOG.d("save notes to file", jsonFile);
                    removeTempFiles();
                } catch (Exception e) {
                    LOG.e(e);
                }
            }
        }.start();
    }
    return muPdfDocument;
}
Also used : FooterNote(com.foobnix.ext.FooterNote) MuPdfDocument(org.ebookdroid.droids.mupdf.codec.MuPdfDocument) File(java.io.File) Map(java.util.Map)

Example 5 with MuPdfDocument

use of org.ebookdroid.droids.mupdf.codec.MuPdfDocument in project LibreraReader by foobnix.

the class TxtContext method openDocumentInner.

@Override
public CodecDocument openDocumentInner(String fileName, String password) {
    Map<String, String> notes = null;
    try {
        FooterNote extract = TxtExtract.extract(fileName, CacheZipUtils.CACHE_BOOK_DIR.getPath());
        fileName = extract.path;
        notes = extract.notes;
        LOG.d("new file name", fileName);
    } catch (Exception e) {
        LOG.e(e);
    }
    MuPdfDocument muPdfDocument = new MuPdfDocument(this, MuPdfDocument.FORMAT_PDF, fileName, password);
    muPdfDocument.setFootNotes(notes);
    return muPdfDocument;
}
Also used : FooterNote(com.foobnix.ext.FooterNote) MuPdfDocument(org.ebookdroid.droids.mupdf.codec.MuPdfDocument)

Aggregations

MuPdfDocument (org.ebookdroid.droids.mupdf.codec.MuPdfDocument)7 File (java.io.File)4 FooterNote (com.foobnix.ext.FooterNote)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)1 OutlineLink (org.ebookdroid.core.codec.OutlineLink)1