Wednesday, August 3, 2011

Convert multiple Tiff images(File path or Bytes) to one PDF file (get bytes or file)- java code

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;


import org.apache.commons.io.IOUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;
import com.itextpdf.text.pdf.codec.TiffImage;


public class TiffToPdfConverter
{
public static void main(String args[])
{
TiffToPdfConverter converter=new TiffToPdfConverter();
String[] files=new String[]{"D:\\TestTiffToPDF\\AZ-MC-DYI-2002.1034.tif","D:\\TestTiffToPDF\\testcolor-packbits.tif","D:\\TestTiffToPDF\\03.tif"};
try
{

byte[] bytes1=converter.printImagesToPDF(files);
OutputStream out1=new FileOutputStream("D:\\TestTiffToPDF\\test-fax2.pdf");
out1.write(bytes1);

FileInputStream inputStream=new FileInputStream(new File("D:\\TestTiffToPDF\\AZ-MC-DYI-2002.1034.tif"));
FileInputStream inputStream1=new FileInputStream(new File("D:\\TestTiffToPDF\\03.tif"));
FileInputStream inputStream2=new FileInputStream(new File("D:\\TestTiffToPDF\\testcolor-packbits.tif"));
byte[] bytes=IOUtils.toByteArray(inputStream);
byte[] bytes2=IOUtils.toByteArray(inputStream1);
byte[] bytesInputStream2=IOUtils.toByteArray(inputStream2);
ArrayList fileBytes=new ArrayList();
fileBytes.add(bytes);
fileBytes.add(bytes2);
fileBytes.add(bytesInputStream2);
byte[] bytes3=converter.printImagesToPDF(fileBytes);
OutputStream out2=new FileOutputStream("D:\\TestTiffToPDF\\test-fax3.pdf");
out2.write(bytes3);

} catch (Exception e)
{
e.printStackTrace();
}

}

private byte[] printImagesToPDF(String[] files){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
Document TifftoPDF = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter.getInstance(TifftoPDF,baos );
TifftoPDF.open();
for(int i=0;i {
Image tempImage=TiffImage.getTiffImage(getInputFileInBytes(files[i]), 1);
tempImage.scaleToFit(595f, 842f);
TifftoPDF.add(tempImage);
}
TifftoPDF.close();


} catch (DocumentException e) {
e.printStackTrace();
}
return baos.toByteArray();
}
private byte[] printImagesToPDF(ArrayList fileBytes) throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
RandomAccessFileOrArray myTiffFile=null;
try {
Document TifftoPDF = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter.getInstance(TifftoPDF,baos );
TifftoPDF.open();
for(int i=0;i {
ByteArrayInputStream byteInputStream=new ByteArrayInputStream((byte[])fileBytes.get(i));
myTiffFile=new RandomAccessFileOrArray(byteInputStream);
Image tempImage=TiffImage.getTiffImage(myTiffFile, 1);
tempImage.scaleToFit(595f, 842f);
TifftoPDF.add(tempImage);
}
TifftoPDF.close();


} catch (DocumentException e) {
e.printStackTrace();
}
return baos.toByteArray();
}
private RandomAccessFileOrArray getInputFileInBytes(String fileName){
RandomAccessFileOrArray myTiffFile=null;
try{
//Read the Tiff File
FileInputStream inputStream=new FileInputStream(new File(fileName));
byte[] bytes=IOUtils.toByteArray(inputStream);
ByteArrayInputStream byteInputStream=new ByteArrayInputStream(bytes);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
myTiffFile=new RandomAccessFileOrArray(byteInputStream);
}
catch (Exception i1){
i1.printStackTrace();
}
return myTiffFile;
}
}

Friday, May 20, 2011

South Africa

Now I am in South africa. Left bangalore a year ago and accompanied my husband.
I am working here in a good insurance company called "Discovery". Cool company and coolest work.
Hmmmm....anyways Africa is worth visiting, it has beautiful places which is nothing but a visual treat.
Only one problem here is the Security. You can never expect when you may face hijacks,robberies or crimes. ok ok got to go...

Thursday, January 7, 2010

September 1752




Do you know how many days were there for the month of September in the year 1752? It was only 18 days and you know, why?

The answer is:

