Java Code Examples for com.lowagie.text.Image#ORIGINAL_WMF

The following examples show how to use com.lowagie.text.Image#ORIGINAL_WMF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RtfImage.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: RtfImage.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 3
Source File: RtfImage.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the RtfImage content
 */ 
public void writeContent(final OutputStream result) throws IOException
{
	
    if(this.topLevelElement) {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        switch(alignment) {
            case Element.ALIGN_LEFT:
                result.write(RtfParagraphStyle.ALIGN_LEFT);
                break;
            case Element.ALIGN_RIGHT:
                result.write(RtfParagraphStyle.ALIGN_RIGHT);
                break;
            case Element.ALIGN_CENTER:
                result.write(RtfParagraphStyle.ALIGN_CENTER);
                break;
            case Element.ALIGN_JUSTIFIED:
                result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
                break;
        }
    }
    result.write(OPEN_GROUP);
    result.write(PICTURE_GROUP);
    result.write(OPEN_GROUP);
    result.write(PICTURE);
    switch(imageType) {
    	case Image.ORIGINAL_JPEG:
    	    result.write(PICTURE_JPEG);
    		break;
    	case Image.ORIGINAL_PNG:
        case Image.ORIGINAL_GIF:
    	    result.write(PICTURE_PNG);
    		break;
    	case Image.ORIGINAL_WMF:
    	case Image.ORIGINAL_BMP:
    	    result.write(PICTURE_WMF);
    		break;
    }
    result.write(PICTURE_WIDTH);
    result.write(intToByteArray((int) width));
    result.write(PICTURE_HEIGHT);
    result.write(intToByteArray((int) height));
    if(this.document.getDocumentSettings().isWriteImageScalingInformation()) {
        result.write(PICTURE_SCALE_X);
        result.write(intToByteArray((int)(100 * plainWidth / width)));
        result.write(PICTURE_SCALE_Y);
        result.write(intToByteArray((int)(100 * plainHeight / height)));
    }
    if(this.document.getDocumentSettings().isImagePDFConformance()) {
        result.write(PICTURE_SCALED_WIDTH);
        result.write(intToByteArray((int) (plainWidth * RtfElement.TWIPS_FACTOR)));
        result.write(PICTURE_SCALED_HEIGHT);
        result.write(intToByteArray((int) (plainHeight * RtfElement.TWIPS_FACTOR)));
    } else {
        if(this.width != this.plainWidth || this.imageType == Image.ORIGINAL_BMP) {
            result.write(PICTURE_SCALED_WIDTH);
            result.write(intToByteArray((int) (plainWidth * PIXEL_TWIPS_FACTOR)));
        }
        if(this.height != this.plainHeight || this.imageType == Image.ORIGINAL_BMP) {
            result.write(PICTURE_SCALED_HEIGHT);
            result.write(intToByteArray((int) (plainHeight * PIXEL_TWIPS_FACTOR)));
        }
    }

    if(this.document.getDocumentSettings().isImageWrittenAsBinary()) {
    	//binary
    	result.write('\n');
    	result.write(PICTURE_BINARY_DATA);
    	result.write(intToByteArray(imageDataSize()));
        result.write(DELIMITER);
        if(result instanceof RtfByteArrayBuffer) {
        	((RtfByteArrayBuffer)result).append(imageData);
        } else {
        	for(int k = 0; k < imageData.length; k++) {
	result.write(imageData[k]);
}
        }
    } else {
    	//hex encoded
        result.write(DELIMITER);
    	result.write('\n');
    	writeImageDataHexEncoded(result);
    }
    
    result.write(CLOSE_GROUP);
    result.write(CLOSE_GROUP);
    if(this.topLevelElement) {
        result.write(RtfParagraph.PARAGRAPH);
        result.write(RtfParagraph.PARAGRAPH);
    }
    result.write('\n');    	
}