Package com.netcode.pdf;
Import java. Io .*;
Import java. AWT. image. renderedimage;
Import java. AWT. image. bufferedimage;
Import java. AWT. image. Raster;
Import java. util. hashtable;
Import com. lowagie. Text. Document;
Import com. lowagie. Text. image;
Import com.lowagie.text.html. Contents contentbyte;
Import com.lowagie.text=. writable writer;
Import com. Sun. Media. Jai. codec .*;
Import com. Sun. Media. Jai. codecimpl .*;
Import com. Sun. Media. Jai. codec. seekablestream;
Import com. Sun. Media. Jai. codec. fileseekablestream;
Import com. Sun. Media. Jai. codec. imagedecoder;
Import com. Sun. Media. Jai. codec. imagecodec;
Public class extends topdf {
Document document;
Pdfcontentbyte CB;
Public writable topdf (string filename, string [] strimages) throws exception {
Document = new document ();
Fileoutputstream rech = new fileoutputstream (filename );
Response writer = Response writer. getinstance (document, rech );
Document. open ();
CB = writer. getdirectcontent ();
For (INT I = 0; I <strimages. length; ++ I ){
Addimage (strimages [I]);
}
Document. Close ();
}
Public void addimage (string strimagename) throws exception {
System. Out. println (strimagename );
File file = new file (strimagename );
Seekablestream stream = new fileseekablestream (strimagename );
Catalog directory dir = new catalog directory (stream, 0 );
String [] names = imagecodec. getdecodernames (Stream );
Imagedecoder dec = imagecodec. createimagedecoder (Names [0], stream,
Null );
Int Total = dec. getnumpages ();
For (int K = 0; k <total; ++ K ){
Renderedimage rI = dec. decodeasrenderedimage (k );
Raster Ra = Ri. getdata ();
Bufferedimage Bi = new bufferedimage (Ri. getcolormodel (), raster
. Createwritableraster (Ri. getsamplemodel (), RA
. Getdatabuffer (), null), false, new hashtable ());
Image IMG = image. getinstance (Bi, null, true );
Long h = 0;
Long W = 0;
Long ifdoffset = dir. getifdoffset ();
While (ifdoffset! = 0l ){
Dir = new catalog directory (stream, ifdoffset, 0 );
Ifdoffset = dir. getnextifdoffset ();
H = dir. getfieldaslong (incluimagedecoder. pai_image_length );
W = dir. getfieldaslong (incluimagedecoder. pai_image_width );
}
Float percent = 100;
Int Pos = 0;
If (W> 895)
Percent = (595 + 18) * 100/W );
If (h> 842)
Pos = (INT) (842-H x percent/100 );
Else
Position = (INT) (842-h );
System. Out. println (percent );
System. Out. println (POS );
IMG. scalepercent (percent );
IMG. setabsoluteposition (0, POS );
System. Out. println ("Image:" + k );
CB. addimage (IMG );
Document. Newpage ();
}
Stream. Close ();
File. Delete ();
}
Public static void main (string [] ARGs ){
Try {
String [] temp = {"1. Tiff", "2. Tiff", "3. Tiff "};
Export topdf build = new export topdf ("temptid", temp );
} Catch (exception e ){
E. printstacktrace ();
}
}
}