Friday, October 11, 2013

Convert PDF to image And Extract them into individual Pages from Existing PDF to a new File (C# .NET sample)

Convert PDF to image And Extract them into individual Pages from Existing PDF to a new File (C# .NET sample) 

I was recently working on received PDF files from a website which it then needed to store in a Folder and split these files into images and individual pages. I wanted the ability to display previews of these documents within the application. While there are a number of solutions for creating PDF files from C#, options for viewing a PDF within your application is much more limited, unless you purchase expensive commercial products, or use COM interop to embed Acrobat Reader into your application.
This article describes an alternate solution, in which the pages in a PDF are converted into images using GhostScript, from where you can then display them in your application.


I Used itextsharp.dll and ghostscript(gsdll32.dll)

Step 1:- Add reference of itextsharp.dll from  given source code dll's folder.

Step 2:- Copy gsdll32.dll from given source code dll's folder and paste dll (gsdll32.dll) into following path.

if you are using x86 based operating system then gsdll32.dll file should be on (C:\Windows\System32)
C:\Windows\System32\gsdll32.dll
if you are using x64 based operating system then gsdll32.dll file should be on (C:\Windows\SysWOW64) 

C:\Windows\SysWOW64\ gsdll32.dll



Defining conversion settings

The Pdf2ImageSettings class allows you to customize various properties of the output image. The following properties are available:

  • AntiAliasMode - specifies the antialiasing level between Low, Medium and High. This internally will set the dTextAlphaBits and dGraphicsAlphaBits GhostScript switches to appropriate values.
  • Dpi - dots per inch. Internally sets the r switch. This property is not used if a paper size is set.
  • GridFitMode - controls the text readability mode. Internally sets the dGridFitTT switch.
  • ImageFormat - specifies the output image format. Internally sets the sDEVICE switch.
  • PaperSize - specifies a paper size from one of the standard sizes supported by GhostScript.
  • TrimMode - specifies how the image should be sized. Your milage may vary if you try and use the paper size option. Internally sets either the dFIXEDMEDIA and sPAPERSIZE or the dUseCropBox or the dUseTrimBox switches.

Converting the PDF

To convert a PDF file into a series of images, use the Pdf2Image class. The following properties and methods are offered:

  • ConvertPdfPageToImage - converts a given page in the PDF into an image which is saved to disk
  • GetImage - converts a page in the PDF into an image and returns the image
  • GetImages - converts a range of pages into the PDF into images and returns an image array
  • PageCount - returns the number of pages in the source PDF
  • PdfFilename - returns or sets the filename of the PDF document to convert
  • PdfPassword - returns or sets the password of the PDF document to convert
  • Settings - returns or sets the settings object described above

Usage when running as a service

  • Sometimes problems may occure when running pdfaPilot/pdfToolbox as a service with Microsoft Office. Automation is not supported by Microsoft officially, but the following workaround was successful in most cases:
    • Create the following folder (with appropriate permissions) on your system:
      • Windows x64: C:\Windows\SysWOW64\config\systemprofile\Desktop
      • Windows x86: C:\Windows\System32\config\systemprofile\Desktop


Download Source Code Here...

Friday, June 14, 2013

TWITTER API 1.1 FOLLOWER BOX WIDGET Example on C#, Asp Dot Net, With full source code

twitter API 1.1 Example on C#, Asp Dot Net, With full source code



We all are similar with Facebook Like Box and also how important they are to increase followers or likes. Cool Twitter Follower Box Widget Also works just like facebook like box. This will help you to increase twitter followers and get better position in twitter.  Other twitter users can also see which of their friends is already following your website so it gives a more social blend to your website and helps in bringing more traffic from twitter. Follow the steps below to add Cool Twitter Follower Box Widget For website
.




first create a application from https://dev.twitter.com/apps/new

after create application you can get oauth_token, oauth_token_secret ,oauth_consumer_key ,oauth_consumer_secret

After create oauth_token, oauth_token_secret ,oauth_consumer_key ,oauth_consumer_secret, put these value's on attached C# project and run attached code, you can POST/GET data from Rest API.
Download Source Code Here...

Friday, March 22, 2013

Tic Tac Toe Game


CSS
<style type="text/css">
        input
        {
            width: 50px;
            height: 50px;
        }
        .winner
        {
            background-color: #FF69B4;
        }
</style>
HTML
<table width="150px">
            <tr>
                <td>
                    <input type="button" id="1" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="2" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="3" onclick="return Tic(this);" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="4" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="5" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="6" onclick="return Tic(this);" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="7" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="8" onclick="return Tic(this);" />
                </td>
                <td>
                    <input type="button" id="9" onclick="return Tic(this);" />
                </td>
            </tr>
        </table>
        <br />
        <input type="button" id="btnPlay" onclick="return Play();" value="Play" 
                  style="width:100px; height: 30px; font: verdana 12pt;" />
        <asp:HiddenField ID="hfGameOver" runat="server" Value="No" />
        <asp:HiddenField ID="hfValue" runat="server" Value="X" />
Script
<script type="text/javascript" language="javascript">
   var ID = [1, 2, 3, 4, 5, 6, 7, 8, 9];
       
    // Possible Solution Array 2D
   var SolArr = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7],
                     [2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7]];
       
        // For Play Again
        function Play() {
            for (var i = 0; i < 9; i++) {
              var btn = document.getElementById(ID[i]);
              btn.value = "";
              btn.className = "";
              document.getElementById('<%= hfGameOver.ClientID  %>').value = "No";
            }
        }
        // For Tic
        function Tic(obj) {           
            var val;
            var TicValue = document.getElementById('<%=  hfValue.ClientID  %>').value;
            if (document.getElementById('<%= hfGameOver.ClientID  %>').value == "Yes") {
                alert("Game Over");
                return false;
            }
            if (obj.value != "") {
                alert("You can't change value");
                return false;
            }
            if (TicValue == "X") {
                obj.value = TicValue;
                val = "O";
            }
            else {
                obj.value = TicValue;
                val = "X";
            }
            CheckForResult();
            document.getElementById('<%=  hfValue.ClientID  %>').value = val;
        }
        // For Checking Result.
        function CheckForResult() {           
            var TicValue = document.getElementById('<%=  hfValue.ClientID  %>').value;
            for (var i = 0; i < 8; i++) {
                var Id1 = SolArr[i][0], Id2 = SolArr[i][1], Id3 = SolArr[i][2];
                var txt1 = document.getElementById(Id1);
                var txt2 = document.getElementById(Id2);
                var txt3 = document.getElementById(Id3);
                if ((txt1.value != "") && (txt1.value == txt2.value) && 
                    (txt2.value == txt3.value)) {
                    txt1.className = "winner";
                    txt2.className = "winner";
                    txt3.className = "winner";
                   
                    document.getElementById('<%= hfGameOver.ClientID  %>').value = "Yes";
                    alert(TicValue + " is Winner.");
                    return false;
                }
               
            }
        }
            
    </script>

