Java 类com.lowagie.text.Image 实例源码

项目:twainBDirect    文件:ImageManager.java   
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
    try {
        //Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
        Image img = Image.getInstance(bufeBufferedImage, null);
        Document document = new Document(img);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
        //--
        document.open();
        img.setAbsolutePosition(0, 0);
        //--
        document.add(img);
        //--
        document.close();
    } catch (DocumentException | IOException e) {
        System.out.println("Intern Log : " + e.getMessage());
    }
}
项目:unitimes    文件:PdfWebTable.java   
private float addImage(PdfPCell cell, String name) {
    try {
        java.awt.Image awtImage = (java.awt.Image)iImages.get(name);
        if (awtImage==null) return 0;
        Image img = Image.getInstance(awtImage, Color.WHITE);
        Chunk ck = new Chunk(img, 0, 0);
        if (cell.getPhrase()==null) {
            cell.setPhrase(new Paragraph(ck));
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        } else {
            cell.getPhrase().add(ck);
        }
        return awtImage.getWidth(null);
    } catch (Exception e) {
        return 0;
    }
}
项目:itext2    文件:PdfPCell.java   
/**
 * Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>.
 * The default padding is 0.25 for a border width of 0.5.
 * 
 * @param image the <CODE>Image</CODE>
 * @param fit <CODE>true</CODE> to fit the image to the cell
 */
public PdfPCell(Image image, boolean fit) {
    super(0, 0, 0, 0);
    borderWidth = 0.5f;
    border = BOX;
    if (fit) {
        this.image = image;
        column.setLeading(0, 1);
        setPadding(borderWidth / 2);
    }
    else {
        column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0)));
        column.setLeading(0, 1);
        setPadding(0);
    }
}
项目:itext2    文件:PdfPCell.java   
/**
 * Constructs a deep copy of a <CODE>PdfPCell</CODE>.
 * 
 * @param cell the <CODE>PdfPCell</CODE> to duplicate
 */
public PdfPCell(PdfPCell cell) {
    super(cell.llx, cell.lly, cell.urx, cell.ury);
    cloneNonPositionParameters(cell);
    verticalAlignment = cell.verticalAlignment;
    paddingLeft = cell.paddingLeft;
    paddingRight = cell.paddingRight;
    paddingTop = cell.paddingTop;
    paddingBottom = cell.paddingBottom;
    phrase = cell.phrase;
    fixedHeight = cell.fixedHeight;
    minimumHeight = cell.minimumHeight;
    noWrap = cell.noWrap;
    colspan = cell.colspan;
    rowspan = cell.rowspan;
    if (cell.table != null)
        table = new PdfPTable(cell.table);
    image = Image.getInstance(cell.image);
    cellEvent = cell.cellEvent;
    useDescender = cell.useDescender;
    column = ColumnText.duplicate(cell.column);
    useBorderPadding = cell.useBorderPadding;
    rotation = cell.rotation;
}
项目:itext2    文件:BarcodeDatamatrix.java   
/**
 * Creates a <CODE>java.awt.Image</CODE>. A successful call to the method <CODE>generate()</CODE>
 * before calling this method is required.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    if (image == null)
        return null;
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();

    int w = width + 2 * ws;
    int h = height + 2 * ws;
    int pix[] = new int[w * h];
    int stride = (w + 7) / 8;
    int ptr = 0;
    for (int k = 0; k < h; ++k) {
        int p = k * stride;
        for (int j = 0; j < w; ++j) {
            int b = image[p + (j / 8)] & 0xff;
            b <<= j % 8;
            pix[ptr++] = (b & 0x80) == 0 ? g : f;
        }
    }
    java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w));
    return img;
}
项目:sistra    文件:PDFDocument.java   
private Image generateBarCode()
{
    try {
    Barcode128 code128 = new Barcode128();

    code128.setSize(12f);
    code128.setBaseline(12f);
    code128.setCode(barcode);

    Image img = code128.createImageWithBarcode(writer.getDirectContent(), null, null);
    img.scalePercent(50, 50);


    //img.setAbsolutePosition(PageSize.A4.width() - img.width() - 10,10);           
        //document.add(img);

    return img;
    }catch (Exception ex){
        ex.printStackTrace();
        return null;
    }
}
项目:jasperreports    文件:JRPdfExporter.java   
/**
 *
 */
