Thursday, February 2, 2012

Another Day Another Month Another Year

Life changes too fast. It shows India is growing too fast and changing too fast. Just a year back i had a different set of friends and habits. Today i am altogether a new person. The change is too drastic. I sometimes wonder if change is really good. You loose yourself in the midst of the tremendous change. Although change is a welcome moment thats helped me be a better person, but the way i would be happy as in contended is lost somewhere. Am i part of the rat race or have I become a rat. Either ways I've lost the me in me.


Money seems to be everything in todays world and most times it buys me artificial happiness. Have I lost those days when all i worried was about having fun. Today I have to define happiness the way Life defines it to be.

Theres no conclusion to what I've been trying to picturize. I just am worried that I am part of the movie where the frames are played too fast to actually freeze a moment and completely enjoy it.

Friday, November 18, 2011

I blog again!

It's been over three months since I've opened my blog to review my Personal life.
A lot has changed and I realise its for the good.
A change in Career has made me explain and explore my life.

Today, I took time out to blog myself out.
Lifes pretty much ended the same way it was before I tried to Change my life.
I end up being bored the same way I was three months back.

I've gained a lot with the change but lost my good old life.

Today is the day I break my shakkles and regain the good old life again ...!


One liner Stress buster for the day ends with the note
"Driving your point inn and trying to be good to everyone is touch task and ask. You ultimately end up being the culprit or rather looser."

Sunday, June 26, 2011

Find IP Address of a machine using Java (java.net)

Code to Find the IP Address of a local machine or any website on the network

import java.io.IOException;

import java.net.*;
public class Network {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        // Get Hostname of the local machine
        sop("Local Host Name"+InetAddress.getLocalHost());
        //Get IP of google.co.in
        //Get IP of google.com
        sop("IP of website google.co.in : "+InetAddress.getByName("google.co.in"));
        sop("IP of website google.com  : "+InetAddress.getByName("google.com"));
        sop("IP address of my website "+InetAddress.getByName("javaapionline.com"));
       
   
       // Google has multiple IPs. To List all the IP's use getAllByName
        InetAddress SW[] = InetAddress.getAllByName("www.google.com");
        for (int i=0; i
        System.out.println(SW[i]);
       
       
        // Google - Sites - Using Instance of Address
        // Access hostname or host address
        InetAddress Address = InetAddress.getByName("google.com");
        sop("Google Host Name : "+Address.getHostName());
        sop("Google Host Address : "+Address.getHostAddress());
             
    }

    public static void sop(String b)
    {
        System.out.println(b);
       
    }
    public static void sop(boolean b)
    {
        System.out.println(b);
    }
}


--------------------------------------------------------------------------------

Sample Output ( Could Vary on your machine )
Local Host Name : xxx-xxx/124.123.161.188
IP of website google.co.in : google.co.in/74.125.236.49
IP of website google.com  : google.com/74.125.236.51
IP address of my website javaapionline.com/38.101.213.236
www.google.com/74.125.236.48
www.google.com/74.125.236.49
www.google.com/74.125.236.50
www.google.com/74.125.236.52
www.google.com/74.125.236.51
Google Host Name : google.com
Google Host Address74.125.236.51

Monday, June 6, 2011

Create 5 Table Cell Data in Single Column in a PDF File

Jar : PDFBox from Apache

http://www.javaapionline.com/2011/06/create-pdf-document-using-java-pdfbox.html


An Extension to the earlier program.
Create 5 Rows of Data Cells

I decided to add in 5 Cells in a Single Column

Here's how the code will look.

/*
 * Author : Ajith Moni
 * Date : June 6th 2011
 */
import java.io.IOException;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;


public class PDFTableSingleColumn {