Joins in Linq


Join Between two Tables
DataTable DT1 = FillDatset("select * from country_Master");
DataTable DT2 = FillDatset("select * from State_Master");
          var List = (from DtCountry in DT1.AsEnumerable()
                           join DtState in DT2.AsEnumerable()
                           on DtCountry.Field<int>("CountryID")
                           equals DtState.Field<int>("CountryID") into DTALL
                           from _dtAll in DTALL.DefaultIfEmpty()
                           select new
                            {
                               CountryID = DtCountry.Field<int>("CountryID"),
                               StateName = (_dtAll != null) ?
                                                   _dtAll.Field<string>("StateName") :
                                                     string.Empty
                             }
                           ).ToList();
          var List1 = (from DtCountry in DT1.AsEnumerable()
                            join DtState in DT2.AsEnumerable()
                            on DtCountry.Field<int>("CountryID")
                            equals DtState.Field<int>("CountryID") into DTALL
                            from _dtAll in DTALL.DefaultIfEmpty()
                            select _dtAll).ToList();

Read Excel file in C#


protected void BtnReadExcel_Click(object sender, EventArgs e)
        {
            try
            {
              OleDbConnection con = new OleDbConnection("
                                                Provider=Microsoft.Jet.OLEDB.4.0;
                                                Data Source="
+ Server.MapPath("TestExcel.xlsx") + ";
                                                Extended Properties='Excel 8.0;HDR=Yes;'"
 

                                               );
                OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]",
                                                                                 con);
                DataSet ds = new DataSet();
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

Call server side function using JQuery/JSON