protected Image getPxImage()
{
    if (pxImage == null)
    {
        try
        {
            pxImage =
                Image.getInstance(
                    JRLoader.loadBytesFromResource(JRImageLoader.PIXEL_IMAGE_RESOURCE)
                    );
        }
        catch(Exception e)
        {
            throw new JRRuntimeException(e);
        }
    }

    return pxImage;
}
项目:sistra    文件:PDFDocumentTemplate.java   
/**
 *  M�todo que permite introducir un c�digo de barras code128 que represente el texto
 * que se pasa como par�metro. Se debe indicar la p�gina del PDF donde se debe introducir
 * el c�digo (normlamente la p�gina 1) y la posici�n absoluta X e Y dentro de la p�gina.
 */
public void establecerBarCode (int Pagina, String texto, int XPos, int YPos) throws Exception
{       
        Barcode128 code128 = new Barcode128();

        code128.setSize(12f);
        code128.setBaseline(12f);
        code128.setCode(texto);

        Image img = code128.createImageWithBarcode(pdfs.getOverContent(Pagina), null, null);

        img.setAbsolutePosition(XPos, YPos);
        //Se hace un poco mas peque�o en la escala X para que no ocupe tanto
        img.scalePercent(75, 100);

        pdfs.getOverContent(Pagina).addImage(img);

}
项目:itext2    文件:RtfImage.java   
/**
 * Constructs a RtfImage for an Image.
 * 
 * @param doc The RtfDocument this RtfImage belongs to
 * @param image The Image that this RtfImage wraps
 * @throws DocumentException If an error occurred accessing the image content
 */
