Error while importing FormData into PDF

Product:Demo

Product Version:Latest

Please give a brief summary of your issue:
(Think of this as an email subject)
Error while importing FormData into PDF

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I wanted to import XFDF string to PDF document.
Below code i have tried with

        val file = createNewFile()
        // add blank pdf in filepath
        mPdfDoc = PDFDoc(file?.absolutePath)
        val xfdf_string = xfdfSample
        val fdf_doc = FDFDoc.createFromXFDF(xfdf_string)
        mPdfDoc?.fdfMerge(fdf_doc)
        mPdfViewCtrl?.doc = mPdfDoc

// Creating new Pdf file:
fun createNewFile():String{
try {
val rootPath: String = requireContext().cacheDir
.absolutePath.toString() + “/XFDF/”
val root = File(rootPath)
if (!root.exists()) {
root.mkdirs()
}

        val f = File(rootPath + "sample.pdf")
        if (f.exists()) {
            f.delete()
        }
        f.createNewFile()
        val out = FileOutputStream(f)
        out.flush()
        out.close()
        return f
    } catch (e: java.lang.Exception) {
        e.printStackTrace()
    }

}

I am facing the error like,
"Exception:
Message: PDF header not found. The file is not a valid PDF document.
Conditional expression: false
Filename : Parser.cpp
Function : SkipHeader
Linenumber : 1163
Error code : 0
"
I am following something wrong. Please correct me with correct approach.

Thanks in Advance.
Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

The error

PDF header not found. The file is not a valid PDF document.

means that you are passing a non-PDF file to the PDFDoc constructor. Please double check exactly what you are passing into the PDFDoc constructors (check the binary/hex data perhaps).

Note that XFDF is not a PDF file.

If you are still stuck, then please provide the exact PDF file you are trying to open.
Also confirm the exact line of code that throws the exception.

Hi,

I resolved to fix the crash while loading pdf. But, I am unable to see the expected result after importing xfdf string into PDF.

I am sending here below with all details. Please assist me what am i doing wrong.

Here is my code:

val file = Utils.copyResourceToLocal(activity, resourceId, fileName, “.pdf”)
mPdfDoc = PDFDoc(file.absolutePath)

    // XFDF loading:
    val xfdf_string = xfdfSample
    val fdf_doc = FDFDoc.createFromXFDF(xfdf_string)
    mPdfDoc?.fdfMerge(fdf_doc)

    mPdfViewCtrl?.doc = mPdfDoc.

Here, I am trying to import xfdf string ( given in attachment ) into “inspection_sample_pdf” from attachment. I have attached the attachment of expected result & how this is showing in PDFTron.

Missing Info are:
The dropdown data like: Insp. agency, TIO reference, drop & selected radio options are not matching with Expected attached photo.
inspection_sample_pdf.pdf (477.2 KB)



xfdf_data.pdf (97.3 KB)

I believe we’ve resolved this thread as part of Not matching with expected PDF after importing XFDF into PDF file, @Manoj if that is not the case please let us know by adding new information, a new sample project, current output, expected output so we can continue. Thanks.