當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.isImgTemplate方法代碼示例

本文整理匯總了Java中com.lowagie.text.Image.isImgTemplate方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.isImgTemplate方法的具體用法?Java Image.isImgTemplate怎麽用?Java Image.isImgTemplate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.Image的用法示例。


在下文中一共展示了Image.isImgTemplate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addDirectImageSimple

import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:78,代碼來源:PdfWriter.java


注:本文中的com.lowagie.text.Image.isImgTemplate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。