public RtfImage(RtfDocument doc, Image image) throws DocumentException
{
    super(doc);
    imageType = image.getOriginalType();
    if (!(imageType == Image.ORIGINAL_JPEG || imageType == Image.ORIGINAL_BMP
            || imageType == Image.ORIGINAL_PNG || imageType == Image.ORIGINAL_WMF || imageType == Image.ORIGINAL_GIF)) {
        throw new DocumentException("Only BMP, PNG, WMF, GIF and JPEG images are supported by the RTF Writer");
    }
    alignment = image.getAlignment();
    width = image.getWidth();
    height = image.getHeight();
    plainWidth = image.getPlainWidth();
    plainHeight = image.getPlainHeight();
    this.imageData = getImageData(image);
}
项目:camel-spring    文件:BarcodeQRCode.java   
/** Creates a <CODE>java.awt.Image</CODE>.
 *
 * @param foreground the color of the bars
 * @param background the color of the background
 *
 * @return the image
 */
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background) {

    int f = foreground.getRGB();
    int g = background.getRGB();

    int width = bm.getWidth();
    int height = bm.getHeight();
    int pix[] = new int[width * height];
    byte[][] mt = bm.getArray();

    for (int y = 0; y < height; ++y) {
        byte[] line = mt[y];
        for (int x = 0; x < width; ++x) {
            pix[y * width + x] = line[x] == 0 ? f : g;
        }
    }

    java.awt.Canvas canvas = new java.awt.Canvas();
    java.awt.Image img = canvas.createImage(new java.awt.image.MemoryImageSource(width, height, pix, 0, width));

    return img;
}
项目:itext2    文件:AbsolutePositionsTest.java   
/**
 * Adds an Image at an absolute position.
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file

    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("absolutepositions.pdf"));

    // step 3: we open the document
    document.open();

    // step 4: we add content
    Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
    png.setAbsolutePosition(171, 250);
    document.add(png);
    png.setAbsolutePosition(342, 500);
    document.add(png);

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:ImageCellTest.java   
/**
 * A cell with an image.
 * 
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();

    // step 2:
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ImageCell.pdf"));

    // step 3: we open the document
    document.open();
    Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
    float[] widths = { 1f, 4f };
    PdfPTable table = new PdfPTable(widths);
    table.addCell("This is my dog");
    table.addCell(image);
    table.addCell("This two");
    table.addCell(new PdfPCell(image, true));
    table.addCell("This three");
    table.addCell(new PdfPCell(image, false));
    document.add(table);

    // step 5: we close the document
    document.close();
}
项目:unitimes    文件:PdfTimetableGridTable.java   
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
    if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
    BaseFont bf = font.getBaseFont();
    float width = bf.getWidthPoint(text, font.getSize());
    PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
    template.beginText();
    template.setColorFill(Color.BLACK);
    template.setFontAndSize(bf, font.getSize());
    template.setTextMatrix(0, 2);
    template.showText(text);
    template.endText();
    template.setWidth(width);
    template.setHeight(font.getSize() + 2);
    //make an Image object from the template
    Image img = Image.getInstance(template);
    img.setRotationDegrees(270);
    //embed the image in a Chunk
    Chunk ck = new Chunk(img, 0, 0);

    if (cell.getPhrase()==null) {
        cell.setPhrase(new Paragraph(ck));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    } else {
        cell.getPhrase().add(ck);
    }
}
项目:jaffa-framework    文件:FormPrintEngineIText.java   
/** Print a java image */
private void printImage(java.awt.Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws BadElementException, IOException, DocumentException {
    if(image!=null) {
        // Convert to an iText Image
        Image img = Image.getInstance(image, null);
        printImage(img,cb,x1,y1,x2,y2,alignment,fitMethod,rotate);
    }
}
项目:jaffa-framework    文件:FormPrintEngineIText.java   
/** Print an iText image */
private void printImage(Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws DocumentException {
    if(image!=null) {
        float boxWidth = Math.abs(x2-x1)+1;
        float boxHeight = Math.abs(y2-y1)+1;
        log.debug("Print Image (Size w="+image.getPlainWidth()+",h="+image.getPlainHeight()+") wthin BOX (w="+boxWidth+",h="+boxHeight+") FitMethod = "+fitMethod);

        // Clip the image based on the bounding box
        if(fitMethod==FIT_METHOD_CLIP) {
            if( (boxWidth < image.getPlainWidth()) || (boxHeight < image.getPlainHeight()) ) {
                // @TODO - Clip image
                log.warn("IMAGE CLIPPING REQUIRED, but not implemented - default to 'SCALE'...");
                fitMethod=FIT_METHOD_SCALE;
            }
        }
        // Stretch/shrink both the X/Y to fit the bounding box
        if(fitMethod==FIT_METHOD_FILL) {
            log.debug("Scale image to fill box");
            image.scaleToFit(x2-x1, y2-y1);
        }
        // Stretch/shrink preserving the aspect ratio to fit the bounding box
        if(fitMethod==FIT_METHOD_SCALE) {
            float multipler = Math.min(boxWidth / image.getPlainWidth(), boxHeight /image.getPlainHeight());
            log.debug("Need to scale image by " + (Math.floor(multipler*10000)/100) + "%");
            image.scalePercent(multipler*100);
        }
        log.debug("Print image at (" + x1 + "," + y1 +")");
        image.setAbsolutePosition(x1,y1);
        image.setRotationDegrees(rotate);
        cb.addImage(image);
        //Phrase text = new Phrase(new Chunk(image, 0, 0));
        //ColumnText ct = new ColumnText(cb);
        //ct.setSimpleColumn(text, x1, y1, x2, y2, 10, alignment);
        //ct.go();
    }
}
项目:itext2    文件:SAXiTextHandler.java   
protected void addImage(Image img) throws EmptyStackException {
    // if there is an element on the stack...
    Object current = stack.pop();
    // ...and it's a Chapter or a Section, the Image can be
    // added directly
    if (current instanceof Chapter
            || current instanceof Section
            || current instanceof Cell) {
        ((TextElementArray) current).add(img);
        stack.push(current);
        return;
    }
    // ...if not, we need to to a lot of stuff
    else {
        Stack newStack = new Stack();
        while (!(current instanceof Chapter
                || current instanceof Section || current instanceof Cell)) {
            newStack.push(current);
            if (current instanceof Anchor) {
                img.setAnnotation(new Annotation(0, 0, 0,
                        0, ((Anchor) current).getReference()));
            }
            current = stack.pop();
        }
        ((TextElementArray) current).add(img);
        stack.push(current);
        while (!newStack.empty()) {
            stack.push(newStack.pop());
        }
        return;
    }
}
项目:itext2    文件:BarcodePDF417.java   
/** Creates a <CODE>java.awt.Image</CODE>.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();

    paintCode();
    int h = (int)yHeight;
    int pix[] = new int[bitColumns * codeRows * h];
    int stride = (bitColumns + 7) / 8;
    int ptr = 0;
    for (int k = 0; k < codeRows; ++k) {
        int p = k * stride;
        for (int j = 0; j < bitColumns; ++j) {
            int b = outBits[p + (j / 8)] & 0xff;
            b <<= j % 8;
            pix[ptr++] = (b & 0x80) == 0 ? g : f;
        }
        for (int j = 1; j < h; ++j) {
            System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns);
        }
        ptr += bitColumns * (h - 1);
    }

    java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns));
    return img;
}
项目:itext2    文件:PdfStamperImp.java   
void setThumbnail(Image image, int page) throws PdfException, DocumentException {
    PdfIndirectReference thumb = getImageReference(addDirectImageSimple(image));
    reader.resetReleasePage();
    PdfDictionary dic = reader.getPageN(page);
    dic.put(PdfName.THUMB, thumb);
    reader.resetReleasePage();
}
项目:OA    文件:PdfImage.java   
/**
 * ����ͼƬ���뷽ʽ
 * @param value ͼƬ���뷽ʽ
 */
public void setAlignment(String value){
    if(value.equalsIgnoreCase("center")){
        this.image.setAlignment(Image.ALIGN_CENTER);
    }
    if(value.equalsIgnoreCase("left")){
        this.image.setAlignment(Image.ALIGN_LEFT);
    }
    if(value.equalsIgnoreCase("right")){
        this.image.setAlignment(Image.ALIGN_RIGHT);
    }
}
项目:jasperreports    文件:JRPdfExporter.java   
private InternalImageProcessorResult processImageFillFrame(String rendererId, DataRenderable renderer) throws JRException
{
    Image image = null;

    if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId))
    {
        image = loadedImagesMap.get(rendererId);
    }
    else
    {
        try
        {
            image = Image.getInstance(renderer.getData(jasperReportsContext));
            imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
        }
        catch (Exception e)
        {
            throw new JRException(e);
        }

        if (printImage.isUsingCache())
        {
            loadedImagesMap.put(rendererId, image);
        }
    }

    image.scaleAbsolute(availableImageWidth, availableImageHeight);

    return 
        new InternalImageProcessorResult(
            new Chunk(image, 0, 0), 
            image.getScaledWidth(), 
            image.getScaledHeight(),
            0,
            0
            );
}
项目:itext2    文件:BarcodeDatamatrix.java   
/** Gets an <CODE>Image</CODE> with the barcode. A successful call to the method <CODE>generate()</CODE>
 * before calling this method is required.
 * @return the barcode <CODE>Image</CODE>
 * @throws BadElementException on error
 */    
