Monday 28 November 2022

Editable Table Jquery

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>

   

Saturday 12 November 2022

Select A Table all rows by checkbox using jquery

Select/Unselect  Table all row by clicking the checkbox using jquery. You can do this by class selector. Make a class and apply it on all checkbox and select or unselect using class name by just one line of code.

Name City
Ram Vns
Syam Alld
Gita LKO
Anita Vns

Code

<html>

<head>

    <title>Table Select</title>

    <style>

        .chk {

        }

    </style>

Thursday 10 November 2022

Make PDF from hyperlink | ASP.NET C#


 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. 

Step 1 : 

Download Select.HtmlToPdf.NetCore package from NuGet. 

Goto Tools Menu>Nuget Package Manager > Manage Nuget Package for Solution

Step 2 : 

 
 Create a Button and call the javascript function, which will create a PDF file from the given URL. The passing argument is URL of the page. Which will be converted into PDF file on the server at the given path. Then you can download the file.

<input type="button" value="Get PDF" onclick="createPDF('https://girfa.co.in/')" />

Step 3 


Javascript Code

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); 

                }

            });

}

Step 4

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 });

            }

        }