Add() публичный Метод

public Add ( IElement o ) : bool
o IElement
Результат bool
Пример #1
0
// ===========================================================================
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        var SQL = 
@"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
FROM film_country c, film_movie_country mc
WHERE c.id = mc.country_id
GROUP BY mc.country_id, country ORDER BY c DESC";  
        // Create a list for the countries
        List list = new RomanList();
        // loop over the countries
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = SQL;        
            c.Open();            
            using (var r = cmd.ExecuteReader()) {
              while (r.Read()) {
              // create a list item for the country
                ListItem item = new ListItem(
                  string.Format("{0}: {1} movies",
                    r["country"].ToString(), r["c"].ToString()
                  )
                );
                // Create a list for the movies
                List movielist = new GreekList();
                movielist.Lowercase = List.LOWERCASE;
                // Loop over the movies
                foreach (Movie movie in 
                    PojoFactory.GetMovies(r["country_id"].ToString())
                ) {
                  ListItem movieitem = new ListItem(movie.MovieTitle);
                  // Create a list for the directors
                  List directorlist = new ZapfDingbatsNumberList(0); 
                  // Loop over the directors                 
                  foreach (Director director in movie.Directors) {
                    directorlist.Add(String.Format("{0}, {1}",
                      director.Name, director.GivenName
                    ));
                  }
                  movieitem.Add(directorlist);
                  movielist.Add(movieitem);
                }
                item.Add(movielist);
                list.Add(item);
              }
              document.Add(list);
            }
          }
        }
      }
    }
Пример #2
0
        private void CreatePdf(string path)
        {
            Document doc = null;

            try
            {
                // Creating pdf
                doc = new Document(PageSize.LETTER);
                var writer = PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));
                doc.Open();

                // Support other languages
                var ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),
                    "ARIALUNI.TTF");
                var bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                // Headers
                var header = new Paragraph(documentHeaderTB.Text.Trim(), new Font(bf, 22))
                {
                    Alignment = Element.ALIGN_CENTER
                };
                doc.Add(header);

                doc.Add(Chunk.NEWLINE); // New Line
                doc.Add(Chunk.NEWLINE); // New Line

                var questionIndex = 0; // AA της ερώτησης
                foreach (DataGridViewRow row in testDGV.Rows)
                {
                    // QuestionID
                    var qid = Convert.ToInt32(row.Cells["QuestionID"].Value);

                    // QuestionText
                    var questionText = new Paragraph(
                        ++questionIndex + ") " + row.Cells["QuestionText"].Value.ToString(), new Font(bf));

                    Image img = null;
                    if (includeImages.Checked)
                    {
                        // Image
                        var data = (Byte[])(row.Cells["Image"].Value);
                        img = Image.GetInstance(data);
                        img.Alignment = Image.MIDDLE_ALIGN;
                        img.ScaleToFit(140f, 120f);
                    }

                    // Answers
                    var adapter = new multiplechoicedbDataSetTableAdapters.answersTableAdapter();
                    DataTable dt = adapter.GetDataBy(qid);

                    var answerList = new GreekList(true, 30) {IndentationLeft = 30f};

                    foreach (DataRow dtrow in dt.Rows)
                    {
                        answerList.Add(dtrow["AnswerText"].ToString());
                    }

                    doc.Add(questionText);
                    doc.Add(Chunk.NEWLINE); // New Line
                    if (includeImages.Checked)
                    {
                        doc.Add(img);
                        doc.Add(Chunk.NEWLINE); // New Line
                    }
                    doc.Add(answerList);
                    doc.Add(Chunk.NEWLINE); // New Line
                    doc.Add(Chunk.NEWLINE); // New Line
                }

                MessageBox.Show("PDF file saved!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (doc != null)
                    doc.Close();
            }
        }