I Want save (download) navigated Map as Image which contain root navigated also visited spot but when I am saving it as image then it is showing only navigated line
it is not showing map.
What I have tried:
written Javascript function WHich take Id of div on which navigated map is present as follows
<script type="text/javascript" src="http://cdn.rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script>
<script type="text/javascript">
function ConvertToImage(btnExportPdf) {
debugger;
alert("Hi");
html2canvas($("#MyWhiteBoxMap")[0]).then(function (canvas) {
debugger;
var base64 = canvas.toDataURL();
$("[id*=hfImageData]").val(base64);
debugger;
__doPostBack(btnExportPdf.name, "");
});
return false;
}
</script>
then on button click I am calling function
<asp:Button ID="btnExportPdf" runat="server" CssClass="btn btn-default" Text="To PDF Report" OnClientClick="Export()" OnClick="btnExportPdf_Click" ToolTip="Export Excel" />
server button click code is as follows
protected void btnShowPrint_Click(object sender, System.EventArgs e)
{
string companyName = "";
int orderNo = 2303;
DataTable dt = new DataTable();
if (ViewState["RecordData"] != null) { dt = (DataTable)ViewState["RecordData"]; }
divReportInput.Visible = false;
backgroundDiv.Visible = false;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
sb.Append("<div style='text-align:center'>Report</div>");
sb.Append("<table style='width:100%'>");
sb.Append(" <tr> <td >Device Name</td><td >: " + txtDeviceName.Text + "</td><td></td><td></td> </tr>");
sb.Append(" <tr></td>");
sb.Append("<td >Test Name</td> <td >: " + txtTestName.Text + "</td>");
sb.Append(" <td >Report Generated by</td><td>: " + txtReportGeneratedby.Text + "</td>");
sb.Append("</tr>");
sb.Append(" <tr>");
sb.Append(" <td >Start Date</td> <td >: " + txtStartDate.Text + "</td>");
sb.Append("<td >End Date</td> <td >: " + txtEndDate.Text + "</td>");
sb.Append("</tr>");
sb.Append(" </table>");
sb2.Append("<div style='text-align:center'>ROOT MAP</div>");
System.IO.StringReader sr = new System.IO.StringReader(sb.ToString());
System.IO.StringReader sr2 = new System.IO.StringReader(sb2.ToString());
byte[] file;
file = System.IO.File.ReadAllBytes(Server.MapPath("img/A.png"));
iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(file);
png.ScaleToFit(800F, 500F);
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
Response.Clear();
Response.ContentType = "image/png";
Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
MemoryStream storeStream = new MemoryStream();
MemoryStream ms = new MemoryStream(bytes);
FileStream file1 = new FileStream(Server.MapPath("img/HTML100.png") , FileMode.Create,
FileAccess.Write);
ms.WriteTo(file1);
file1.Close();
ms.Close();
Response.End();
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate(), 10f, 10f, 10f, 0f);
iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc);
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Add(png);
htmlparser.Parse(sr2);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Record Report.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}