Product: PDFTron SDK
Product Version: 9.0177774
Hello,
I am loading a PDF from a remote URL and annotating on them. Once the annotations are done, I want to save this to cache or external file location. I have used doc.save() method. But I am getting below error.
libc++abi: terminating with unexpected exception of type trn::Common::Exception: Exception:
Message: Is a directory
Conditional expression: m_stream != NULL
Version : 9.0.1.77774
Platform : Android
Architecture : Arm
Filename : StdFile.cpp
Function : InitL
Linenumber : 221
Below is my code to load and save pdf.
// Loading PDF from http url
val url = "https://example.com/myfile.pdf"
pdfviewctrl.openUrlAsync(url, cacheDir?.absolutePath, null, httpOptions)
// After adding the annotations, I am executing below to save the file to cache location. (Or I want to get the file path of annotated pdf)
val uri = FileUtils.createPdfTempFile(this@PdfAnnotatorActivity)
// the uri value is - content://com.myapp.fileprovider/external_files/Documents/Checked_20210827.pdf
// after getting the url, I am calling save() method.
// Method 1 tried:
var filter = SecondaryFileFilter(this@PdfAnnotatorActivity, uriPdf)
pdfviewctrl.doc.lock()
pdfviewctrl.doc.save(filter, SDFDoc.SaveMode.LINEARIZED)
// Method 2 tried:
val path = FileUtils.createPdfFile(this@PdfAnnotatorActivity)
// path is absolute path of pdf file
pdfviewctrl.doc.lock()
pdfviewctrl.doc.save(path, SDFDoc.SaveMode.LINEARIZED, null)
// Method to get temporaty file path
@Throws(IOException::class)
fun createPdfFile(context: Context): String? {
// Create an image file name
var path: String? = null
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
val storageDir: File? = context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
File.createTempFile(
"PDF_${timeStamp}_", /* prefix */
".pdf", /* suffix */
storageDir /* directory */
).apply {
// Save a file: path for use with ACTION_VIEW intents
path = absolutePath
}
return path
}
I have used same method createPdfFile() to save a Generated pdf on the fly, it’s working fine. The above error is thrown when loading https url.
Update:
Now I see the above same error while adding Text Annotations also randomly.
Please help me solving this issue.
Thank You