public Image createImage() throws BadElementException {
    if (image == null)
        return null;
    byte g4[] = CCITTG4Encoder.compress(image, width + 2 * ws, height + 2 * ws);
    return Image.getInstance(width + 2 * ws, height + 2 * ws, false, Image.CCITTG4, 0, g4, null);
}
项目:sistra    文件:ITextParser.java   
public void addBarcode(String barcode, int x, int y) throws ParserException {
    try {
        Barcode128 code128 = new Barcode128();
        code128.setCode(barcode);

        PdfContentByte cb = stamp.getOverContent(1);
        Image image128 = Image.getInstance(code128.createImageWithBarcode(cb, null, null));

        cb.addImage(image128, image128.width(), 0, 0, image128.height(), x, y);
        cb.moveTo(0, 0);
    } catch (DocumentException e) {
        throw new ParserException("Could not add barcode", e);
    }
}
项目:itext2    文件:PdfCell.java   
/**
 * Returns the height needed to draw the remaining text.
 *
 * @return a height
 */

public float remainingHeight() {
    float result = 0f;
    for (Iterator i = images.iterator(); i.hasNext();) {
        Image image = (Image) i.next();
        result += image.getScaledHeight();
    }
    return remainingLinesHeight() + cellspacing + 2 * cellpadding + result;
}
项目:itext2    文件:BmpImage.java   
/** Reads a BMP from an url.
 * @param url the url
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(URL url) throws IOException {
    InputStream is = null;
    try {
        is = url.openStream();
        Image img = getImage(is);
        img.setUrl(url);
        return img;
    }
    finally {
        if (is != null) {
            is.close();
        }
    }
}
项目:itext2    文件:BmpImage.java   
/** Reads a BMP from a byte array.
 * @param data the byte array
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(byte data[]) throws IOException {
    ByteArrayInputStream is = new ByteArrayInputStream(data);
    Image img = getImage(is);
    img.setOriginalData(data);
    return img;
}
项目:sistra    文件:PDFDocumentTemplate.java   
/** 
 * Establece una imagen en una posici�n indic�ndole el tama�o que ha de tener
 *     
 * @param   nPagina Indica el n�mero de p�gina donde se inertar� la imagen
 * @param   a_Imagen Indica el byte[] de la imagen a insertar
 * @param   a_posX Indica la posici�n X absoluta dentro del PDF donde se colocar� la imagen
 * @param   a_posY Indica la posici�n Y absoluta dentro del PDF donde se colocar� la imagen
 */
