Wednesday, April 27, 2011

conveting html to pdf


http://www.devtoolshed.com/content/c-free-component-

generate-pdf-convert-html-pdf



under button click
=====================



     // set a path to where you want to write the PDF to.

string sPathToWritePdfTo = @"d:\new_pdf_name.pdf";



// build some HTML text to write as a PDF.  You could also

// read this HTML from a file or other means.

// NOTE: This component doesn't understand CSS or other

// newer style HTML so you will need to use depricated

// HTML formatting such as the <font> tag to make it look correct.

System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();

sbHtml.Append("<html>");

sbHtml.Append("<body>");

sbHtml.Append("<font size='14'>My Document Title Line</font>");

sbHtml.Append("<br />");

sbHtml.Append("This is my document text");

sbHtml.Append("</body>");

sbHtml.Append("</html>");



// create file stream to PDF file to write to

using (System.IO.Stream stream = new System.IO.FileStream

(sPathToWritePdfTo, System.IO.FileMode.OpenOrCreate))

{

    // create new instance of Pdfizer

    Pdfizer.HtmlToPdfConverter htmlToPdf = new Pdfizer.HtmlToPdfConverter();

    // open stream to write Pdf to to

    htmlToPdf.Open(stream);

    // write the HTML to the component

    htmlToPdf.Run(sbHtml.ToString());

    // close the write operation and complete the PDF file

    htmlToPdf.Close();

}

//This component also supports PDF Chapters. You could add a single line of code right before the Run() method to make the HTML specified a single chapter like this:

// open stream to write Pdf to to

//htmlToPdf.Open(stream);



//// add a chapter for this HTML

//htmlToPdf.AddChapter("My Chapter Title 1");



//// write the HTML to the component

//htmlToPdf.Run(sbHtml.ToString());

Tuesday, April 26, 2011

good looking imgaes using jquey

http://www.templatezone.com/html-email-marketing-software/high-impact-email-free-trial-download


http://www.campaignmonitor.com/templates/

Saturday, April 16, 2011

Tuesday, April 12, 2011

emailcode using in handler

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Configuration;
using System.Net.Mail;
using System.Net.Configuration;

//using System.Web.Mail;



public class EmailHandler : IHttpHandler {

    string result = null;
    int id = 0;
    String strMethodName = String.Empty;

    string smtpHost;
    string smtpport;
    string smtpuser;
    string smtppwd;
    SmtpClient client = null;

   
    SqlConnection con = null;
    DataSet ds;
   StringBuilder sb = new StringBuilder();

   
    public void ProcessRequest (HttpContext context) {
       
         con = new SqlConnection("Data Source=CRM1-PC;Initial Catalog=LibraryApp;User ID=sa;Password=hyd@345");
        context.Response.ContentType = "text/plain";
        strMethodName = "sendemail";

        if (!String.IsNullOrEmpty(context.Request.QueryString["StrMethodName"]))
        {
          //  strMethodName = Convert.ToString(context.Request.QueryString["StrMethodName"]);
            strMethodName = "sendemail";
        }

       

        //if (!String.IsNullOrEmpty(context.Request.Form["CategoryId"]))
        //{
        //    categoryId = Convert.ToInt32(context.Request.Form["CategoryId"]);
        //}


        //if (!String.IsNullOrEmpty(context.Request.QueryString["StrMethodName"]))
        //{
        //    strMethodName = Convert.ToString(context.Request.QueryString["StrMethodName"]);
        //}

        if (strMethodName.Length > 0 && strMethodName.Equals("sendemail"))
        {

            bool Result = SendMail("giribhushan1988@gmail.com","hi","hello");
            context.Response.Write(Result);
          
        }
      
     
    }



   
    private static MailMessage message = null;


    public bool SendMail(string toMailAddress, string mailSubject, string mailMessage)
    {
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
        MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
         smtpHost = settings.Smtp.Network.Host;
         smtpport = settings.Smtp.Network.Port.ToString();
         smtpuser = settings.Smtp.Network.UserName;
         smtppwd = settings.Smtp.Network.Password;
       
     



        string MessageBody = string.Empty;
        try
        {

            message = new MailMessage();
            message.From = new MailAddress(smtpuser);
        
            message.To.Add(toMailAddress);
           
            message.BodyEncoding = System.Text.Encoding.UTF8;
           
            message.Subject = mailSubject;
            message.Body = mailMessage.ToString();



            message.IsBodyHtml = true;

            client = new SmtpClient();
            client.Host = smtpHost;
            //if (isSSLEnabled)
            //{
            //    client.EnableSsl = true;
            //}

            client.Port =  Convert.ToInt32(smtpport);
            client.EnableSsl = false;
            client.Credentials = new System.Net.NetworkCredential(smtpuser, smtppwd);
          
            client.Send(message);
        }
        catch (Exception ex)
        {
            string x = ex.Message;
        }
        return true;
    }
   

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Handler code

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web.Mail;


public class EmailHandler : IHttpHandler {

