ahmed salah

ahmed salah

  • 1.1k
  • 537
  • 33.3k

when export grid view have Arabic data to pdf format using JQUERY it d

May 24 2024 10:37 PM

I work on asp.net app . I face issue when export grid view with data to pdf it downloaded but

finally not open grid view have Arabic data when inspect browser to check error i can't found

any error I work on asp.net app . I face issue when export grid view with data to pdf it

downloaded but finally not open grid view have Arabic data when inspect browser to check error

i can't found any error

full code jQuery to export to pdf

$.each(Result.d, function (key, value) {
                if (value.Status == "1") {
                    $("#gvResults tbody").empty();
                    /*   $("#gvResults th").empty();*/
                    if (value.P_REQ_CURInfo != null) {
                        if (value.P_REQ_CURInfo.length > 0) {
                            var rowNo = 0;
                            for (var i in value.P_REQ_CURInfo) {
                                if (rowNo == 0) {
                                    /*                    $("#gvResults").append("<tr class='card-info card-header text-white text-center'><th>?</th><th>??? ???????</th><th>????? ???????</th><th>??? ???? ????? ??????</th><th>??? ????? ??????</th><th>??????? </th><th>??????</th><th> ??????? </th> <th>??? ?????? </th><th>????? ?????? </th><th> ??? ??? ?????? </th><th> ?????? ???? ????? ??????? </th><th>?????? ??????? ???????? </th></tr>");*/
                                    $("#gvResults").append("<tr class='card-info card-header text-white text-center'><th>?</th><th>??? ???????</th><th>????? ???????</th><th>??? ???? ????? ??????</th><th>??? ????? ??????</th><th>??????? </th><th>??????</th><th> ??????? </th> <th>??? ?????? </th><th>????? ?????? </th><th> ?????? ???? ????? ??????? </th><th>?????? ??????? ???????? </th></tr>");
                                }
                                var row = "<tbody><tr align='center' id='tr" + value.P_REQ_CURInfo[i].REQ_ID + "' class='record clickable-row'> " + "<td class='tdCount'>" +
                                    (rowNo + 1) + "</td><td>" +
                                    value.P_REQ_CURInfo[i].REQ_ID + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_DATE + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].BROKER_CIVIL_ID + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].BROKER_NAME + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_AREA_ID_DESC + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_AREA_BLOCK_NO + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_AREA_PLOT + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_AREA_CAT_DESC + "</td> <td>" +
                                    value.P_REQ_CURInfo[i].APPR_PROPERTY_SPACE + "</td> <td>" +
                                    /*      value.P_REQ_CURInfo[i].APPR_OTHER_AREA_DESC + "</td> <td>" +*/
                                    value.P_REQ_CURInfo[i].APPR_TOTAL_VALUE_LAND_BUILDING + "</td> <td>";
                                row += value.P_REQ_CURInfo[i].APPR_MARKET_VALUE_ESTIMATE + "</td>";
                                row += "</tr></tbody>";
                                row = $(row).hide();
                                $('#gvResults').append($(row));
                                rowNo++;
                                $(row).fadeIn(1000);
                            }
                        }
                    }
                }
                else {
                    ModelSuccessDanger('???? !!', value.StatusDesc, '0', null);
                }
            });

     `function GET_RE_APPR_REP_ReportPDF() {
    // Get the data from the GridView
    var $rows = $('#gvResults tbody tr');
    var data = [];

    // Loop through the rows and add the data to the data array
    $rows.each(function () {
        var $cols = $(this).find('td');
        var rowData = [];
        $cols.each(function () {
            rowData.push(encodeURIComponent($(this).text().trim()));
        });
        data.push(rowData);
    });

    // Add a header row
    var headers = [];
    $('#gvResults th').each(function () {
        headers.push(encodeURIComponent($(this).text().trim()));
    });
    data.unshift(headers);

    // Call the downloadPDF function
    downloadPDFDirect(data, "GridViewData");
    }
  

 function downloadPDFDirect(data, filename) {
    // Convert the data to a JSON string
    var jsonData = JSON.stringify(data);

    // Construct the PDF URL
    var pdfUrl = 'data:application/pdf;base64,' + btoa(jsonData);

    // Create a temporary link element and click it to initiate the download
    var link = document.createElement('a');

    link.setAttribute('download', filename + '.pdf');
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    }``

 


Answers (1)