Giter Site home page Giter Site logo

gzehua / documentreader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from asutosh11/documentreader

0.0 1.0 0.0 173 KB

This library reads word documents (.doc and .docx), txt and PDF files, and gives the output content of the document as a String.

License: MIT License

Kotlin 100.00%

documentreader's Introduction

API Android Arsenal

DocumentReader

This library reads word documents (.doc and .docx), txt and PDF files, and gives the output content of the document as a String.

If you have ever tried to read contents of a PDF or MS word document on Android, you know how painful it is. This library makes your work easy.


Dependency for build.gradle (Module: app)


repositories {
  ...
  maven { url 'https://jitpack.io' }
}
dependencies {
  ....
  implementation 'com.github.Asutosh11:DocumentReader:0.12'
  
  // NOTE: use this only if you get a multidex exception
  implementation "androidx.multidex:multidex:2.0.1"
}
// NOTE: use this only if you get an error like - More than one file was found with OS independent path
packagingOptions {
   exclude 'META-INF/DEPENDENCIES'
   exclude 'META-INF/INDEX.LIST'
   exclude 'META-INF/spring.handlers'
   exclude 'META-INF/spring.schemas'
   exclude 'META-INF/cxf/bus-extensions.txt'
}
// NOTE: use this only if you get a multidex exception
defaultConfig {
   ...
   multiDexEnabled true
}


How to use it?


// Read a pdf file from Uri
val docString : String = DocumentReaderUtil.readPdfFromUri(fileUri, applicationContext)
// Read a pdf file from File
val docString : String = DocumentReaderUtil.readPdfFromFile(file, applicationContext)
// read a doc file from Uri
val docString : String = DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext)
// read a doc file from File
val docString : String = DocumentReaderUtil.readWordDocFromFile(file, applicationContext)
// read a docx file from Uri
val docString : String = DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext)
// read a docx file from File
val docString : String = DocumentReaderUtil.readWordDocFromFile(file, applicationContext)
// read a txt file from Uri
val docString : String = DocumentReaderUtil.readTxtFromUri(fileUri, applicationContext)
/*
 Even if you don't know your file type, 
 this library detects the file mime type and gives you the content of the file as a String
*/
val docString : String = when (DocumentReaderUtil.getMimeType(fileUri, applicationContext)) {
        "text/plain" -> DocumentReaderUtil.readTxtFromUri(fileUri, applicationContext)
        "application/pdf" -> DocumentReaderUtil.readPdfFromUri(fileUri, applicationContext)
        "application/msword" -> DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext)
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document" -> 
                                        DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext)
         else -> ""
	 }

Thanks

The Apache Tika project
Apache's PdfBox port by TomRoush

documentreader's People

Contributors

asutosh11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.