Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void loadLocalImages( int startPage, int endPage, String inputPrefix) throws IOException, DocumentException{
- //BufferedImage[] images = new BufferedImage[endPage + 1];
- Document document = new Document();
- PdfWriter.getInstance(document,
- new FileOutputStream("VictoriaInversed.pdf"));
- document.open();
- document.right(0);
- document.left(0);
- document.setMargins(0, 0, 0, 0);
- document.compress = true;
- URL imageURL = new URL("http://stat.ks.kidsklik.com/statics/files/2011/02/12967198191354791838.jpg");
- for(int i = startPage; i <= endPage; i++){
- imageURL = new URL(inputPrefix + i + ".png");
- //document.add(new Paragraph("\n"+"AWT Image"));
- java.awt.image.BufferedImage awtImg = ImageIO.read(imageURL);
- awtImg = invertImage(awtImg);
- Image image =
- Image.getInstance(awtImg, null);
- image.setAbsolutePosition(0f, 0f);
- image.scaleToFit(document.getPageSize());
- document.add(image);
- document.newPage();
- }
- document.close();
- }
- public void saveImages(BufferedImage[] img, String outputPrefix) throws IOException{
- int i = 0;
- for(BufferedImage k : img){
- ImageIO.write(k, "png", new File(outputPrefix + i + ".png"));
- i++;
- }
- }
- public void savePDFDocument(BufferedImage[] images, String outputFile) throws DocumentException, MalformedURLException, IOException{
- Document document = new Document();
- PdfWriter.getInstance(document,
- new FileOutputStream(outputFile));
- document.open();
- for(BufferedImage img : images){
- document.add(new Paragraph("\n"+"AWT Image"));
- java.awt.Image awtImg = img;
- Image image =
- Image.getInstance(awtImg, null);
- document.add(image);
- document.newPage();
- }
- document.close();
- }