SetGenericTag() public method

Sets the generic tag Chunk.
The text for this tag can be retrieved with PdfPageEvent.
public SetGenericTag ( string text ) : Chunk
text string the text for the tag
return Chunk
Example #1
0
        /// <summary>
        /// Returns a Phrase that has been constructed taking in account
        /// the value of some attributes.
        /// </summary>
        /// <param name="attributes">some attributes</param>
        public Phrase(Properties attributes) : this("", FontFactory.GetFont(attributes))
        {
            this.Clear();
            string value;

            if ((value = attributes.Remove(ElementTags.LEADING)) != null)
            {
                Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            else if ((value = attributes.Remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null)
            {
                Leading = MarkupParser.ParseLength(value);
            }
            if ((value = attributes.Remove(ElementTags.ITEXT)) != null)
            {
                Chunk chunk = new Chunk(value);
                if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null)
                {
                    chunk.SetGenericTag(value);
                }
                Add(chunk);
            }
            if (attributes.Count > 0)
            {
                MarkupAttributes = attributes;
            }
        }
Example #2
0
        public void TestImageChunkOnGenericTag()
        {
            String     fileName = "testImageChunkOnGenericTag.pdf";
            FileStream fos      = new FileStream(TARGET + fileName, FileMode.Create);
            Document   doc      = new Document(PageSize.LETTER);
            PdfWriter  writer   = PdfWriter.GetInstance(doc, fos);

            writer.PageEvent = new EventHandler();
            doc.Open();

            Image img = Image.GetInstance(writer.DirectContent.CreateTemplate(100f, 25f));

            Console.WriteLine(img.Height.ToString("F1", CultureInfo.InvariantCulture));
            Chunk c = new Chunk(img, 0, 0);

            c.SetGenericTag("foobar");

            doc.Add(c);
            doc.Close();

            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.CompareByContent(TARGET + fileName, RESOURCES + "cmp_" + fileName, TARGET, "diff_");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }
Example #3
0
        /// <summary>
        /// Returns a Paragraph that has been constructed taking in account
        /// the value of some attributes.
        /// </summary>
        /// <param name="attributes">Some attributes</param>
        public Paragraph(Properties attributes) : this("", FontFactory.GetFont(attributes))
        {
            string value;

            if ((value = attributes.Remove(ElementTags.ITEXT)) != null)
            {
                Chunk chunk = new Chunk(value);
                if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null)
                {
                    chunk.SetGenericTag(value);
                }
                Add(chunk);
            }
            if ((value = attributes.Remove(ElementTags.ALIGN)) != null)
            {
                SetAlignment(value);
            }
            if ((value = attributes.Remove(ElementTags.LEADING)) != null)
            {
                this.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            else if ((value = attributes.Remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null)
            {
                this.Leading = MarkupParser.ParseLength(value);
            }
            else
            {
                this.Leading = 16;
            }
            if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null)
            {
                this.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null)
            {
                IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            if ((value = attributes.Remove(ElementTags.KEEPTOGETHER)) != null)
            {
                keeptogether = bool.Parse(value);
            }
            if (attributes.Count > 0)
            {
                MarkupAttributes = attributes;
            }
        }
Example #4
0
// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        writer.PageEvent = new AnnotationHelper();
        // step 3
        document.Open();
        // step 4
        Paragraph p = new Paragraph();
        Chunk chunk;
        Chunk tab = new Chunk(new VerticalPositionMark());
        for (int i = 0; i < ICONS.Length; i++) {
          chunk = new Chunk(ICONS[i]);
          chunk.SetGenericTag(ICONS[i]);
          p.Add(chunk);
          p.Add(tab);
        }        
        document.Add(p); 
      }
    }
Example #5
0
 public static Phrase GetPhrase(Properties attributes)
 {
     Phrase phrase = new Phrase();
     phrase.Font = FontFactory.GetFont(attributes);
     String value;
     value = attributes[ElementTags.LEADING];
     if (value != null) {
         phrase.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     }
     value = attributes[Markup.CSS_KEY_LINEHEIGHT];
     if (value != null) {
         phrase.Leading = Markup.ParseLength(value, Markup.DEFAULT_FONT_SIZE);
     }
     value = attributes[ElementTags.ITEXT];
     if (value != null) {
         Chunk chunk = new Chunk(value);
         if ((value = attributes[ElementTags.GENERICTAG]) != null) {
             chunk.SetGenericTag(value);
         }
         phrase.Add(chunk);
     }
     return phrase;
 }
