1 3 import java.util.*; 4 import java.io.*; 5 import org.faceless.pdf2.*; 6 7 17 public class ImageToPDF 18 { 19 public static void main(String [] args) 20 throws IOException 21 { 22 if (args.length==0) { 23 System.out.println("Usage: java ImageToPDF <file1> [<file2> ... ]\n"); 24 System.out.println(" Creates the file \"ImageToPDF.pdf\"\n\n"); 25 System.exit(0); 26 } 27 28 PDF pdf = new PDF(); 29 30 for (int i=0;i<args.length;i++) { 31 InputStream in = new FileInputStream(args[i]); 35 PDFImageSet imgs = new PDFImageSet(in); 36 in.close(); 37 for (int j=0;j<imgs.getNumImages();j++) 38 { 39 PDFImage img = imgs.getImage(j); 43 PDFPage page = pdf.newPage((int)img.getWidth(), (int)img.getHeight()); 44 page.drawImage(img,0,0,page.getWidth(),page.getHeight()); 45 } 46 } 47 48 OutputStream fo = new FileOutputStream("ImageToPDF.pdf"); 49 pdf.render(fo); 50 fo.close(); 51 } 52 } 53 | Popular Tags |