1

I have an android epub reader project which uses Readium SDK for opening epub files. I'm trying user to open pdf files to which I want to convert to epub, store it to internal storage and make it available for user to read through my epub reader application. Now I've searched for libraries and projects and found some but didn't meet my expectation.

Following are the resources I've tried:

Java PDF converter library

An opensource android project

I'm yet to try this LeadTools SDK which was suggested by this answer:

Leadtools SDK

Can anyone recommend me any libraries or resources regarding this?

5
  • Have you considered opening the PDF directly in your reader project? Android has had PDF viewing support for some time now. If not, and you really need PDF2EPUB, are you looking to convert the PDF to reflowable HTML or fixed layout HTML? – Ryan Sep 9 '20 at 5:43
  • @Ryan My project is a epub reader project. That's why I need to convert. This is the requirement. As it will have to be epub so it's reflowable HTML – Miq Sep 13 '20 at 6:44
  • "will have to be epub so it's reflowable HTML" Just so you know, EPUB supports fixed HTML layout, so you can do either in EPUB. – Ryan Sep 14 '20 at 16:52
  • "found some but didn't meet my expectation." What issues did you have with the 3 tools you listed in your question? – Ryan Sep 14 '20 at 16:53
  • @Ryan I'm now working with the second one. It seems to have working. Just an issue there. Bengali text extraction doesn't seem to work correctly. And that's an iText issue. – Miq Sep 15 '20 at 4:39
1

I've noticed one of the resources you listed is the LEADTOOLS SDK. (Disclosure: I'm a LEADTOOLS employee).

Converting to the ePub file format from an input PDF can be done through the use of the DocumentConverter as you have listed https://www.leadtools.com/help/sdk/v21/dh/doxc/documentconverter.html

To test this in Android code, you can try the following:

Uri imageUri = data.getData();
ILeadStream stream = LeadStreamFactory.create(getContentResolver().openInputStream(imageUri),true);
DocumentConverter convert = new DocumentConverter();
ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD);
ocrEngine.startup(null, null, null, OCR_RUNTIME_DIRECTORY);
convert.setOcrEngineInstance(ocrEngine, true);
convert.setDocumentWriterInstance(new DocumentWriter());

File file = new File(this.getFilesDir(), "output.epub");
String path = file.getAbsolutePath();

LEADDocument inputstream = DocumentFactory.loadFromStream(stream, new LoadDocumentOptions());
DocumentConverterJobData jobData = new DocumentConverterJobData();
jobData.setDocument(inputstream);
jobData.setOutputDocumentFileName(path);
jobData.setDocumentFormat(DocumentFormat.PUB);
jobData.setAnnotationsMode(DocumentConverterAnnotationsMode.EMBED);
jobData.setRasterImageBitsPerPixel(0);
jobData.setRasterImageFormat(RasterImageFormat.UNKNOWN);

DocumentConverterJob job = convert.getJobs().createJob(jobData);
convert.getJobs().runJob(job);

Assuming you are passing in a PDF file which is populated through imageUri, this will work. If you would like a starting template to work with, you can try supplying this code inside this template: https://www.leadtools.com/help/sdk/v21/tutorials/viewers/cross-platform/android/display-images-in-an-image-viewer.html

2
  • I have to convert Bengali language PDFs which are encoded in Unicode. Will this work in that case? – Miq Dec 10 '20 at 4:55
  • You will be able to convert your Bengali language PDFs to ePub as long as the original PDF file you are supplying is already searchable. Both PDF and ePub are both Document File Formats – Marvin Reid Dec 15 '20 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.