<script src="App_Script/jquery-1.4.3.min.js" type="text/javascript">
</script>
<script type="text/javascript">
        $(document).ready(function () {
            $("#<%= btnLogin.clientID %>").click(function () {
                    $.ajax({
                        type: "POST",
                        url: "server-side.aspx/GetCategory",
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (msg) {
                            $('#msg').text(msg.d);
                        },
                        error: function (data) { alert("Error" + data.d); }
                    })
                    return false;
               
             });
        });
   
</script>
HTML
<div id="msg">
 </div>
 <asp:Button runat="server" ID="btnLogin" />

C#
[WebMethod]
public static string FillRelatedCategory1 ()
{
        return " success";
}

Modal Popup With Jquery


<script type="text/javascript">
        $(document).ready(function () {
            //select all the a tag with name equal to modal
            $('a[name=modal]').click(function (e) {
                //Cancel the link behavior
                e.preventDefault();
                //Get the A tag
                var id = $(this).attr('href');
                //Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();
                //Set heigth and width to mask to fill up the whole screen
                $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
                //transition effect                
                $('#mask').fadeIn(500);
                $('#mask').fadeTo("slow", 0.8);
                //Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();
                //Set the popup window to center
                $(id).css('top', winH / 2 - $(id).height() / 2 );
                $(id).css('left', winW / 2 - $(id).width() / 2);
                //transition effect
                $(id).fadeIn(500);
            });
            //if mask is clicked
            $('#mask').click(function () {
                $get("<%=txtUN.clientID %>").value = "";
                $get("<%=txtPass.clientID %>").value = "";
                $(this).fadeOut(500, '', 'slow');
                $('.window').fadeOut(500, '', 'slow');
            });
            // When close button clicked
            $('#Close').click(function (e) {              
                e.preventDefault();
                $get("<%=txtUN.clientID %>").value = "";
                $get("<%=txtPass.clientID %>").value = "";
                $get('MSG').innerHTML = "";
                $('#mask').fadeOut(500, '', 'slow');
                $('.window').fadeOut(500, '', 'slow');
            });
            // when browser resize
            $(window).resize(function () {
                var box = $('#boxes .window');
                //Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();
                //Set height and width to mask to fill up the whole screen
                $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
                //Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();
                //Set the popup window to center
                box.css('top', winH / 2 - box.height() / 2 );
                box.css('left', winW / 2 - box.width() / 2);
            });
        });
    </script>
CSS
<style type="text/css">
        body{font-family: Verdana;font-size: 10pt;}
        a{color: #333;text-decoration: none;}
        a:hover{color: #ccc;text-decoration: none;}
        #mask{position: absolute;left: 0;top: 0;z-index: 9000;
                     background-color: #000;display: none;}
        #boxes .window{position: fixed;left: 0;top: 0;width: 440px;
                                  height: 200px;display: none;z-index: 9999;
                                   padding: 20px;}
        #boxes #dialog{width: 375px;height: 203px;padding: 10px;
                                  background-color: #ffffff;}
        #boxes #dialog1{width: 375px;height: 203px;}
        #dialog1 .d-login{float: left;width: 180px;height: 53px;margin-left: 109px;}
        .txtBox{height: 25px;margin: 10px;width: 200px;}
        .loginbtnC{background-image: url("Images/ImgCancel.jpeg");
                         border: medium none;height: 32px;width: 80px;}
        .loginbtnL{background-image: url("Images/loginImage.jpeg");}
    </style>
HTML
<div id="boxes">
                
                <div id="dialog1" class="window" style="display: none;">
                    <fieldset style="background-color: #FFF; border-radius: 25px;
                                           -webkit-border-radius: 25px;">
                        <legend style="margin-left: 15px;"> LOGIN</legend>
                        <div style="padding-top: 10px; text-align: center;">
                            <span>UserName :</span>
                            <
asp:TextBox ID="txtUN" CssClass="txtBox" runat="server"
placeholder="Enter UserName"></asp:TextBox>
     <
br />
                            <span>Password :</span>
    <asp:TextBox ID="txtPass" CssClass="txtBox" runat="server"
                                placeholder="Enter Password"></asp:TextBox>
                        </div>
                        <div class="d-login">
                        <asp:Button runat="server" ID="btnLogin" CssClass="loginbtnC loginbtnL" />
                        <input id="Close" type="button" class="loginbtnC" />
                      </div>
                    </fieldset>
                </div>
               
               
                <div id="mask">
                </div>
            </div>