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

项目:itext2    文件:PdfWriter.java   
/**
 * Adds an image to the document but not to the page resources.
 * It is used with templates and <CODE>Document.add(Image)</CODE>.
 * Use this method only if you know what you're doing!
 * @param image the <CODE>Image</CODE> to add
 * @param fixedRef the reference to used. It may be <CODE>null</CODE>,
 * a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
 * @return the name of the image added
 * @throws PdfException on error
 * @throws DocumentException on error
 */
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws PdfException, DocumentException {
    PdfName name;
    // if the images is already added, just retrieve the name
    if (images.containsKey(image.getMySerialId())) {
        name = (PdfName) images.get(image.getMySerialId());
    }
    // if it's a new image, add it to the document
    else {
        if (image.isImgTemplate()) {
            name = new PdfName("img" + images.size());
            if(image instanceof ImgWMF){
                try {
                    ImgWMF wmf = (ImgWMF)image;
                    wmf.readWMF(PdfTemplate.createTemplate(this, 0, 0));
                }
                catch (Exception e) {
                    throw new DocumentException(e);
                }
            }
        }
        else {
            PdfIndirectReference dref = image.getDirectReference();
            if (dref != null) {
                PdfName rname = new PdfName("img" + images.size());
                images.put(image.getMySerialId(), rname);
                imageDictionary.put(rname, dref);
                return rname;
            }
            Image maskImage = image.getImageMask();
            PdfIndirectReference maskRef = null;
            if (maskImage != null) {
                PdfName mname = (PdfName)images.get(maskImage.getMySerialId());
                maskRef = getImageReference(mname);
            }
            PdfImage i = new PdfImage(image, "img" + images.size(), maskRef);
            if (image instanceof ImgJBIG2) {
                byte[] globals = ((ImgJBIG2) image).getGlobalBytes();
                if (globals != null) {
                    PdfDictionary decodeparms = new PdfDictionary();
                    decodeparms.put(PdfName.JBIG2GLOBALS, getReferenceJBIG2Globals(globals));
                    i.put(PdfName.DECODEPARMS, decodeparms);
                }
            }
            if (image.hasICCProfile()) {
                PdfICCBased icc = new PdfICCBased(image.getICCProfile(), image.getCompressionLevel());
                PdfIndirectReference iccRef = add(icc);
                PdfArray iccArray = new PdfArray();
                iccArray.add(PdfName.ICCBASED);
                iccArray.add(iccRef);
                PdfArray colorspace = i.getAsArray(PdfName.COLORSPACE);
                if (colorspace != null) {
                    if (colorspace.size() > 1 && PdfName.INDEXED.equals(colorspace.getPdfObject(0)))
                        colorspace.set(1, iccArray);
                    else
                        i.put(PdfName.COLORSPACE, iccArray);
                }
                else
                    i.put(PdfName.COLORSPACE, iccArray);
            }
            add(i, fixedRef);
            name = i.name();
        }
        images.put(image.getMySerialId(), name);
    }
    return name;
}
项目:DroidText    文件:PdfWriter.java   
/**
 * Adds an image to the document but not to the page resources.
 * It is used with templates and <CODE>Document.add(Image)</CODE>.
 * Use this method only if you know what you're doing!
 * @param image the <CODE>Image</CODE> to add
 * @param fixedRef the reference to used. It may be <CODE>null</CODE>,
 * a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
 * @return the name of the image added
 * @throws PdfException on error
 * @throws DocumentException on error
 */
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws PdfException, DocumentException {
    PdfName name;
    // if the images is already added, just retrieve the name
    if (images.containsKey(image.getMySerialId())) {
        name = (PdfName) images.get(image.getMySerialId());
    }
    // if it's a new image, add it to the document
    else {
        if (image.isImgTemplate()) {
            name = new PdfName("img" + images.size());
            if(image instanceof ImgWMF){
                try {
                    ImgWMF wmf = (ImgWMF)image;
                    wmf.readWMF(PdfTemplate.createTemplate(this, 0, 0));
                }
                catch (Exception e) {
                    throw new DocumentException(e);
                }
            }
        }
        else {
            PdfIndirectReference dref = image.getDirectReference();
            if (dref != null) {
                PdfName rname = new PdfName("img" + images.size());
                images.put(image.getMySerialId(), rname);
                imageDictionary.put(rname, dref);
                return rname;
            }
            Image maskImage = image.getImageMask();
            PdfIndirectReference maskRef = null;
            if (maskImage != null) {
                PdfName mname = (PdfName)images.get(maskImage.getMySerialId());
                maskRef = getImageReference(mname);
            }
            PdfImage i = new PdfImage(image, "img" + images.size(), maskRef);
            if (image instanceof ImgJBIG2) {
                byte[] globals = ((ImgJBIG2) image).getGlobalBytes();
                if (globals != null) {
                    PdfDictionary decodeparms = new PdfDictionary();
                    decodeparms.put(PdfName.JBIG2GLOBALS, getReferenceJBIG2Globals(globals));
                    i.put(PdfName.DECODEPARMS, decodeparms);
                }
            }
            add(i, fixedRef);
            name = i.name();
        }
        images.put(image.getMySerialId(), name);
    }
    return name;
}