public void establecerImagen (int nPagina, byte[] a_Imagen, float a_posX, float a_posY, float a_width, float a_height) throws Exception
{   
    Image imagen = Image.getInstance(a_Imagen);
    imagen.scaleAbsolute(a_width, a_height);
    imagen.setAbsolutePosition(a_posX, a_posY);
    imagen.setTransparency(new int[] {255, 255,255, 255, 255, 255});
    pdfs.getOverContent(nPagina).addImage(imagen);
}
项目:OA    文件:PdfImage.java   
/**
 * ����ͼƬ����
 * @param fileName ͼƬ����
 */
public PdfImage(String fileName) {
    try{
    this.image=Image.getInstance(fileName);

    }catch(Exception e){
        System.out.println(e);
    }
}
项目:itext2    文件:BmpImage.java   
private Image readRLE8() throws IOException, BadElementException {

    // If imageSize field is not provided, calculate it.
    int imSize = (int)imageSize;
    if (imSize == 0) {
        imSize = (int)(bitmapFileSize - bitmapOffset);
    }

    // Read till we have the whole image
    byte values[] = new byte[imSize];
    int bytesRead = 0;
    while (bytesRead < imSize) {
        bytesRead += inputStream.read(values, bytesRead,
        imSize - bytesRead);
    }

    // Since data is compressed, decompress it
    byte val[] = decodeRLE(true, values);

    // Uncompressed data does not have any padding
    imSize = width * height;

    if (isBottomUp) {

        // Convert the bottom up image to a top down format by copying
        // one scanline from the bottom to the top at a time.
        // int bytesPerScanline = (int)Math.ceil((double)width/8.0);
        byte temp[] = new byte[val.length];
        int bytesPerScanline = width;
        for (int i=0; i<height; i++) {
            System.arraycopy(val,
            imSize - (i+1)*(bytesPerScanline),
            temp,
            i*bytesPerScanline, bytesPerScanline);
        }
        val = temp;
    }
    return indexedModel(val, 8, 4);
}
项目:itext2    文件:JBIG2Image.java   
/**
 * returns an Image representing the given page.
 * @param ra    the file or array containing the image
 * @param page  the page number of the image
 * @return  an Image object
 */
