🛠️ Fix crash with PDF parser
* Fixed crash due to not initialized PDFBoxResourceLoader
This commit is contained in:
parent
4b166f71e7
commit
3b26b94ddc
2 changed files with 12 additions and 2 deletions
|
|
@ -12,7 +12,9 @@ import ua.acclorite.book_story.domain.util.UIText
|
|||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class PdfFileParser @Inject constructor(private val application: Application) : FileParser {
|
||||
class PdfFileParser @Inject constructor(
|
||||
private val application: Application
|
||||
) : FileParser {
|
||||
|
||||
override suspend fun parse(file: File): BookWithCover? {
|
||||
return try {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package ua.acclorite.book_story.data.parser.pdf
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log
|
||||
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
|
||||
import com.tom_roush.pdfbox.pdmodel.PDDocument
|
||||
import com.tom_roush.pdfbox.text.PDFTextStripper
|
||||
import kotlinx.coroutines.yield
|
||||
|
|
@ -15,7 +17,9 @@ import javax.inject.Inject
|
|||
|
||||
private const val PDF_TAG = "PDF Parser"
|
||||
|
||||
class PdfTextParser @Inject constructor() : TextParser {
|
||||
class PdfTextParser @Inject constructor(
|
||||
private val application: Application
|
||||
) : TextParser {
|
||||
|
||||
override suspend fun parse(file: File): Resource<List<ChapterWithText>> {
|
||||
Log.i(PDF_TAG, "Started PDF parsing: ${file.name}.")
|
||||
|
|
@ -23,6 +27,10 @@ class PdfTextParser @Inject constructor() : TextParser {
|
|||
return try {
|
||||
yield()
|
||||
|
||||
PDFBoxResourceLoader.init(application)
|
||||
|
||||
yield()
|
||||
|
||||
val oldText: String
|
||||
|
||||
val pdfStripper = PDFTextStripper()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue