IsImgTemplate() public method

Returns true if the image is an ImgTemplate-object.
public IsImgTemplate ( ) : bool
return bool
Example #1
0
 /**
 * Adds an image to the document but not to the page resources. It is used with
 * templates and <CODE>Document.Add(Image)</CODE>.
 * @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)
 {
     PdfName name;
     // if the images is already added, just retrieve the name
     if (images.ContainsKey(image.MySerialId)) {
         name = images[image.MySerialId];
     }
     // if it's a new image, add it to the document
     else {
         if (image.IsImgTemplate()) {
             name = new PdfName("img" + images.Count);
             if (image is ImgWMF){
                 ImgWMF wmf = (ImgWMF)image;
                 wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
             }
         }
         else {
             PdfIndirectReference dref = image.DirectReference;
             if (dref != null) {
                 PdfName rname = new PdfName("img" + images.Count);
                 images[image.MySerialId] = rname;
                 imageDictionary.Put(rname, dref);
                 return rname;
             }
             Image maskImage = image.ImageMask;
             PdfIndirectReference maskRef = null;
             if (maskImage != null) {
                 PdfName mname = images[maskImage.MySerialId];
                 maskRef = GetImageReference(mname);
             }
             PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
             if (image is ImgJBIG2) {
                 byte[] globals = ((ImgJBIG2) image).GlobalBytes;
                 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.TagICC, image.CompressionLevel);
                 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[0]))
                         colorspace[1] = iccArray;
                     else
                         i.Put(PdfName.COLORSPACE, iccArray);
                 }
                 else
                     i.Put(PdfName.COLORSPACE, iccArray);
             }
             Add(i, fixedRef);
             name = i.Name;
         }
         images[image.MySerialId] = name;
     }
     return name;
 }
        /**
        * Adds an <CODE>Image</CODE> to the page. The positioning of the <CODE>Image</CODE>
        * is done with the transformation matrix. To position an <CODE>image</CODE> at (x,y)
        * use AddImage(image, image_width, 0, 0, image_height, x, y). The image can be placed inline.
        * @param image the <CODE>Image</CODE> object
        * @param a an element of the transformation matrix
        * @param b an element of the transformation matrix
        * @param c an element of the transformation matrix
        * @param d an element of the transformation matrix
        * @param e an element of the transformation matrix
        * @param f an element of the transformation matrix
        * @param inlineImage <CODE>true</CODE> to place this image inline, <CODE>false</CODE> otherwise
        * @throws DocumentException on error
        */
        public virtual void AddImage(Image image, float a, float b, float c, float d, float e, float f, bool inlineImage)
        {
            if (image.Layer != null)
                BeginLayer(image.Layer);
            if (image.IsImgTemplate()) {
                writer.AddDirectImageSimple(image);
                PdfTemplate template = image.TemplateData;
                float w = template.Width;
                float h = template.Height;
                AddTemplate(template, a / w, b / w, c / h, d / h, e, f);
            }
            else {
                if (inText && autoControlTextBlocks) {
                    EndText();
                }
                if (writer.IsTagged() && allowTaggedImages)
                    BeginMarkedContentSequence(new PdfStructureElement(GetParentStructureElement(), PdfName.FIGURE));
                content.Append("q ");
                content.Append(a).Append(' ');
                content.Append(b).Append(' ');
                content.Append(c).Append(' ');
                content.Append(d).Append(' ');
                content.Append(e).Append(' ');
                content.Append(f).Append(" cm");
                if (inlineImage) {
                    content.Append("\nBI\n");
                    PdfImage pimage = new PdfImage(image, "", null);
                    if (image is ImgJBIG2) {
                        byte[] globals = ((ImgJBIG2)image).GlobalBytes;
                        if (globals != null) {
                            PdfDictionary decodeparms = new PdfDictionary();
                            decodeparms.Put(PdfName.JBIG2GLOBALS, writer.GetReferenceJBIG2Globals(globals));
                            pimage.Put(PdfName.DECODEPARMS, decodeparms);
                        }
                    }
                    foreach (PdfName key in pimage.Keys) {
                        if (!abrev.ContainsKey(key))
                            continue;
                        PdfObject value = pimage.Get(key);
                        String s = abrev[key];
                        content.Append(s);
                        bool check = true;
                        if (key.Equals(PdfName.COLORSPACE) && value.IsArray()) {
                            PdfArray ar = (PdfArray)value;
                            if (ar.Size == 4
                                && PdfName.INDEXED.Equals(ar.GetAsName(0))
                                && ar[1].IsName()
                                && ar[2].IsNumber()
                                && ar[3].IsString()
                            ) {
                                check = false;
                            }

                        }
                        if (check && key.Equals(PdfName.COLORSPACE) && !value.IsName()) {
                            PdfName cs = writer.GetColorspaceName();
                            PageResources prs = PageResources;
                            prs.AddColor(cs, writer.AddToBody(value).IndirectReference);
                            value = cs;
                        }
                        value.ToPdf(null, content);
                        content.Append('\n');
                    }
                    content.Append("ID\n");
                    pimage.WriteContent(content);
                    content.Append("\nEI\nQ").Append_i(separator);
                }
                else {
                    PdfName name;
                    PageResources prs = PageResources;
                    Image maskImage = image.ImageMask;
                    if (maskImage != null) {
                        name = writer.AddDirectImageSimple(maskImage);
                        prs.AddXObject(name, writer.GetImageReference(name));
                    }
                    name = writer.AddDirectImageSimple(image);
                    name = prs.AddXObject(name, writer.GetImageReference(name));
                    content.Append(' ').Append(name.GetBytes()).Append(" Do Q").Append_i(separator);
                }
                if (writer.IsTagged() && allowTaggedImages)
                    EndMarkedContentSequence();
            }
            if (image.HasBorders()) {
                SaveState();
                float w = image.Width;
                float h = image.Height;
                ConcatCTM(a / w, b / w, c / h, d / h, e, f);
                Rectangle(image);
                RestoreState();
            }
            if (image.Layer != null)
                EndLayer();
            Annotation annot = image.Annotation;
            if (annot == null)
                return;
            float[] r = new float[unitRect.Length];
            for (int k = 0; k < unitRect.Length; k += 2) {
                r[k] = a * unitRect[k] + c * unitRect[k + 1] + e;
                r[k + 1] = b * unitRect[k] + d * unitRect[k + 1] + f;
            }
            float llx = r[0];
            float lly = r[1];
            float urx = llx;
            float ury = lly;
            for (int k = 2; k < r.Length; k += 2) {
                llx = Math.Min(llx, r[k]);
                lly = Math.Min(lly, r[k + 1]);
                urx = Math.Max(urx, r[k]);
                ury = Math.Max(ury, r[k + 1]);
            }
            annot = new Annotation(annot);
            annot.SetDimensions(llx, lly, urx, ury);
            PdfAnnotation an = PdfAnnotationsImp.ConvertAnnotation(writer, annot, new Rectangle(llx, lly, urx, ury));
            if (an == null)
                return;
            AddAnnotation(an);
        }