    string result = null;
    int id = 0;
    SqlConnection con = null;
    DataSet ds;
   StringBuilder sb = new StringBuilder();
 
   
    public void ProcessRequest (HttpContext context) {
       
         con = new SqlConnection("Data Source=CRM1-PC;Initial Catalog=LibraryApp;User ID=sa;Password=hyd@345");
        context.Response.ContentType = "text/plain";


        string Mehtodname = "sendemail";//context.Request.QueryString["str"].ToString();
       

        //if (!String.IsNullOrEmpty(context.Request.Form["CategoryId"]))
        //{
        //    categoryId = Convert.ToInt32(context.Request.Form["CategoryId"]);
        //}


        //if (!String.IsNullOrEmpty(context.Request.QueryString["StrMethodName"]))
        //{
        //    strMethodName = Convert.ToString(context.Request.QueryString["StrMethodName"]);
        //}

        //if (strMethodName.Length > 0 && strMethodName.ToUpper().Equals("REGISTERUSER"))
        //{

        //    Result = RegisterUser();
        //    context.Response.Write(Result);
        //    //context.Response.Write("<div><p><strong>Name : </strong>" + strSalutation + " " + strFirstName + " " + strLastName + "</p><p><strong>Email: </strong>" + strEmailID + "</p><p><strong>Location: </strong> " + strCity + ", " + strContactNo + ", " + strReferalId + ", " + strCaptcha + "</p></div>");
        //}
      
        //context.Response.Write("Hello World");
    }



    //private int RegisterUser()
    //{
    //    objuser.Salutation = strSalutation;
    //    objuser.FirstName = strFirstName;
    //    objuser.LastName = strLastName;
    //    objuser.Email = strEmailID;
    //    objuser.Phone = strContactNo;
    //    objuser.ReferalId = strReferalId;
    //    // objuser.City = strCity;
    //    objuser.RoleId = 3;
    //    objuser.Captcha = strCaptcha;
    //    objuser.IsFirstLogin = false;
    //    objuser.Status = 0;

    //    return objuser.AddUser();

