itext pdf一个表格取决于在Android中创建的多个表格数据

时间:2019-04-25 05:30:47

标签: json kotlin itext

Json Data在表中显示itxet pdf。

所有JSON数据在代码下方显示一个表,但是如何创建表取决于创建的JSON键“ PartyName”值更改表?

我正在使用Retrofit2和rxjava2来解析JSON数据。

我必须分离表中显示的数据。

"PartyName”是JSON键。当"PartyName"更改其对象数据在另一表中的显示时,"PartyName"值将在一个表中显示。

PartyName值更改其创建的新表显示数据。

如何在itext pdf中创建更多表格,请指导我?

还有其他适用于Android的报告工具吗?

{
    "status": 1,
    "0": [
        {
            "Cmp_Name": "ABC",
            "Partyid": "18",
            "ChallanNo": "-",
            "PartyName": "PURCHASE MH",
            "FirmName": "PURCHASE MH",
            "ChallanDate": "-",
            "ChallanAmount": "0.0",
            "RecieveDate": "2019-03-15 00:00:00",
            "RecieveAmount": "4000.0",
            "DiscountAmount": "0.0",
            "TDSAmount": "0.0",
            "Bank": "AXIS BANK",
            "ChequeNo": null,
            "ChequeDate": null
        },
        {
            "Cmp_Name": "ABC",
            "Partyid": "17",
            "ChallanNo": "20",
            "PartyName": "PURCHASE GJ",
            "FirmName": "PURCHASE GJ",
            "ChallanDate": "3/11/2019",
            "ChallanAmount": "1391.0",
            "RecieveDate": "2019-03-15 00:00:00",
            "RecieveAmount": "1391.0",
            "DiscountAmount": "0.0",
            "TDSAmount": "0.0",
            "Bank": "AXIS BANK",
            "ChequeNo": "321456",
            "ChequeDate": "2019-03-15 00:00:00"
        },
        {
            "Cmp_Name": "ABC",
            "Partyid": "17",
            "ChallanNo": "20",
            "PartyName": "Dharama",
            "FirmName": "Dharama",
            "ChallanDate": "3/11/2019",
            "ChallanAmount": "1391.0",
            "RecieveDate": "2019-03-15 00:00:00",
            "RecieveAmount": "1391.0",
            "DiscountAmount": "0.0",
            "TDSAmount": "0.0",
            "Bank": "AXIS BANK",
            "ChequeNo": "321456",
            "ChequeDate": "2019-03-15 00:00:00"
        },
        {
            "Cmp_Name": "ABC",
            "Partyid": "17",
            "ChallanNo": "20",
            "PartyName": "Dharama",
            "FirmName": "Dharama",
            "ChallanDate": "3/11/2019",
            "ChallanAmount": "1391.0",
            "RecieveDate": "2019-03-15 00:00:00",
            "RecieveAmount": "1391.0",
            "DiscountAmount": "0.0",
            "TDSAmount": "0.0",
            "Bank": "AXIS BANK",
            "ChequeNo": "321456",
            "ChequeDate": "2019-03-15 00:00:00"
        }
    ]
}

itext pdf中创建一个表,但我想在JSON上方的数据键"PartyName"上更改另一个表中的显示数据。