public static Image getJbig2Image(RandomAccessFileOrArray ra, int page) {
    if (page < 1)
           throw new IllegalArgumentException("The page number must be >= 1.");

    try {
        JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
        sr.read();
        JBIG2SegmentReader.JBIG2Page p = sr.getPage(page);
        Image img = new ImgJBIG2(p.pageBitmapWidth, p.pageBitmapHeight, p.getData(true), sr.getGlobal(true));
        return img;
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
项目:itext2    文件:PngImage.java   
/** Reads a PNG from an url.
 * @param url the url
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(URL url) throws IOException {
    InputStream is = null;
    try {
        is = url.openStream();
        Image img = getImage(is);
        img.setUrl(url);
        return img;
    }
    finally {
        if (is != null) {
            is.close();
        }
    }
}
项目:itext2    文件:PngImage.java   
/** Reads a PNG from a byte array.
 * @param data the byte array
 * @throws IOException on error
 * @return the image
 */    
public static Image getImage(byte data[]) throws IOException {
    ByteArrayInputStream is = new ByteArrayInputStream(data);
    Image img = getImage(is);
    img.setOriginalData(data);
    return img;
}
项目:itext2    文件:RtfHeaderFooter.java   
/**
 * Set the alignment of this RtfHeaderFooter. Passes the setting
 * on to the contained element.
 */
public void setAlignment(int alignment) {
    super.setAlignment(alignment);
    for(int i = 0; i < this.content.length; i++) {
        if(this.content[i] instanceof Paragraph) {
            ((Paragraph) this.content[i]).setAlignment(alignment);
        } else if(this.content[i] instanceof Table) {
            ((Table) this.content[i]).setAlignment(alignment);
        } else if(this.content[i] instanceof Image) {
            ((Image) this.content[i]).setAlignment(alignment);
        }     
    }
}
项目:itext2    文件:RtfImage.java   
/**
 * Extracts the image data from the Image.
 * 
 * @param image The image for which to extract the content
 * @return The raw image data, not formated
 * @throws DocumentException If an error occurs accessing the image content
 */
private byte[][] getImageData(Image image) throws DocumentException 
{
    final int WMF_PLACEABLE_HEADER_SIZE = 22;
    final RtfByteArrayBuffer bab = new RtfByteArrayBuffer();

    try {
        if(imageType == Image.ORIGINAL_BMP) {
            bab.append(MetaDo.wrapBMP(image));
        } else {                
            final byte[] iod = image.getOriginalData();
            if(iod == null) {

                final InputStream imageIn = image.getUrl().openStream();
                if(imageType == Image.ORIGINAL_WMF) { //remove the placeable header first
                    for(int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++) {
            if(imageIn.read() < 0) throw new EOFException("while removing wmf placeable header");
        }
                }
                bab.write(imageIn);
                imageIn.close();

            } else {

                if(imageType == Image.ORIGINAL_WMF) {
                    //remove the placeable header                       
                    bab.write(iod, WMF_PLACEABLE_HEADER_SIZE, iod.length - WMF_PLACEABLE_HEADER_SIZE);
                } else {
                    bab.append(iod);
                }

            }
        }

        return bab.toByteArrayArray();

    } catch(IOException ioe) {
        throw new DocumentException(ioe.getMessage());
    }
}
项目:itext2    文件:TransformImageTest.java   
/**
    * Add an image using different transformation matrices.
    */
@Test
public void main() throws Exception {
       Document.compress = false;
       // step 1: creation of a document-object
       Document document = new Document(PageSize.A4);

       try {
           // step 2: creation of the writer
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "transformimage.pdf"));

           // step 3: we open the document
           document.open();

           // step 4:
           PdfContentByte cb = writer.getDirectContent();
           Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
           cb.addImage(img, 271, -50, -30, 550, 100, 100);
           cb.sanityCheck();

       }
       catch(DocumentException de) {
           System.err.println(de.getMessage());
       }
       catch(IOException ioe) {
           System.err.println(ioe.getMessage());
       }

       // step 5: we close the document
       document.close();
   }
项目:itext2    文件:SoftMaskTest.java   
/**
 * Demonstrates the Transparency functionality.
 */
@Test
public  void main() throws Exception {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2: creation of a writer
    PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("softmask.pdf"));
    // step 3: we open the document
    document.open();
    // step 4: content
    PdfContentByte cb = writer.getDirectContent();
    String text = "text ";
    text += text;
    text += text;
    text += text;
    text += text;
    text += text;
    text += text;
    text += text;
    text += text;
    document.add(new Paragraph(text));
    Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
    img.setAbsolutePosition(100, 550);
    byte gradient[] = new byte[256];
    for (int k = 0; k < 256; ++k) {
        gradient[k] = (byte) k;
    }
    Image smask = Image.getInstance(256, 1, 1, 8, gradient);
    smask.makeMask();
    img.setImageMask(smask);
    cb.addImage(img);
    cb.sanityCheck();
    // step 5: we close the document
    document.close();
}
项目:camel-spring    文件:BarcodeQRCode.java   
/**
 * Gets an <CODE>Image</CODE> with the barcode.
 *
 * @return the barcode <CODE>Image</CODE>
 * @throws BadElementException on error
 */
