SetAnnotation() public méthode

Sets a generic annotation to this Chunk.
public SetAnnotation ( PdfAnnotation annotation ) : Chunk
annotation iTextSharp.text.pdf.PdfAnnotation the annotation
Résultat Chunk
Exemple #1
0
// ---------------------------------------------------------------------------    
    /**
     * Creates a PDF document.
     * @param stream Stream for the new PDF document
     */
    public void CreatePdf(Stream stream) {
      string RESOURCE = Utility.ResourcePosters;
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        Phrase phrase;
        Chunk chunk;
        PdfAnnotation annotation;
        foreach (Movie movie in PojoFactory.GetMovies()) {
          phrase = new Phrase(movie.MovieTitle);
          chunk = new Chunk("\u00a0\u00a0");
          annotation = PdfAnnotation.CreateFileAttachment(
            writer, null,
            movie.MovieTitle, null,
            Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
            string.Format("img_{0}.jpg", movie.Imdb)
          );
          annotation.Put(PdfName.NAME, new PdfString("Paperclip"));
          chunk.SetAnnotation(annotation);
          phrase.Add(chunk);
          document.Add(phrase);
          document.Add(PojoToElementFactory.GetDirectorList(movie));
          document.Add(PojoToElementFactory.GetCountryList(movie));
        }
      }
    }
 // ---------------------------------------------------------------------------          
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         Phrase phrase;
         Chunk chunk;
         foreach (Movie movie in PojoFactory.GetMovies())
         {
             phrase = new Phrase(movie.MovieTitle);
             chunk = new Chunk("\u00a0");
             chunk.SetAnnotation(PdfAnnotation.CreateText(
               writer, null, movie.MovieTitle,
               string.Format(INFO, movie.Year, movie.Duration),
               false, "Comment"
             ));
             phrase.Add(chunk);
             document.Add(phrase);
             document.Add(PojoToElementFactory.GetDirectorList(movie));
             document.Add(PojoToElementFactory.GetCountryList(movie));
         }
     }
 }
 // ---------------------------------------------------------------------------
 /**
  * Creates the PDF.
  * @return the bytes of a PDF file.
  */
 public byte[] CreatePdf()
 {
     using (MemoryStream ms = new MemoryStream())
     {
         using (Document document = new Document())
         {
             PdfWriter writer = PdfWriter.GetInstance(document, ms);
             document.Open();
             document.Add(new Paragraph(
               "This is a list of Kubrick movies available in DVD stores."
             ));
             IEnumerable<Movie> movies = PojoFactory.GetMovies(1)
               .Concat(PojoFactory.GetMovies(4))
             ;
             List list = new List();
             string RESOURCE = Utility.ResourcePosters;
             foreach (Movie movie in movies)
             {
                 PdfAnnotation annot = PdfAnnotation.CreateFileAttachment(
                   writer, null,
                   movie.GetMovieTitle(false), null,
                   Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
                   string.Format("{0}.jpg", movie.Imdb)
                 );
                 ListItem item = new ListItem(movie.GetMovieTitle(false));
                 item.Add("\u00a0\u00a0");
                 Chunk chunk = new Chunk("\u00a0\u00a0\u00a0\u00a0");
                 chunk.SetAnnotation(annot);
                 item.Add(chunk);
                 list.Add(item);
             }
             document.Add(list);
         }
         return ms.ToArray();
     }
 }
Exemple #4
0
        /// <summary>
        /// Custom cell's content template as a PdfPCell
        /// </summary>
        /// <returns>Content as a PdfPCell</returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            if (OnPrintAnnotation == null)
                throw new InvalidOperationException("Please set the OnPrintAnnotation formula.");

            var data = OnPrintAnnotation.Invoke(attributes.RowData.TableRowData);
            if (data == null) return new PdfPCell();

            var defaultFont = attributes.BasicProperties.PdfFont.Fonts[0];
            var chunk = new Chunk(".", defaultFont);
            chunk.SetAnnotation(
                    PdfAnnotation.CreateText(
                           attributes.SharedData.PdfWriter,
                           new Rectangle(100, 100),
                           data.Title,
                           data.Text,
                           false,
                           _annotationIcon[data.Icon]));

            return new PdfPCell(new Phrase(chunk));
        }