Java 类com.lowagie.text.pdf.codec.TiffImage 实例源码

项目:itext2    文件:OddEvenTest.java   
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
    if (args.length < 3) {
        System.err.println("OddEven needs 3 Arguments.");
        System.out
                .println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
        return;
    }
    RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
    RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
    Image img = TiffImage.getTiffImage(odd, 1);
    Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
    for (int c = 0; c < count; ++c) {

        Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
        Image imgEven = TiffImage.getTiffImage(even, count - c);
        document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
        document.newPage();
        imgOdd.setAbsolutePosition(0, 0);
        cb.addImage(imgOdd);
        document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
        document.newPage();
        imgEven.setAbsolutePosition(0, 0);
        cb.addImage(imgEven);

    }
    odd.close();
    even.close();
    document.close();

}
项目:joinpdf    文件:JoinPdf.java   
private void addTiff(final File file, final Document document, final PdfWriter writer)
        throws Exception {
    RandomAccessFileOrArray randomAccess = createRamdomAccessSource(file);

    int pages = getPageCount(file);
    for (int i = 1; i <= pages; i++) {
        Image image = TiffImage.getTiffImage(randomAccess, i);
        addImage(image, document, writer);
    }

}
项目:joinpdf    文件:JoinPdf.java   
public static int getPageCountTif(final File file) throws IOException {
    RandomAccessFileOrArray randomAccess = createRamdomAccessSource(file);
    return TiffImage.getNumberOfPages(randomAccess);
}