    //}
   

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Monday, April 11, 2011

menus and sliders using jquery

http://wowslider.com/jquery-slider-noble-fade-demo.html

http://apycom.com/menus/9-deep-sky-blue.html

Extracting images from pdf file

http://kishor-naik-dotnet.blogspot.com/2011/01/cnet-extract-image-from-pdf-file.html



C#.net - Extract image from PDF file.

In this article i will show you how to extract image from PDF file.

Step 1
First you need to download "ITextSharp.dll" from the following link.
http://sourceforge.net/projects/itextsharp/

Step 2
Create a Console application and give the solution name as ConExtractImagefromPDF.

Step 3
Add two assembly reference to the project from solution explorer.

1.ITextSharp.dll
2.System.Drawing.dll
Step 4
Write a static method for extracting image from pdf file,it is look like this

/// <summary>
        ///  Extract Image from PDF file and Store in Image Object
        /// </summary>
        /// <param name="PDFSourcePath">Specify PDF Source Path</param>
        /// <returns>List</returns>
        private static List<System.Drawing.Image> ExtractImages(String PDFSourcePath)
        {
            List<System.Drawing.Image> ImgList = new List<System.Drawing.Image>();

            iTextSharp.text.pdf.RandomAccessFileOrArray RAFObj = null;
            iTextSharp.text.pdf.PdfReader PDFReaderObj = null;
            iTextSharp.text.pdf.PdfObject PDFObj = null;
            iTextSharp.text.pdf.PdfStream PDFStremObj = null;

            try
            {
                RAFObj = new iTextSharp.text.pdf.RandomAccessFileOrArray(PDFSourcePath);
                PDFReaderObj = new iTextSharp.text.pdf.PdfReader(RAFObj, null);

                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
                        {
                            byte[] bytes = iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw((iTextSharp.text.pdf.PRStream)PDFStremObj);

                            if ((bytes != null))
                            {
                                try
                                {
                                    System.IO.MemoryStream MS = new System.IO.MemoryStream(bytes);

                                    MS.Position = 0;
                                    System.Drawing.Image ImgPDF = System.Drawing.Image.FromStream(MS);

                                    ImgList.Add(ImgPDF);

                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return ImgList;
        }


Step 5
Write a static method for store extracting image file in folder,it is look like this

/// <summary>
        ///  Write Image File
        /// </summary>
        private static void WriteImageFile()
        {
            try
            {
                System.Console.WriteLine("Wait for extracting image from PDF file....");

                // Get a List of Image
                List<System.Drawing.Image> ListImage = ExtractImages(@"C:\Users\Kishor\Desktop\TuterPDF\ASP.net\ASP.NET 3.5 Unleashed.pdf");

                for (int i = 0; i < ListImage.Count; i++)
                {
                    try
                    {
                        // Write Image File
                        ListImage[i].Save(AppDomain.CurrentDomain.BaseDirectory + "ImageStore\\Image" + i + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        System.Console.WriteLine("Image" + i + ".jpeg write sucessfully"); 
                    }
                    catch (Exception)
                    { }
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

Step 6
Call above function in main method,it is look like this

static void Main(string[] args)
        {
            try
            {
                WriteImageFile(); // write image file
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);  
            }
        }

Full Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConExtractImagefromPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                WriteImageFile(); // write image file
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);  
            }
        }

        #region Methods

        /// <summary>
        ///  Extract Image from PDF file and Store in Image Object
        /// </summary>
        /// <param name="PDFSourcePath">Specify PDF Source Path</param>
        /// <returns>List</returns>
        private static List<System.Drawing.Image> ExtractImages(String PDFSourcePath)
        {
            List<System.Drawing.Image> ImgList = new List<System.Drawing.Image>();

            iTextSharp.text.pdf.RandomAccessFileOrArray RAFObj = null;
            iTextSharp.text.pdf.PdfReader PDFReaderObj = null;
            iTextSharp.text.pdf.PdfObject PDFObj = null;
            iTextSharp.text.pdf.PdfStream PDFStremObj = null;

            try
            {
                RAFObj = new iTextSharp.text.pdf.RandomAccessFileOrArray(PDFSourcePath);
                PDFReaderObj = new iTextSharp.text.pdf.PdfReader(RAFObj, null);

                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
                        {
                            byte[] bytes = iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw((iTextSharp.text.pdf.PRStream)PDFStremObj);

                            if ((bytes != null))
                            {
                                try
                                {
                                    System.IO.MemoryStream MS = new System.IO.MemoryStream(bytes);

                                    MS.Position = 0;
                                    System.Drawing.Image ImgPDF = System.Drawing.Image.FromStream(MS);

                                    ImgList.Add(ImgPDF);

                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return ImgList;
        }


        /// <summary>
        ///  Write Image File
        /// </summary>
        private static void WriteImageFile()
        {
            try
            {
                System.Console.WriteLine("Wait for extracting image from PDF file....");

                // Get a List of Image
                List<System.Drawing.Image> ListImage = ExtractImages(@"C:\Users\Kishor\Desktop\TuterPDF\ASP.net\ASP.NET 3.5 Unleashed.pdf");

                for (int i = 0; i < ListImage.Count; i++)
                {
                    try
                    {
                        // Write Image File
                        ListImage[i].Save(AppDomain.CurrentDomain.BaseDirectory + "ImageStore\\Image" + i + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        System.Console.WriteLine("Image" + i + ".jpeg write sucessfully"); 
                    }
                    catch (Exception)
                    { }
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }
}

Saturday, April 9, 2011

JQUERY VALIDATINS AND FORM LAYOUTS

http://www.position-relative.net/creation/formValidator/


http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/



http://www.easywayserver.com/blog/must-see-the-best-jquery-examples/


http://demos.usejquery.com/ketchup-plugin/

http://www.queness.com/post/2190/40-extremely-useful-jquery-form-plugins

http://www.lullabot.com/files/bt/bt-latest/DEMO/index.html

http://tympanus.net/codrops/2010/04/30/rocking-and-rolling-rounded-menu-with-jquery/


http://tympanus.net/codrops/2010/04/29/awesome-bubble-navigation-with-jquery/

Friday, April 8, 2011

adding items to dropdown and clear items using javascript

<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object       

        var opt = document.createElement("option");

        // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);

        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;

    }<script />

clear items in dropdown

  var theDropDown = document.getElementById("testddl") 
         var numberOfOptions = theDropDown.options.length
         for (i = 0; i < numberOfOptions; i++) {
           //Note: Always remove(0) and NOT remove(i)
             theDropDown.remove(0);
            }


http://chiragrdarji.wordpress.com/2007/06/06/add-items-in-drop-down-list-or-list-box-using-javascript/

dynamically building table using javascript by stack overflow

function start() {
    // get the reference for the body
    var body = document.getElementsByTagName("body")[0];

    // creates a <table> element and a <tbody> element
    var tbl     = document.createElement("table");
    var tblBody = document.createElement("tbody");

    // creating all cells
    for (var j = 0; j < 2; j++) {
        // creates a table row
        var row = document.createElement("tr");

        for (var i = 0; i < 2; i++) {
            // Create a <td> element and a text node, make the text
            // node the contents of the <td>, and put the <td> at
            // the end of the table row
            var cell = document.createElement("td");
            var cellText = document.createTextNode("cell is row "+j+", column "+i);
            cell.appendChild(cellText);
            row.appendChild(cell);
        }

        // add the row to the end of the table body
        tblBody.appendChild(row);
    }

    // put the <tbody> in the <table>
    tbl.appendChild(tblBody);
    // appends <table> into <body>
    body.appendChild(tbl);
    // sets the border attribute of tbl to 2;
    tbl.setAttribute("border", "2");