有趣的pdfViewer(purchaseOut:List,fDate:String,tDate:String,todayDate:String){

val document = Document()
try {
    val SDCardRoot = Environment.getExternalStorageDirectory()
    val dir = File(SDCardRoot.getAbsolutePath() + dirPath)
    if (!dir.exists()) {
        dir.mkdirs()
    }
    val d = Date()
    val s = DateFormat
            .format("yyyyMMdd", d.getTime())
    val ran = java.util.Random()
    var n = 10000
    n = ran.nextInt(n)
    //var file = File(dir,   ".pdf")
    //val targetPdf = "/sdcard/pdffromlayout.pdf"
    //  val targetPdf = file
    val pathName: String = "purchaseOut" + s + ".pdf"
    val filePath: File
    filePath = File(dir, pathName)
    val docWriter = PdfWriter.getInstance(document, FileOutputStream(filePath))
    document.open()
    val cb = docWriter.getDirectContent()




    initializeFonts()

    createHeadings(cb, 260F, 780F, companyName )
    createHeadings(cb, 190F, 765F, "Party Wise Purchase Pending Report(Summary)")
    //createHeadings(cb, 265F, 750F, "GST IN : "+ salesGSt.get(1).GSTIN)
    createHeadings(cb, 35F, 660F, "Date : "+todayDate)
    createHeadings(cb, 327F, 660F, "From Date :" +fDate)
    createHeadings(cb, 439F, 660F, "To Date :"+tDate)


    /* var header = PdfPTable(1)
     var cellHeader = PdfPCell(Phrase("CompanyName"))
     header.setHorizontalAlignment(Element.ALIGN_CENTER)
    // cellHeader.setName("Hi")
     header.addCell(cellHeader)
     header.setWidthPercentage(100F)*/

    val columnWidths = floatArrayOf(0.75f, 5f, 2f, 2f, 2.5f, 2f, 2.5f)
    //var cell : PdfPCell
    var table = PdfPTable(columnWidths)
    table.setTotalWidth(500f)
    var cell = PdfPCell(Phrase("Sr.No"))
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT)

    table.addCell(cell)

    cell = PdfPCell(Phrase("Party Name"))
    cell.setHorizontalAlignment(Element.ALIGN_LEFT)
    table.addCell(cell)
    cell = PdfPCell(Phrase("Opening Balance"))
    cell.setHorizontalAlignment(Element.ALIGN_LEFT)
    table.addCell(cell)
    cell = PdfPCell(Phrase("Bill Amount"))
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT)
    table.addCell(cell)
    cell = PdfPCell(Phrase("Rcv Amount"))
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT)
    table.addCell(cell)
    cell = PdfPCell(Phrase("Other Amount"))
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT)
    table.addCell(cell)
    cell = PdfPCell(Phrase("Closing Balance"))
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT)
    table.addCell(cell)


    table.setHeaderRows(1)
    val df = DecimalFormat("0.00")
    for (j in 0 until purchaseOut.size) {
        val price = java.lang.Double.valueOf(df.format(Math.random() * 10))
        //  val extPrice = price * (i + 1)
        /*val inputFormatter1 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val date1 = inputFormatter1.parse(salesGSt.get(j).ChallanDate)
        val outputFormatter1 = SimpleDateFormat("dd-MMM-yyyy")
        var bill_date = outputFormatter1.format(date1)*/

        if (purchaseOut.get(j).FirmName != null) {
            partyName = purchaseOut.get(j).FirmName!!
        } else {
            partyName = ""
        }

        if (purchaseOut.get(j).Balance != null) {
            openingBalance = purchaseOut.get(j).Balance!!
        } else {
            openingBalance = ""
        }
        if (purchaseOut.get(j).CR != null) {
            billAmount = purchaseOut.get(j).CR!!
        } else {
            billAmount = ""
        }
        if (purchaseOut.get(j).DB != null) {
            rcvAmt = purchaseOut.get(j).DB!!
        } else {
            rcvAmt = ""
        }

        if (purchaseOut.get(j).OtherAmt != null) {
            otherAmt = purchaseOut.get(j).OtherAmt!!
        } else {
            otherAmt = ""
        }

        if (purchaseOut.get(j).ClBalance != null) {
            cLBalance = purchaseOut.get(j).ClBalance!!
        } else {
            cLBalance = ""
        }


        table.addCell((j + 1).toString())
        table.addCell(partyName)
        table.addCell(openingBalance)
        table.addCell(billAmount)
        table.addCell(rcvAmt)
        table.addCell(otherAmt)
        table.addCell(cLBalance)

        //table.addCell(df.format(extPrice))
    }
    table.writeSelectedRows(0, -1, document.leftMargin(), 650F, docWriter.getDirectContent())
    document.close()

    openGeneratedPDF(pathName)
} catch (e: Exception) {

    e.printStackTrace()

}

}

显示数据为下方图像。

enter image description here

0 个答案:

没有答案