Example #6
0
        public static Chunk GetChunk(Properties attributes)
        {
            Chunk chunk = new Chunk();

            chunk.Font = FontFactory.GetFont(attributes);
            String value;

            value = attributes[ElementTags.ITEXT];
            if (value != null) {
                chunk.Append(value);
            }
            value = attributes[ElementTags.LOCALGOTO];
            if (value != null) {
                chunk.SetLocalGoto(value);
            }
            value = attributes[ElementTags.REMOTEGOTO];
            if (value != null) {
                String page = attributes[ElementTags.PAGE];
                if (page != null) {
                    chunk.SetRemoteGoto(value, int.Parse(page));
                }
                else {
                    String destination = attributes[ElementTags.DESTINATION];
                    if (destination != null) {
                        chunk.SetRemoteGoto(value, destination);
                    }
                }
            }
            value = attributes[ElementTags.LOCALDESTINATION];
            if (value != null) {
                chunk.SetLocalDestination(value);
            }
            value = attributes[ElementTags.SUBSUPSCRIPT];
            if (value != null) {
                chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
            }
            value = attributes[Markup.CSS_KEY_VERTICALALIGN];
            if (value != null && value.EndsWith("%")) {
                float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f;
                chunk.SetTextRise(p * chunk.Font.Size);
            }
            value = attributes[ElementTags.GENERICTAG];
            if (value != null) {
                chunk.SetGenericTag(value);
            }
            value = attributes[ElementTags.BACKGROUNDCOLOR];
            if (value != null) {
                chunk.SetBackground(Markup.DecodeColor(value));
            }
            return chunk;
        }
Example #7
0
 /// <summary>
 /// Returns a Paragraph that has been constructed taking in account
 /// the value of some attributes.
 /// </summary>
 /// <param name="attributes">Some attributes</param>
 public Paragraph(Properties attributes)
     : this("", FontFactory.GetFont(attributes))
 {
     string value;
     if ((value = attributes.Remove(ElementTags.ITEXT)) != null) {
         Chunk chunk = new Chunk(value);
         if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null) {
             chunk.SetGenericTag(value);
         }
         Add(chunk);
     }
     if ((value = attributes.Remove(ElementTags.ALIGN)) != null) {
         SetAlignment(value);
     }
     if ((value = attributes.Remove(ElementTags.LEADING)) != null) {
         this.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     }
     else if ((value = attributes.Remove(Markup.CSS_KEY_LINEHEIGHT)) != null) {
         this.Leading = Markup.ParseLength(value);
     }
     else {
         this.Leading = 16;
     }
     if ((value = attributes.Remove(ElementTags.INDENTATIONLEFT)) != null) {
         this.IndentationLeft = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     }
     if ((value = attributes.Remove(ElementTags.INDENTATIONRIGHT)) != null) {
         IndentationRight = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     }
     if ((value = attributes.Remove(ElementTags.KEEPTOGETHER)) != null) {
         keeptogether = bool.Parse(value);
     }
 }
Example #8
0
 /**
 * Create an index entry.
 *
 * @param text  The text for the Chunk.
 * @param in1   The first level.
 * @param in2   The second level.
 * @param in3   The third level.
 * @return Returns the Chunk.
 */
 public Chunk Create(String text, String in1, String in2,
         String in3)
 {
     Chunk chunk = new Chunk(text);
     String tag = "idx_" + (indexcounter++);
     chunk.SetGenericTag(tag);
     chunk.SetLocalDestination(tag);
     Entry entry = new Entry(in1, in2, in3, tag, this);
     indexentry.Add(entry);
     return chunk;
 }