public Image getImage() throws BadElementException {

    byte[] b = getBitMatrix();
    byte g4[] = CCITTG4Encoder.compress(b, bm.getWidth(), bm.getHeight());

    return Image.getInstance(bm.getWidth(), bm.getHeight(), false, Image.CCITTG4, Image.CCITT_BLACKIS1, g4, null);
}
项目:itext2    文件:ImageSequenceTest.java   
/**
 * Generates 2 documents: one that respects the order of Images added,
 * another that has the default behaviour: only show the images if they fit
 * on the page, if they don't fit, wait until the next page.
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("notInSequence.pdf"));
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("inSequence.pdf"));
    writer.setStrictImageSequence(true);

    // step 3: we open the document
    document.open();

    // step 4:
    document.add(new Paragraph("1st image"));
    Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
    document.add(jpg);
    document.add(new Paragraph("2nd image"));
    Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "getacro.gif");
    document.add(gif);
    document.add(new Paragraph("3rd image"));
    document.add(jpg);
    document.add(new Paragraph("4th image"));
    document.add(gif);
    document.add(new Paragraph("5th image"));
    document.add(jpg);
    document.add(new Paragraph("6th image"));
    document.add(gif);
    document.add(new Paragraph("7th image"));
    document.add(jpg);

    // step 5: we close the document
    document.close();
}
项目:camel-spring    文件:PdfController.java   
/**
 * Generate barcode in the form
 *
 * @param pdfStamper
 * @throws DocumentException
 */
private void generateBarcode(PdfStamper pdfStamper, String userId) throws DocumentException {

    // add barcode on the first page
    PdfContentByte cb = pdfStamper.getOverContent(BARCODE_PAGE);

    // barcode format 128C
    Barcode128 code128 = new Barcode128();

    // barcode format e.g. *1502A1234567890
    //  asterisk - * [constant]
    //  WebPOS Transaction - 1502 [constant]
    //  Form Version - A [constant for MyPost 1.5]
    //  10-digit APCN
    code128.setCode(ASTERISK + WEBPOS_TRANSACTIION + MYPOST_FORM_VERSION + userId);

    code128.setCodeType(Barcode128.CODE128);

    // convert barcode into image
    Image code128Image = code128.createImageWithBarcode(cb, null, null);

    // set barcode position x pixel, y pixel
    code128Image.setAbsolutePosition(BARCODE_POSITION_X, BARCODE_POSITION_Y);
    code128Image.scalePercent(BARCODE_SCALE_PERCENTAGE);

    // add barcode image into PDF template
    cb.addImage(code128Image);
}
项目:sistra    文件:PDFDocumentTemplate.java   
/** 
 * Establece una imagen de fondo para todas las paginas
 *     
 * @param   nPagina Indica el n�mero de p�gina donde se inertar� la imagen de fondo
 * @param   a_pathImagen Indica el fichero imagen a insertar (Path absoluto)
 * @param   a_posX Indica la posici�n X absoluta dentro del PDF donde se colocar� la imagen
 * @param   a_pathImagen Indica la posici�n Y absoluta dentro del PDF donde se colocar� la imagen
 */
public void establecerFondo (String a_pathImagen, float a_posX, float a_posY) throws Exception
{
    int n = pdfr.getNumberOfPages();
    Image imagen = Image.getInstance(a_pathImagen);
    imagen.setAbsolutePosition(a_posX, a_posY);
    imagen.setTransparency(new int[] {255, 255,255, 255, 255, 255});

    for (int i=1;i<=n;i++){
        pdfs.getUnderContent(i).addImage(imagen);
    }
}
项目:itext2    文件:ExamplePDF417Test.java   
/**
 * Example Barcode PDF417.
 */
@Test
public void main() throws Exception {


           BarcodePDF417 pdf417 = new BarcodePDF417();
           String text = "It was the best of times, it was the worst of times, " + 
               "it was the age of wisdom, it was the age of foolishness, " +
               "it was the epoch of belief, it was the epoch of incredulity, " +
               "it was the season of Light, it was the season of Darkness, " +
               "it was the spring of hope, it was the winter of despair, " +
               "we had everything before us, we had nothing before us, " +
               "we were all going direct to Heaven, we were all going direct " +
               "the other way - in short, the period was so far like the present " +
               "period, that some of its noisiest authorities insisted on its " +
               "being received, for good or for evil, in the superlative degree " +
               "of comparison only.";
           pdf417.setText(text);
           Document document = new Document(PageSize.A4, 50, 50, 50, 50);
           PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "pdf417.pdf"));
           document.open();
           Image img = pdf417.getImage();
           img.scalePercent(50, 50 * pdf417.getYHeight());
           document.add(img);
           document.close();

}