A month with whole of eleven days missing. This was the time England shifted from Roman Julian Calendar to the Gregorian Calendar, and the king of England ordered those 11 days to be wiped off the face of the month of September of 1752. (What couldn't a King do in those days?!) And yes, the workers worked for 11 days less, but got paid for the entire 30 days. And that's how "Paid Leave" was born.Hail the King!!!

Monday, December 7, 2009

Great Young Pilot


Outstanding job by a great young pilot from Pennsylvania !
Can't add anything else to this... the picture is worth 10,000 words!If you don't think our military pilots earn their pay, you need to takea look at this picture.
This photo was taken by a soldier in Afghanistan of a helo rescue mission.The pilot is a PA National Guard guy who flies EMS choppers in civilian life.
Now how many people on the planet you reckon could set the ass end of achopper down on the roof top of a shack, on a steep mountain cliff, and holdit there while soldiers load wounded men in the rear. If this does not impressyou... nothing ever will.

Friday, December 4, 2009

Inventions of 20th Century

Some great inventions of 20th century

1900
The machine known as dirigible or zeppelin (to the name of its inventor Ferdinand Zeppelin ) was invented .

1903
The brothers Wilbur and Orville Wright invented the first aeroplane and the same year made the first flight with the new inventions.

1905
Albert Einstein developed the well-known theory of relativity - E=mc2.

1930
The nylon(comes from New York and LONdon) was invented by scientists from NY and London among which was the American chemist Wallace Hume Carothers who is thought the inventor of the nylon.

1935
In this year the British physicist Robert Watson-Watt invented the first radar.

1945
was the year in which American government scientists invented the atomic bomb - the most powerful and destructive weapon that mankind knows.

1947
The microwave oven was invented. Its inventor was the American Percy Spencer.

1949
LEGO - the game that millions of children all over the world play, was invented by the Dutch Ole Kirk Christiansen.

1950
The American Peter Carl Goldmark invented the color television.

1968
The device in the computer that we use every day along with our keyboard - the well known "mouse" was invented by Douglas Engelbart.

1971
The heart of the computer - the microprocessor was invented by Marcian Edward Hoff probably better known as Ted Hoff.

1974
The game with over 1 billion combinations - the rubik's cube was invented. Its "father" was Erno Rubik.

1976
In that year 1976, the American Steve Jobs "invented" the Apple - the first personal computer.

1979
The CD(means Compact Disk) was invented by the Dutch Joop Sinjou and the Japanese Toshi tada Doi.

1991
In the 1991 Tim Berners-Lee discovered the WWW(World Wide Web).

1995
The Digital Video Disc or just DVD was invented in 1995 and until now has been improved much... It can hold up the amount of data of more than 10 CDs.

History of Computer Mouse

One friday afternoon I was getting bugged in office and was just staring at the mouse having no better work to do,then many questions arouse in my mind about its invention and inventer.So googled and found this piece of information..

Douglas Carl Englebart was the man behind the invention of computer mouse in 1968 along with NLS (oNLine System) which introduced two dimensional text editing.

Computer mouse is now one of the simplest and most effective input devices that we have ever known.Before the computer mice hit the market, the only way to move the cursor on the computer screen was to use the keyboard arrow keys. However, the launch of Apple Macintosh with computer mouse in 1984 started a new era in the evolution of computing devices. It was Microsoft and its OS Windows 3.1 with its graphical user interface that made mouse so popular device in the following years.

Evolution
Before Steve Jobs, the co-founder of Apple computer designed the computer mouse for his new Macintosh in 1984, there were a few input devices like light pens, graphics tablets and joy sticks that were used as alternative to keyboards during the nineteen seventies. The earlier computers (before nineteen seventies) used interfaces like punch cards or teletype machines. The screen editors were introduced only after 1970’s and the arrow keys were used to move the cursor on the computer screen while editing the text.

Although the graphics tablets and joy sticks were used as pointing devices before computer mouse was introduced, they were expensive and also occupied more space on the desk.
The first computer mice were mechanical type and had a ball that rolls under the mouse body. When the mouse moves on the pad, the rollers detect the direction and the speed. The movement of rollers was sensed by light emitting diode (LED) and the IC connected to it, converted it to the code understandable by the computer. However, the performance of the mechanical mice depended on the rollers and the sensors which need to be clean and free from any debris.

Apple continued to use mouse as an input device in nineteen eighties, while PC users had to wait until Microsoft to launch its popular Windows operating system 3.1 (GUI) to get all the benefits of using a computer mouse. In the following years, the newer versions of Microsoft Windows hit the market and made the mouse as a standard pointing device for their products.

The next generation of computer mice designed by Agilent used all electronic LED and DSP ((Digital Signal Processor chip) devices could sense the data even better and were more precise and rapid and enabled much smoother movement of cursor on the computer screen. These mice also allowed the users to customize the speed of movement and other options like tracking etc.
With the introduction of optical mouse, the mouse pad became unnecessary and so was the cleaning of internal parts of computer mice.

Logitech, the pioneer in the computer mouse technology, introduced cordless mice which do not need any cable but worked on the same principles of earlier computer mouse models. In addition, they came with rechargeable batteries.

Microsoft introduced another useful feature - the rolling wheel between right and left buttons. The rolling wheel allowed the user to scroll up and down without the need to drag the cursor. Newer optical mice came with extra buttons (the side buttons) that helped the user to move the cursor backward and forward in the latest OS versions like Windows XP.

Monday, November 30, 2009

Tips for a healthy marriage.

Trust: Trust your spouse completely when you love even if you are aware that your spouse is lying or denying saying nothing.Don't ask lot of quetsions which may not necessarily be aswered or you may only get silence as response.May be there is a very strong/valid reason behind which your spouse was compelled to lie or keep silent.Give some time to come out with truth. If you dont get the answer after some time then assume that you are not eligible to know what was that afterall.

Space around: Always give some space around your spouse. Don't always try and force your likes and dislikes on them.Coz every individual thinks different from other. Giving some space to them will keep your relationship more healthy and happy.

Compliment: Compliment right at that moment if your spouse really deserves it. Don't think of the people around, its afterall your wife/husband. At the same time dont ever try to put them down in a crowd or any family get togethers. If you don't like something then let your spouse know that in person and not in public.

Mutual Compromises and Support: "Happiness comes in small packets", this is one of the known facts and is very true. Try to compromise/give away few little things in your life just to see a cute smile in your spouse's face. Sometimes that smile will make your day and even enhances LOVE between you and ofcourse increases an understanding in your marriage.
Give support whenver needed either a moral support or financial support(if possible). Doing this will increase respect towards each other.

Surprises: Surprise your spouse on occasions. A simple candle light dinner or a movie will do. But surprises are surprises small or big will certainly blooms your love life.

All the best "ALWAYS BE HAPPY"....