Example #3
0
 /**
 * Adds an image to the document but not to the page resources. It is used with
 * templates and <CODE>Document.Add(Image)</CODE>.
 * @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)
 {
     PdfName name;
     // if the images is already added, just retrieve the name
     if (images.ContainsKey(image.MySerialId)) {
         name = (PdfName) images[image.MySerialId];
     }
     // if it's a new image, add it to the document
     else {
         if (image.IsImgTemplate()) {
             name = new PdfName("img" + images.Count);
             if (image.TemplateData == null) {
                 if (image is ImgWMF){
                     ImgWMF wmf = (ImgWMF)image;
                     wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
                 }
             }
         }
         else {
             PdfIndirectReference dref = image.DirectReference;
             if (dref != null) {
                 PdfName rname = new PdfName("img" + images.Count);
                 images[image.MySerialId] = rname;
                 imageDictionary.Put(rname, dref);
                 return rname;
             }
             Image maskImage = image.ImageMask;
             PdfIndirectReference maskRef = null;
             if (maskImage != null) {
                 PdfName mname = (PdfName)images[maskImage.MySerialId];
                 maskRef = GetImageReference(mname);
             }
             PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
             if (image.HasICCProfile()) {
                 PdfICCBased icc = new PdfICCBased(image.TagICC);
                 PdfIndirectReference iccRef = Add(icc);
                 PdfArray iccArray = new PdfArray();
                 iccArray.Add(PdfName.ICCBASED);
                 iccArray.Add(iccRef);
                 PdfObject colorspace = i.Get(PdfName.COLORSPACE);
                 if (colorspace != null && colorspace.IsArray()) {
                     ArrayList ar = ((PdfArray)colorspace).ArrayList;
                     if (ar.Count > 1 && PdfName.INDEXED.Equals(ar[0]))
                         ar[1] = iccArray;
                     else
                         i.Put(PdfName.COLORSPACE, iccArray);
                 }
                 else
                     i.Put(PdfName.COLORSPACE, iccArray);
             }
             Add(i, fixedRef);
             name = i.Name;
         }
         images[image.MySerialId] = name;
     }
     return name;
 }