    public static void main(String[] args)
            throws IOException, COSVisitorException {
       
        // Create the PDF Document
        PDDocument document =new PDDocument();
        // Create a Page of the PDF Document
        PDPage page1=new PDPage();
        // Add the created page to the PDF Document
        document.addPage( page1 );
       
        // Set Font Type
        PDFont font = PDType1Font.HELVETICA_BOLD;
       
        // Create a Stream for the Document and page
        PDPageContentStream contentStream = new PDPageContentStream(document, page1);
       
        // Begin Text
        contentStream.beginText();
        // The X and Y co-ordinates start from the end of the page
        // Use the following methods to get the results -
        // might vary on your machine.
        // 612.0
        // 792.0
        System.out.println(page1.getArtBox().getUpperRightX());
        System.out.println(page1.getArtBox().getUpperRightY());
       
        // Margin of the Document - X Value
        int margin=50;
       
        // Max val - 792 - Set Margin from top - Y Value
        int y1=750;
        int y2=750;
       
        // Dimensions of the cell to draw
        // length  - length of the line
        // breadth - height of the cell
        int length=100; 
        int breadth=30;
       
       
        // draw 5 cells having single column
            for(int rows=0;rows<5;rows++)
            {
                // draw the horizontal lines
                contentStream.drawLine(margin, y1, margin+length, y2);
                // breadth
                contentStream.drawLine(margin, y1, margin, y1-breadth);
                contentStream.drawLine(margin+length, y1, margin+length, y2-breadth);
                y2-=breadth;
                y1=y2;
            }
            // Draw the closing of the Cell
            contentStream.drawLine(margin, y1, margin+length, y2);
           
       
                // Close the Text
                contentStream.endText();

                // Closing the Connection is Important
                // especially when using multiple pages
                contentStream.close();
       
        document.save("D:\\Trash\\PDFTableSingleColumn.pdf");
       
        document.close();   


    }
   
}
For Creating a Compelete Table with N Rows and N columns, See the Article  :
http://www.javaapionline.com/2011/06/create-table-with-rows-and-columns-in.html
Also Read :

Create Table with Rows and Columns in a PDF File

Jar Used : PDFBox from Apache

http://www.javaapionline.com/2011/06/create-pdf-document-using-java-pdfbox.html

The following code is used to Create a Table in PDF with 5 Rows and 3 Columns.




/*
 * Author : Ajith Moni
 * Date : June 6th 2011
 */
import java.io.IOException;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;


public class PDFTableComplete {

    public static void main(String[] args)
            throws IOException, COSVisitorException {
       
        // Create the PDF Document
        PDDocument document =new PDDocument();
        // Create a Page of the PDF Document
        PDPage page1=new PDPage();
        // Add the created page to the PDF Document
        document.addPage( page1 );
       
        // Set Font Type
        PDFont font = PDType1Font.HELVETICA_BOLD;
       
        // Create a Stream for the Document and page
        PDPageContentStream contentStream = new PDPageContentStream(document, page1);
       
        // Begin Text
        contentStream.beginText();
        // The X and Y co-ordinates start from the end of the page
        // Use the following methods to get the results -
        // might vary on your machine.
        // 612.0
        // 792.0
        System.out.println(page1.getArtBox().getUpperRightX());
        System.out.println(page1.getArtBox().getUpperRightY());
       
        // Margin of the Document - X Value
        int margin=50;
       
        // Max val - 792 - Set Margin from top - Y Value
        int y1=750;
        int y2=750;
       
        // Dimensions of the cell to draw
        // length  - length of the line
        // breadth - height of the cell
        int length=100; 
        int breadth=30;
       
       
       
            // For Each Column Draw the length and Width
            for(int cols=0;cols<3;cols++)
            {
                // draw length line
                // draw breadth
               
                // draw rows
                for(int rows=0;rows<5;rows++)
                {
                    // draw the horizontal lines
                    contentStream.drawLine(margin, y1, margin+length, y2);
                    // breadth
                    contentStream.drawLine(margin, y1, margin, y1-breadth);
                    contentStream.drawLine(margin+length, y1, margin+length, y2-breadth);
                    y2-=breadth;
                    y1=y2;
                }
                contentStream.drawLine(margin, y1, margin+length, y2);
                margin=margin+length;
                y1=y2=750;
            }
       

                // Close the Text
                contentStream.endText();

                // Closing the Connection is Important
                // especially when using multiple pages
                contentStream.close();
       
        document.save("D:\\Trash\\PDFTableComplete.pdf");
       
        document.close();   


    }
   
}