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("? ??? ??????? ????? ??????? ??? ???? ????? ?????? ??? ????? ?????? ??????? ?????? ??????? ??? ?????? ????? ?????? ??? ??? ?????? ?????? ???? ????? ??????? ?????? ??????? ???????? ");*/
$("#gvResults").append("? ??? ??????? ????? ??????? ??? ???? ????? ?????? ??? ????? ?????? ??????? ?????? ??????? ??? ?????? ????? ?????? ?????? ???? ????? ??????? ?????? ??????? ???????? ");
}
var row = " " + "" +
(rowNo + 1) + " " +
value.P_REQ_CURInfo[i].REQ_ID + " " +
value.P_REQ_CURInfo[i].APPR_DATE + " " +
value.P_REQ_CURInfo[i].BROKER_CIVIL_ID + " " +
value.P_REQ_CURInfo[i].BROKER_NAME + " " +
value.P_REQ_CURInfo[i].APPR_AREA_ID_DESC + " " +
value.P_REQ_CURInfo[i].APPR_AREA_BLOCK_NO + " " +
value.P_REQ_CURInfo[i].APPR_AREA_PLOT + " " +
value.P_REQ_CURInfo[i].APPR_AREA_CAT_DESC + " " +
value.P_REQ_CURInfo[i].APPR_PROPERTY_SPACE + " " +
/* value.P_REQ_CURInfo[i].APPR_OTHER_AREA_DESC + " " +*/
value.P_REQ_CURInfo[i].APPR_TOTAL_VALUE_LAND_BUILDING + " ";
row += value.P_REQ_CURInfo[i].APPR_MARKET_VALUE_ESTIMATE + " ";
row += " ";
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);
}``
Jithu ThomasPosted May 25, 2024, 7:03 AM
In your
downloadPDFDirectfunction, before creating the link, set theContent-Typeheader of the temporary link element toapplication/pdf;charset=utf-8Optional: -
If you have more control over the PDF generation process on server side, consider generating the PDF on the server-side using a library like iTextSharp or Aspose.PDF. These libraries allow you to specify the character encoding during PDF creation, ensuring Arabic characters display correctly.