Name | Value | ||
---|---|---|---|
Lorem | Ipsum |
Source Code
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Editable
Table</title>
Name | Value | ||
---|---|---|---|
Lorem | Ipsum |
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Editable
Table</title>
Name | City | |
---|---|---|
Ram | Vns | |
Syam | Alld | |
Gita | LKO | |
Anita | Vns |
<html>
<head>
<title>Table
Select</title>
<style>
.chk {
}
</style>
This post will help you to create a PDF file from a URL in ASP.Net C#. Follow the steps given below. We will save a PDF file on the server then after viewing the PDF file, the file will be deleted.
Download Select.HtmlToPdf.NetCore package from NuGet.
Goto Tools Menu>Nuget Package Manager > Manage Nuget Package for Solution
function createPDF(pageurl)
{
$.ajax({
url: '/Common/htmltopdf/',
async: true,
dataType: "json",
type: "GET",
contentType: 'application/json; charset=utf-8',
data: { url: pageurl},
success: function (data) {
DelPDF('/upload/print/' + $.trim(invid) + '.pdf');
window.location.href = '/upload/print/' + $.trim(invid) + '.pdf';
}
});
}
function DelPDF(path)
{
$.ajax({
url: '/Common/DeleteCommonFile?path=' + path,
type: "POST",
contentType: false, // Not to
set any content header
processData: false, // Not to process data
success: function (result) {
//Update Extension
if (result.sMessage == "1")
{
}
else
alert(result.sMessage);
},
error: function (abc) {
alert(abc.statusText);
}
});
}
Controller C# code
public JsonResult htmltopdf(string url,string inv)
{
// instantiate
a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();
// create a new
pdf document converting an url
PdfDocument doc =
converter.ConvertUrl(url);
// save pdf
document
doc.Save(Server.MapPath("~/upload/print/" + inv + ".pdf"));
// close pdf
document
doc.Close();
return Json(new { sMessage = "11"}, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public JsonResult DeleteCommonFile(string path)
{
try
{
string filename = Server.MapPath(path);
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
return Json(new {
sMessage = "1",
JsonRequestBehavior.AllowGet });
}
catch (Exception ex)
{
return Json(new {
sMessage = ex.Message, JsonRequestBehavior.AllowGet });
}
}