Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is My code for download PDF from a jqgrid. I call this js page in My page. pdfExport is my button Id.

$(document).ready(function () {

$("#pdfExport").click(function () {
//alert("clicked");
//alert($("#jqxgrid1").jqxGrid);
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#tab_customers')[0]; //table Id
specialElementHandlers = {
'#htmlexportPDF': function(element, renderer) {
return true
}
};
margins = { //table margins and width
top: 80,
bottom: 60,
left: 40,
width: 100,
height: 200
};
pdf.fromHTML(
source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},

margins);

var gridContent = $("#jqxgrid1").jqxGrid('exportdata', 'html');
var filtercontent1 = '
Visit Type:-Camp Name:-Time Duration:-
'
pageContent =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<meta charset="utf-8" />\n' +
'<title>camp schedule report</title>\n' +
'</head>\n' +
'<body>\n' + filtercontent1 + '\n' + gridContent + '\n</body>\n</html>';
//filtercontent += gridContent;
console.log(pageContent);
pdf.fromHTML(pageContent, 15, 15, {
'width': 270,
'elementHandlers': specialElementHandlers
});
pdf.save('CampScheduleReport1.pdf');


});

});

What I have tried:

Same code work for my another page, but here I can't find the error. so plz fixed it or send some new logic for it..

Regards
Bigyan Sahoo
Posted
Updated 18-Apr-16 20:05pm
Comments
Shambhoo kumar 18-Apr-16 7:59am    
it's better to create RDLC and convert into PDF pro-grammatically for good format.
bigyan sahoo 18-Apr-16 8:01am    
send me some link for that..
Shambhoo kumar 18-Apr-16 8:08am    
Here is some code for Creating a PDF from a RDLC Report in the Background.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes = reportViewer.LocalReport.Render(
"PDF", null, out mimeType, out encoding, out filenameExtension,
out streamids, out warnings);

using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}

but first of all you need to design RDLC report.

Here is some link "How to create RDLC"

http://www.c-sharpcorner.com/UploadFile/6bb76f/create-rdlc-report-in-vs-2010-and-sql-server-2008/
Richard Deeming 18-Apr-16 11:03am    
If you want us to help you find the error, you need to tell us what the error is!

Click "Improve question" and update your question with a proper description of the problem. Include the full details of the error, and remember to indicate which line of code the error is thrown from.
ZurdoDev 18-Apr-16 15:23pm    
Why can't you debug it? It's rude to post a bunch of code and ask other people to debug it for you.

1 solution

There are two options for this question.
1- You can use RDLC for generate pdf Report.

2- My javascript code is also work fine but you have to add 2 more js file in your application, then it work fine.
<script src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.0.16/jspdf.plugin.autotable.js"></script>

Thanks
Code project team.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900