Example #9
0
 /**
 * Create an index entry.
 *
 * @param text  The text.
 * @param in1   The first level.
 * @param in2   The second level.
 * @param in3   The third level.
 */
 public void Create(Chunk text, String in1, String in2,
         String in3)
 {
     String tag = "idx_" + (indexcounter++);
     text.SetGenericTag(tag);
     text.SetLocalDestination(tag);
     Entry entry = new Entry(in1, in2, in3, tag, this);
     indexentry.Add(entry);
 }
Example #10
0
/*
 * end inner class
*/
// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
      // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        GenericTags gevent = new GenericTags();
        writer.PageEvent = gevent;
        writer.PageEvent = new ParagraphPositions();       
        // step 3
        document.Open();
        // step 4
        Font bold = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
        Font italic = new Font(Font.FontFamily.HELVETICA, 11, Font.ITALIC);
        Font white = new Font(
          Font.FontFamily.HELVETICA, 12, 
          Font.BOLD | Font.ITALIC, 
          BaseColor.WHITE
        );
        Paragraph p;
        Chunk c;        
        foreach (Movie movie in PojoFactory.GetMovies(true)) {
            p = new Paragraph(22);
            c = new Chunk(String.Format("{0} ", movie.Year), bold);
            c.SetGenericTag("strip");
            p.Add(c);
            c = new Chunk(movie.MovieTitle);
            c.SetGenericTag(movie.Year.ToString());
            p.Add(c);
            c = new Chunk(
              String.Format(" ({0} minutes)  ", movie.Duration), 
              italic
            );
            p.Add(c);
            c = new Chunk("IMDB", white);
            c.SetAnchor("http://www.imdb.com/title/tt" + movie.Imdb);
            c.SetGenericTag("ellipse");
            p.Add(c);
            document.Add(p);
        }
        document.NewPage();
        writer.PageEvent = null;
        foreach (string entry in gevent.years.Keys) {
          p = new Paragraph(String.Format(
            "{0}: {1} movie(s)", entry, gevent.years[entry]
          ));
          document.Add(p);
        }
      }
    }
Example #11
0
 /// <summary>
 /// Returns an Anchor that has been constructed taking in account
 /// the value of some <var>attributes</var>.
 /// </summary>
 /// <param name="attributes">Some attributes</param>
 public Anchor(Properties attributes)
     : this("", FontFactory.GetFont(attributes))
 {
     string value;
     if ((value = attributes.Remove(ElementTags.ITEXT)) != null)
     {
         Chunk chunk = new Chunk(value);
         if ((value = attributes.Remove(ElementTags.GENERICTAG)) != null)
         {
             chunk.SetGenericTag(value);
         }
         Add(chunk);
     }
     if ((value = attributes.Remove(ElementTags.LEADING)) != null)
     {
         Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
     }
     else if ((value = attributes.Remove(Markup.CSS_KEY_LINEHEIGHT)) != null)
     {
         this.Leading = Markup.ParseLength(value);
     }
     if ((value = attributes.Remove(ElementTags.NAME)) != null)
     {
         this.Name = value;
     }
     if ((value = attributes.Remove(ElementTags.REFERENCE)) != null)
     {
         this.Reference = value;
     }
 }
Example #12
0
        public void TestImageChunkOnGenericTag() {
            String fileName = "testImageChunkOnGenericTag.pdf";
            FileStream fos = new FileStream(TARGET + fileName, FileMode.Create);
            Document doc = new Document(PageSize.LETTER);
            PdfWriter writer = PdfWriter.GetInstance(doc, fos);
            writer.PageEvent = new EventHandler();
            doc.Open();

            Image img = Image.GetInstance(writer.DirectContent.CreateTemplate(100f, 25f));
            Console.WriteLine(img.Height.ToString("F1", CultureInfo.InvariantCulture));
            Chunk c = new Chunk(img, 0, 0);
            c.SetGenericTag("foobar");

            doc.Add(c);
            doc.Close();

            CompareTool compareTool = new CompareTool();
            String error = compareTool.CompareByContent(TARGET + fileName, RESOURCES + "cmp_" + fileName, TARGET, "diff_");
            if (error != null) {
                Assert.Fail(error);
            }
        }