Thursday, November 25, 2010

how Generate pdf to other pdf

//This code is user to generate or create a copy of one pdf to other pdf. 




using iTextSharp.text;
using iTextSharp.text.pdf;
Private void GetPdf()
{


 int pageNumber = 1;
        strURL = txtUrl.Text.Trim(); // URL like http://..../my.pdf
        PdfReader reader = new PdfReader(strURL);
       
        Rectangle size = reader.GetPageSizeWithRotation(pageNumber);
        Document document = new Document(size);
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"D:\Development\NASearcg\LogRuntime.pdf", FileMode.Create, FileAccess.Write));


        //set document info
        document.AddTitle("Document copied using iTextSharp");
        document.AddAuthor("Joachim Tesznar");
        document.AddSubject("Dynamic Content");
        document.AddCreator("PDF Form Tool by Joachim Tesznar");


        document.Open();


        PdfContentByte cb = writer.DirectContent;
        document.NewPage();
        PdfImportedPage page = writer.GetImportedPage(reader, pageNumber);
        cb.AddTemplate(page, 0, 0);
        document.Close();



}

Thursday, November 18, 2010

Code for Geting the client Ip Address

1) First Way to get the client Ip Address in asp.net with C#
string ip;

ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (!string.IsNullOrEmpty(ip))
        {
           string[] ipRange = ip.Split(',');
           int le = ipRange.Length - 1;
            string trueIP = ipRange[le];
        }
        else
        {
            ip = Request.ServerVariables["REMOTE_ADDR"];
        }
       Response.Write(ip);
        Response.Write(Request.UserHostAddress);


2)Second Way to Get the client up address in asp.net with C#


        string strHostName = System.Net.Dns.GetHostName();
        string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
        Response.Write(clientIPAddress);