Java/PDF RTF/Image Manipulation

Материал из Java эксперт
Версия от 18:01, 31 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Getting RawData From Image File

import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
public class RawDataFromImageFilePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFilePDF.pdf"));
      document.open();
      
      RandomAccessFile rf = new RandomAccessFile("logo.png", "r");
      int size = (int) rf.length();
      byte imext[] = new byte[size];
      rf.readFully(imext);
      rf.close();
      
      Image img1 = Image.getInstance(imext);
      img1.setAbsolutePosition(50, 500);
      document.add(img1);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}





Getting RawData From Image File and Manipulation

import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
public class RawDataFromImageFileAndManipulationPDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFileAndManipulationPDF.pdf"));
      document.open();
      
      RandomAccessFile rf = new RandomAccessFile("logo.png", "r");
      int size = (int) rf.length();
      byte imext[] = new byte[size];
      rf.readFully(imext);
      rf.close();
      
      for(int i=0;i<imext.length;i++){
        imext[i]= (byte)(imext[i]+3);
      }
      Image img1 = Image.getInstance(100, 100, 3, 8, imext);
      img1.setAbsolutePosition(200, 200);
      document.add(img1);
      
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}