Add() public method

Adds an Object to the Paragraph.
public Add ( IElement o ) : bool
o IElement the object to add
return bool
        public static IElement GetElement(this HeaderBase hb)
        {
            Paragraph p = new Paragraph();

            Font f = TextSharpFonts.SectionHeaderFont;

            if (hb is TitleHeader)
            {
                f = TextSharpFonts.TitleHeaderFont;
                p.Add(new Phrase(hb.Header, f));
                p.Alignment = Element.ALIGN_CENTER;
                p.Leading = f.Size * 2f;
                p.SpacingAfter = f.Size * 1.5f;
            }

            if (hb is SectionHeader)
            {
                p.Add(new Phrase(hb.Header, f));
                p.Leading = f.Size * 1.5f;
            }

            if (hb is ItemHeader)
            {
                p.Add(new Phrase(hb.Header, TextSharpFonts.ItemHeaderFont));
            }

            return p;
        }
        //override the OnPageEnd event handler to add our footer
        public override void OnEndPage(PdfWriter writer, Document doc)
        {
            //I use a PdfPtable with 2 columns to position my footer where I want it
            PdfPTable footerTbl = new PdfPTable(2);

            //set the width of the table to be the same as the document
            footerTbl.TotalWidth = doc.PageSize.Width;

            //Center the table on the page
            footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;

            //Create a paragraph that contains the footer text
            Paragraph para;// = new Paragraph("", Fuentes.footer);
            DateTime time = DateTime.Now;              // Use current time
            string format = "dd/MM/yyyy";    // Use this format
            para = new Paragraph(time.ToString(format), Fuentes.Footer);

            //add a carriage return
            para.Add(Environment.NewLine);
            para.Add("");

            //create a cell instance to hold the text
            PdfPCell cell = new PdfPCell(para);

            //set cell border to 0
            cell.Border = 0;

            //add some padding to bring away from the edge
            cell.PaddingLeft = 10;

            //add cell to table
            footerTbl.AddCell(cell);

            //Creo el contenido de la 2da celda
            int pageN = writer.PageNumber;
            //DateTime time = DateTime.Now;              // Use current time
            //string format = "dd/MM/yyyy";    // Use this format
            //para = new Paragraph(time.ToString(format), Fuentes.footer);

            //para.Add(Environment.NewLine);
            para = new Paragraph(pageN.ToString(), Fuentes.Footer);

            //create new instance of cell to hold the text
            cell = new PdfPCell(para);

            //align the text to the right of the cell
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            //set border to 0
            cell.Border = 0;

            // add some padding to take away from the edge of the page
            cell.PaddingRight = 10;

            //add the cell to the table
            footerTbl.AddCell(cell);

            //write the rows out to the PDF output stream.
            footerTbl.WriteSelectedRows(0, -1, 0, (doc.BottomMargin + 10), writer.DirectContent);
        }
        // ===========================================================================
        public void Write(Stream stream)
        {
            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";
            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                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())
                            {
                                Paragraph country = new Paragraph();
                                // the name of the country will be a destination
                                Anchor dest = new Anchor(
                                  r["country"].ToString(), FilmFonts.BOLD
                                );
                                dest.Name = r["country_id"].ToString();
                                country.Add(dest);
                                country.Add(string.Format(": {0} movies", r["c"].ToString()));
                                document.Add(country);
                                // loop over the movies
                                foreach (Movie movie in
                                    PojoFactory.GetMovies(r["country_id"].ToString()))
                                {
                                    // the movie title will be an external link
                                    Anchor imdb = new Anchor(movie.MovieTitle);
                                    imdb.Reference = string.Format(
                                      "http://www.imdb.com/title/tt{0}/", movie.Imdb
                                    );
                                    document.Add(imdb);
                                    document.Add(Chunk.NEWLINE);
                                }
                                document.NewPage();
                            }
                            // Create an internal link to the first page
                            Anchor toUS = new Anchor("Go back to the first page.");
                            toUS.Reference = "#US";
                            document.Add(toUS);
                        }
                    }
                }
            }
        }
 private static IElement ClientAddress(string clientAddress)
 {
     var p = new Phrase("\n\nTO:\n", ElementFactory.StandardFontBold);
     var p2 = new Phrase(clientAddress, ElementFactory.StandardFont);
     var x = new Paragraph() { Leading = 0, MultipliedLeading = 0.8f };
     x.Add(p);
     x.Add(p2);
     return x;
 }
Beispiel #5
0
// ---------------------------------------------------------------------------    
    /**
     * Creates a Paragraph containing information about the year
     * and the duration of a movie.
     * @param    movie    the movie for which you want to create a Paragraph
     */
    public Paragraph CreateYearAndDuration(Movie movie) {
      Paragraph info = new Paragraph();
      info.Font = FilmFonts.NORMAL;
      info.Add(new Chunk("Year: ", FilmFonts.BOLDITALIC));
      info.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
      info.Add(new Chunk(" Duration: ", FilmFonts.BOLDITALIC));
      info.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
      info.Add(new Chunk(" minutes", FilmFonts.NORMAL));
      return info;
    }    
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // собираем информацию обо всех блюдах
                string mail = "Перечень блюд\n";
                bludoBindingSource.MoveFirst();
                kafeDataSet.BludoRow r = (kafeDataSet.BludoRow)((DataRowView)bludoBindingSource.Current).Row;
                int i = 0;

                // формируем PDF файл с описанием блюд
                var doc = new Document();
                string docPath = Application.StartupPath + @"\Предложение.pdf";
                PdfWriter.GetInstance(doc, new FileStream(docPath, FileMode.Create));
                doc.Open();
                // заголовок
                string fg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");

                BaseFont baseFont = BaseFont.CreateFont(fg, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Phrase j = new Phrase("Перечень блюд", new iTextSharp.text.Font(baseFont, 14,
                              iTextSharp.text.Font.BOLD, new BaseColor(Color.Black)));
                Paragraph a1 = new Paragraph(j);
                a1.Add(Environment.NewLine);
                a1.Add(Environment.NewLine);
                a1.Add(Environment.NewLine);
                a1.Alignment = Element.ALIGN_CENTER;
                a1.SpacingAfter = 5;
                doc.Add(a1);
                while (i < bludoBindingSource.List.Count)
                {
                    r = (kafeDataSet.BludoRow)((DataRowView)bludoBindingSource.Current).Row;
                    mail += "Блюдо '" + r.Nazvanie + "': " + r.Opisanie + "\n\n";
                    j = new Phrase("Блюдо '" + r.Nazvanie + "'\n" + r.Opisanie + "\n\n", new iTextSharp.text.Font(baseFont, 12,
                  iTextSharp.text.Font.BOLD, new BaseColor(Color.Black)));
                    a1 = new Paragraph(j);
                    a1.Add(Environment.NewLine);
                    a1.Add(Environment.NewLine);
                    a1.Alignment = Element.ALIGN_LEFT;
                    a1.SpacingAfter = 5;
                    doc.Add(a1);

                    bludoBindingSource.MoveNext();
                    i++;
                }
                doc.Close();

                button2.Enabled = true;
                button4.Enabled = true;
                System.Windows.Forms.MessageBox.Show("Предложение было сформировано", "Информация", MessageBoxButtons.OK);
            }
            catch (Exception e1)
            {
                System.Windows.Forms.MessageBox.Show(e1.Message);
            }
        }
Beispiel #7
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            // Create a Document object
            var document = new Document(PageSize.A4, 50, 50, 25, 25);

            string file = "Choo.pdf";
            // Create a new PdfWriter object, specifying the output stream
            var output = new MemoryStream();
            //var writer = PdfWriter.GetInstance(document, output);
            var writer = PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create));

            // Open the Document for writing
            document.Open();

            var titleFont = FontFactory.GetFont("Arial", 18);
            var subTitleFont = FontFactory.GetFont("Arial", 14);
            var boldTableFont = FontFactory.GetFont("Arial", 12);
            var endingMessageFont = FontFactory.GetFont("Arial", 10);
            var bodyFont = FontFactory.GetFont("Arial", 12);

            //document.Add(new Paragraph("Northwind Traders Receipt", titleFont);
            Paragraph tit = new Paragraph();
            Chunk c1 = new Chunk("  Ingresos Diarios \n", titleFont);
            Chunk c2 = new Chunk("Ciclo Escolar 2012 - 2013 \n");
            Chunk c3 = new Chunk("Dia consultado : 25/01/2013");
            tit.Add(c1);
            tit.Add(c2);
            tit.Add(c3);
            tit.IndentationLeft = 200f;
            document.Add(tit);

            PdfContentByte cb = writer.DirectContent;
            cb.MoveTo(50, document.PageSize.Height / 2);
            cb.LineTo(document.PageSize.Width - 50, document.PageSize.Height / 2);
            cb.Stroke();

            var orderInfoTable = new PdfPTable(2);
            orderInfoTable.HorizontalAlignment = 0;
            orderInfoTable.SpacingBefore = 10;
            orderInfoTable.SpacingAfter = 10;
            orderInfoTable.DefaultCell.Border = 0;
            orderInfoTable.SetWidths(new int[] { 1, 4 });

            orderInfoTable.AddCell(new Phrase("Order:", boldTableFont));
            orderInfoTable.AddCell("textorder");
            orderInfoTable.AddCell(new Phrase("Price:", boldTableFont));
            orderInfoTable.AddCell(Convert.ToDecimal(444444).ToString("c"));

            document.Add(orderInfoTable);
            document.Close();
            System.Diagnostics.Process.Start(file);
        }
 public static PdfPCell GetCompanyNameAndSlogan(InvoiceEntity invoiceEntity, CompanyInformationEntity companyInformationEntity)
 {
     var p = new Paragraph { Alignment = Element.ALIGN_TOP };
     p.Add(ElementFactory.GetParagraph(companyInformationEntity.Name, ElementFactory.Fonts.Large));
     p.Add(ElementFactory.GetParagraph(companyInformationEntity.Slogan, ElementFactory.Fonts.Standard));
     var c = new PdfPCell(p)
         {
             VerticalAlignment = Element.ALIGN_TOP,
             FixedHeight = 50f,
             PaddingTop = 0,
             BorderColor = BaseColor.WHITE
         };
     return c;
 }
Beispiel #9
0
        private void Assemble()
        {
            //headers
            document.Add(makeHeader("DISCUSSION SUPPORT SYSTEM"));
            document.Add(makeHeader("Discussion report"));

            InsertLine();

            //subject
            document.Add(makeHeader(discussion.Subject, true));

            InsertLine();

            //background
            Paragraph p = new Paragraph();
            ///p.Add(TextRefsAggregater.PlainifyRichText(discussion.Background));
            p.Add(new Chunk("\n"));
            document.Add(p);

            InsertLine();

            //sources
            backgroundSources();
            document.NewPage();

            //agreement blocks
            List<ArgPoint> agreed = new List<ArgPoint>();
            List<ArgPoint> disagreed = new List<ArgPoint>();
            List<ArgPoint> unsolved = new List<ArgPoint>();
            addBlockOfAgreement("Agreed", agreed);
            addBlockOfAgreement("Disagreed", disagreed);
            addBlockOfAgreement("Unsolved", unsolved);
        }
 // ===========================================================================
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         document.SetPageSize(PageSize.A5);
         document.SetMargins(36, 72, 108, 180);
         document.SetMarginMirroring(true);
         // step 3
         document.Open();
         // step 4
         document.Add(new Paragraph(
           "The left margin of this odd page is 36pt (0.5 inch); " +
           "the right margin 72pt (1 inch); " +
           "the top margin 108pt (1.5 inch); " +
           "the bottom margin 180pt (2.5 inch).")
         );
         Paragraph paragraph = new Paragraph();
         paragraph.Alignment = Element.ALIGN_JUSTIFIED;
         for (int i = 0; i < 20; i++)
         {
             paragraph.Add("Hello World! Hello People! " +
             "Hello Sky! Hello Sun! Hello Moon! Hello Stars!"
             );
         }
         document.Add(paragraph);
         document.Add(new Paragraph(
           "The right margin of this even page is 36pt (0.5 inch); " +
           "the left margin 72pt (1 inch).")
         );
     }
 }
Beispiel #11
0
        public static void AddValues2Paragraph(iTextSharp.text.Paragraph para, ArrayList values, Font font)
        {
            const string METHOD_NAME = "AddValues2Paragraph";

            try {
                iTextSharp.text.Phrase phrase = null;
                foreach (string s in values)
                {
                    if (s.Length > 0)
                    {
                        if (phrase != null)
                        {
                            phrase = new Phrase(@" \ " + s, font);
                        }
                        else
                        {
                            phrase = new Phrase(s, font);
                        }
                        para.Add(phrase);
                    }
                }
            }
            catch (Exception ex) {
                ApplicationException aex = new ApplicationException(MOD_NAME + METHOD_NAME, ex);
                throw(aex);
            }
        }
Beispiel #12
0
    private void Creo_Cabecera(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
    {
        PdfPTable t = new PdfPTable(2);

        Single[] arrAnchosC = { 20F, 80F };
        t.SetWidthPercentage(arrAnchosC, iTextSharpText.PageSize.A4);
        t.WidthPercentage = 100;

        iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + "App_Themes\\imagenes\\logo_impresion.png");
        PdfPCell c = new PdfPCell(png);

        c.HorizontalAlignment = iTextSharpText.Element.ALIGN_LEFT;
        c.BorderWidth         = 0;

        iTextSharpText.Phrase texto = new iTextSharpText.Phrase();
        texto.Font = iTextSharpText.FontFactory.GetFont("Arial", 14, iTextSharpText.Element.ALIGN_CENTER);
        texto.Add(new iTextSharpText.Phrase("Reporte de Solicitudes de Prestamos a Liquidar\n\n"));

        texto.Font = iTextSharpText.FontFactory.GetFont("Arial", 8, iTextSharpText.Element.ALIGN_CENTER);
        texto.Add(new iTextSharpText.Phrase("Fecha Reporte: " + lst[0].Fecha_Informe.ToString("dd/MM/yyyy") + "   N° Reporte: " + lst[0].nroInforme));

        PdfPCell c1 = new PdfPCell(texto);

        c1.HorizontalAlignment = iTextSharpText.Element.ALIGN_CENTER;
        c1.BorderWidth         = 0;

        t.AddCell(c);
        t.AddCell(c1);

        iTextSharpText.Paragraph Cabecera = new iTextSharpText.Paragraph();
        Cabecera.Add(t);

        document.Add(Cabecera);
        document.Add(iTextSharpText.Chunk.NEWLINE);
    }
Beispiel #13
0
        //说明:一个段落有一个且仅有一个间距,如果你添加了一个不同字体的短句或块,
        //原来的间距仍然有效,你可以通过SetLeading来改变间距,
        //但是段落中所有内容将使用新的中的间距
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Document  document  = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream("段落.pdf", FileMode.Create));

            document.Open();
            Paragraph p1 = new Paragraph(new Chunk("This is the fist paragraph",
                                                   FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            //段落中插入chunk
            Chunk ck1 = new Chunk("Test chunk eea fafafe fafeefaeefefeafaefafafaeeea fafafe fafeefaeefefeafae", FontFactory.GetFont(FontFactory.COURIER,
                                                                                                                                    20, BaseColor.BLUE));

            p1.Add(ck1);
            p1.SetLeading(10, 1);

            Paragraph p2 = new Paragraph(new Phrase("This is the second paragraph",
                                                    FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            Paragraph p3 = new Paragraph("This is the third paragraph",
                                         FontFactory.GetFont(FontFactory.HELVETICA, 12));

            document.Add(p1);
            document.Add(p2);
            document.Add(p3);

            document.Close();
            this.Title = "段落";
        }
Beispiel #14
0
        private PdfPTable CreateHeadAndTable(Document doc, BaseFont baseFont)
        {
            PdfPTable table = new PdfPTable(3);

            table.AddCell(new PdfPCell(new Phrase("Деталь", new Font(baseFont, 12, Font.NORMAL)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            table.AddCell(new PdfPCell(new Phrase("Количество", new Font(baseFont, 12, Font.NORMAL)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            table.AddCell(new PdfPCell(new Phrase("Итог", new Font(baseFont, 12, Font.NORMAL)))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            Paragraph p = new Paragraph();

            table.HorizontalAlignment = Element.ALIGN_LEFT;
            table.SpacingBefore       = 5;
            table.SpacingAfter        = 25;
            p.Add(table);

            return(table);
        }
Beispiel #15
0
// ---------------------------------------------------------------------------
    /**
     * Creates a paragraph with some text about a movie with River Phoenix,
     * and a poster of the corresponding movie.
     * @param text the text about the movie
     * @param imdb the IMDB code referring to the poster
     */
    public Paragraph CreateParagraph(String text, String imdb) {
      Paragraph p = new Paragraph(text);
      Image img = Image.GetInstance(Path.Combine(RESOURCE, imdb + ".jpg"));
      img.ScaleToFit(1000, 72);
      img.RotationDegrees = -30;
      p.Add(new Chunk(img, 0, -15, true));
      return p;
    }
 private static void SetAnchor(ISPage iSPage, Chapter chapter, Dictionary<string, int> pageMap)
 {
     Anchor anchorTarget = new Anchor(iSPage.RoomId);
     anchorTarget.Name = iSPage.RoomId;
     Paragraph targetParagraph = new Paragraph();
     targetParagraph.Add(anchorTarget);
     chapter.Add(targetParagraph);
 }
 public static void AddParagraph(Document doc, int alignment, iTextSharp.text.Font font, iTextSharp.text.IElement content)
 {
     Paragraph paragraph = new Paragraph();
     paragraph.SetLeading(0f, 1.2f);
     paragraph.Alignment = alignment;
     paragraph.Font = font;
     paragraph.Add(content);
     doc.Add(paragraph);
 }
Beispiel #18
0
 /// <summary>
 /// Add a paragraph object containing the specified element to the PDF document.
 /// </summary>
 /// <param name="doc">Document to which to add the paragraph.</param>
 /// <param name="alignment">Alignment of the paragraph.</param>
 /// <param name="font">Font to assign to the paragraph.</param>
 /// <param name="content">Object that is the content of the paragraph.</param>
 private void AddParagraph(Document doc, int alignment, iTextSharp.text.Font font, iTextSharp.text.IElement content)
 {
     iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
     paragraph.SetLeading(0f, 1.2f);
     paragraph.Alignment = alignment;
     paragraph.Font      = font;
     paragraph.Add(content);
     doc.Add(paragraph);
 }
        public static IElement GetElement(this TextSection ts)
        {
            Paragraph p = new Paragraph();

            if (ts.Header != null)
            {
                string header = ts.Header.AddDelimiter(':', s => s.EndsWithAlphanum());
                Phrase h = new Phrase(new Chunk(header, TextSharpFonts.ItemBoldFont));
                p.Add(h);
                p.Add(Chunk.NEWLINE);
            }

            Phrase b = new Phrase(new Chunk(ts.Body, TextSharpFonts.ItemFont));
            p.Add(b);
            p.Add(Chunk.NEWLINE);

            return p;
        }
        void WriteHeader(iTextSharp.text.Document doc)
        {
            iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(2f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1);
            iTextSharp.text.Chunk linebreak             = new iTextSharp.text.Chunk(line);
            iTextSharp.text.Font  black = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 9f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            var logo = new iTextSharp.text.Paragraph()
            {
                Alignment = 0
            };

            logo.Add(new iTextSharp.text.Chunk("Graph", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK)));
            logo.Add(new iTextSharp.text.Chunk("SEA", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156))));
            doc.Add(logo);
            doc.Add(new iTextSharp.text.Chunk(line));
            // add front page
            doc.Add(new Paragraph(new iTextSharp.text.Chunk("GraphSEA", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 72, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156)))));
            doc.Add(new Paragraph(new iTextSharp.text.Chunk("Graph Search Algorithms Benchmark Report", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK))));
        }
 public static Paragraph ParaCommonInfoAllBold(string field, string value)
 {
     Paragraph pr = new Paragraph();
     Phrase phr = new Phrase();
     Chunk chk1 = new Chunk(field, FontConfig.BoldFont);
     Chunk chk2 = new Chunk(value, FontConfig.BoldFont);
     phr.Add(chk1);
     phr.Add(chk2);
     pr.Add(phr);
     return pr;
 }
Beispiel #22
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); 
      }
    }
Beispiel #23
0
        protected void Unnamed1_Click1(object sender, EventArgs e)
        {
            try
            {
                string name = Guid.NewGuid().ToString() + ".pdf";
                string fileName = Server.MapPath("~/Reportes/");
                Document document = new Document(PageSize.A4, 50, 50, 25, 25);
                PdfWriter.GetInstance(document, new FileStream(fileName + name, FileMode.Create));
                document.Open();
                Paragraph parrafo = new Paragraph();
                parrafo.Alignment = Element.ALIGN_CENTER;
                parrafo.Font = FontFactory.GetFont("Arial", 24);
                parrafo.Font.SetStyle(Font.BOLD);
                parrafo.Font.SetStyle(Font.UNDERLINE);
                parrafo.Add("CENTRO DE FORMACIÓN TECNOLÓGICA\n\n\nCurso: " + cmbOpciones.SelectedItem.Text + "\n\n\nLista de alumnos inscritos:\n\n\n");
                document.Add(parrafo);
                PdfPTable unaTabla = new PdfPTable(4);
                unaTabla.SetWidthPercentage(new float[] { 200, 200, 200, 200 }, PageSize.A4);
                unaTabla.AddCell(new Paragraph("Estudiante"));
                unaTabla.AddCell(new Paragraph("Fecha de inscripción"));
                unaTabla.AddCell(new Paragraph("Curso"));
                unaTabla.AddCell(new Paragraph("Profesor"));
                foreach (PdfPCell celda in unaTabla.Rows[0].GetCells())
                {
                    celda.BackgroundColor = BaseColor.LIGHT_GRAY;
                    celda.HorizontalAlignment = 1;
                    celda.Padding = 3;
                }
                foreach (System.Web.UI.WebControls.GridViewRow row in grvInscripciones.Rows)
                {
                    PdfPCell celda1 = new PdfPCell(new Paragraph(row.Cells[0].Text, FontFactory.GetFont("Arial", 10)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph(row.Cells[1].Text, FontFactory.GetFont("Arial", 10)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph(row.Cells[2].Text, FontFactory.GetFont("Arial", 10)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph(row.Cells[3].Text, FontFactory.GetFont("Arial", 10)));
                    unaTabla.AddCell(celda1);
                    unaTabla.AddCell(celda2);
                    unaTabla.AddCell(celda3);
                    unaTabla.AddCell(celda4);
                }
                document.Add(unaTabla);
                document.Close();
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + name);
                Response.TransmitFile(fileName + name);
                Response.End();

            }
            catch (Exception ex)
            {
                btnGenerar.Text = "Intentar de nuevo: " + ex.Message;
            }
        }
Beispiel #24
0
        /* (non-Javadoc)
         * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List, com.itextpdf.text.Document)
         */
        public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) {
            try {
                IList<IElement> list = new List<IElement>();
			    HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
			    LineSeparator lineSeparator = (LineSeparator) CssAppliers.GetInstance().Apply(new LineSeparator(), tag, htmlPipelineContext);
                Paragraph p = new Paragraph();
                p.Add(lineSeparator);
                list.Add(CssAppliers.GetInstance().Apply(p, tag, htmlPipelineContext));
                return list;
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Beispiel #25
0
        private static void PrintReportHeader(ref Document document, ref Dealer dealer, int invoiceId)
        {
            document.Add(GetTitleParagraph("Glynn General Corporation"));
            document.Add(GetTitleParagraph("Glynn General Purchasing Group, Inc."));

            DateTime invoiceDate = DateTime.Now;
            if (Invoice.FetchByID(invoiceId) != null)
                invoiceDate = Invoice.FetchByID(invoiceId).DateX;

            Paragraph address = new Paragraph();
            address.IndentationLeft = 60f;
            address.Add(new Phrase(String.Format("\n\n{0:d}\n\n", invoiceDate)));

            if (dealer.HasParent)
            {
                if(dealer.Parent.Name.Trim().Length > 0)
                    address.Add(new Phrase(dealer.Parent.Name + "\n"));
            }

            if(dealer.ContactName.Trim().Length > 0)
                address.Add(new Phrase(dealer.ContactName + "\n"));
            address.Add(new Phrase(dealer.Name + "\n"));
            address.Add(new Phrase(dealer.Address + "\n"));
            address.Add(new Phrase(dealer.CityStateZip + "\n\n"));

            document.Add(address);

            Paragraph invoiceNumber = new Paragraph();
            invoiceNumber.IndentationLeft = 60f;
            invoiceNumber.Add(new Phrase("Invoice #: "));
            invoiceNumber.Font = FontFactory.GetFont(FontFactory.TIMES, 12f, Font.UNDERLINE);
            invoiceNumber.Add(new Phrase(String.Format("{0:00000000}", invoiceId)));
            invoiceNumber.Font = FontFactory.GetFont(FontFactory.TIMES, 12f, Font.NORMAL);
            invoiceNumber.Add(new Phrase("\n\n"));

            document.Add(invoiceNumber);
        }
Beispiel #26
0
// ===========================================================================
    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
        Type3Font t3 = new Type3Font(writer, true);
        PdfContentByte d = t3.DefineGlyph('D', 600, 0, 0, 600, 700);
        d.SetColorStroke(new BaseColor(0xFF, 0x00, 0x00));
        d.SetColorFill(new GrayColor(0.7f));
        d.SetLineWidth(100);
        d.MoveTo(5, 5);
        d.LineTo(300, 695);
        d.LineTo(595, 5);
        d.ClosePathFillStroke();
        PdfContentByte s = t3.DefineGlyph('S', 600, 0, 0, 600, 700);
        s.SetColorStroke(new BaseColor(0x00, 0x80, 0x80));
        s.SetLineWidth(100);
        s.MoveTo(595,5);
        s.LineTo(5, 5);
        s.LineTo(300, 350);
        s.LineTo(5, 695);
        s.LineTo(595, 695);
        s.Stroke();
        Font f = new Font(t3, 12);
        Paragraph p = new Paragraph();
        p.Add("This is a String with a Type3 font that contains a fancy Delta (");
        p.Add(new Chunk("D", f));
        p.Add(") and a custom Sigma (");
        p.Add(new Chunk("S", f));
        p.Add(").");
        document.Add(p);        
      }
    }
Beispiel #27
0
    private PdfPCell CreoCelda(string Texto, int Alineacion)
    {
        iTextSharpText.Paragraph texto = new iTextSharpText.Paragraph();
        texto.Font = iTextSharpText.FontFactory.GetFont("Arial", 7, iTextSharpText.Element.ALIGN_CENTER);

        texto.Add(Texto);

        PdfPCell c = new PdfPCell(texto);

        c.HorizontalAlignment = Alineacion;

        c.Padding    = 3;
        c.PaddingTop = 0;

        return(c);
    }
Beispiel #28
0
    public void ExoticCharsCourierTest()  {
        String filename = "exoticCharsCourierTest.pdf";
        BaseFont bf = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.WINANSI, true);
        Document doc = new Document();

        PdfWriter.GetInstance(doc, new FileStream(outFolder + filename,FileMode.Create));
        doc.Open();
        doc.NewPage();
        Paragraph p = new Paragraph();
        p.Font = new Font(bf);
        p.Add("\u0188");
        doc.Add(p);
        doc.Close();

        new CompareTool().CompareByContent(outFolder + filename, sourceFolder + "cmp_" + filename, outFolder, "diff");
    }
Beispiel #29
0
    public void ExoticCharsWithDifferencesTimesRomanTest()  {
        String filename = "exoticCharsWithDifferencesTimesRomanTest.pdf";
        BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, "# simple 32 0020 0188", true);
        Document doc = new Document();

        PdfWriter.GetInstance(doc, new FileStream(outFolder + filename, FileMode.Create));
        doc.Open();
        doc.NewPage();
        Paragraph p = new Paragraph();
        p.Font = new Font(bf);
        p.Add("\u0188");
        doc.Add(p);
        doc.Close();

        new CompareTool().CompareByContent(outFolder + filename, sourceFolder + "cmp_" + filename, outFolder, "diff");
    }
Beispiel #30
0
        /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="parName"></param>
        /// <param name="imgName"></param>
        protected void AddImg(string parName, string imgName)
        {
            Paragraph titlePar = new Paragraph(parName, fontTableRemark);
            titlePar.IndentationLeft = 24;
            titlePar.SpacingBefore = 5;
            pdfDoc.Add(titlePar);

            Paragraph imgPar = new Paragraph();
            imgPar.IndentationLeft = 20;
            imgPar.IndentationRight = 20;
            Image imgCla = Image.GetInstance(imgName);
            imgCla.ScalePercent(24f);
            imgCla.ScaleAbsoluteHeight(240);
            imgPar.Add(imgCla);
            pdfDoc.Add(imgPar);
        }
        public static IT.Paragraph GetFormattedParagraph(Paragraph paragraph)
        {
            IT.Paragraph formattedPara = new IT.Paragraph();

            foreach (var chunk in paragraph.SubElements)
            {
                IT.Chunk formattedChunk = TextFormatter.GetFormattedText( (Text) chunk);
                formattedPara.Add(formattedChunk);
            }

            // TODO: Paragraph formatting
            formattedPara.MultipliedLeading = paragraph.Leading;
            formattedPara.SpacingAfter = paragraph.SpacingAfter;
            formattedPara.SpacingBefore = paragraph.SpacingBefore;

            return formattedPara;
        }
        public void Go()
        {
            var outputFile = Helpers.IO.GetClassOutputPath(this);
            var imagePath = Helpers.IO.GetInputFilePath("100x100.jpg");
            var imageSpacerPath = Helpers.IO.GetInputFilePath("20x20.png");
            var testText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";

            using (FileStream stream = new FileStream(
                outputFile,
                FileMode.Create,
                FileAccess.Write))
            {
                using (Document document = new Document())
                {
                    Image img = Image.GetInstance(imagePath);
                    PdfWriter writer = PdfWriter.GetInstance(document, stream);
                    // writer.InitialLeading = 108;
                    document.Open();

                    // document.Add(new Paragraph(img.Height.ToString()));
                    img.Alignment = Image.ALIGN_LEFT | Image.TEXTWRAP;
                    img.BorderWidth = 10;
                    img.ScaleToFit(1000, 72);
                    document.Add(img);
                    //img.BorderColor = BaseColor.RED;
                    var p = new Paragraph();
                    p.Add(testText);
                    document.Add(p);


                    PdfContentByte cb = writer.DirectContent;
                    ColumnText ct = new ColumnText(cb);
                    ct.SetSimpleColumn(new Phrase(new Chunk(testText, FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.NORMAL))),
                                       46, 190, 530, 36, 25, Element.ALIGN_LEFT | Element.ALIGN_TOP);
                    ct.Go(); 

                    // document.Add(new Paragraph(testText));
                    // document.Add(new Chunk(testText));

                }
            }
        }
Beispiel #33
0
        //简单表格使用
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Document document = new Document();

            PdfWriter.GetInstance(document, new FileStream("表格简单使用.pdf",
                                                           FileMode.OpenOrCreate));
            document.Open();

            PdfPTable table = new PdfPTable(3);

            table.AddCell("1");
            table.AddCell("2");
            table.AddCell("3");
            table.AddCell("4");

            //table的基本方法
            PdfPCell cell1 = new PdfPCell(new Phrase("Cell1"));

            cell1.Colspan = 2;
            table.AddCell(cell1);

            table.AddCell("4");
            table.AddCell("5");
            table.AddCell("6");
            table.AddCell("7");
            table.AddCell("8");
            table.AddCell("9");  //最后行,必须有三列才显式,如果注释此行,前面的7,8都不会显式

            //不起作用?
            //cell1.HorizontalAlignment = Element.ALIGN_CENTER;
            //cell1.BackgroundColor=BaseColor.GREEN;

            Paragraph p1 = new Paragraph();

            p1.Add(table);

            document.Add(p1);

            document.Close();
            Title = "简单表格使用";
        }
Beispiel #34
0
// ---------------------------------------------------------------------------    
    /**
     * Add content to a ColumnText object.
     * @param ct the ColumnText object
     * @param movie a Movie object
     * @param img the poster of the image
     */
    public void AddContent(ColumnText ct, Movie movie) {
      Paragraph p;
      p = new Paragraph(new Paragraph(movie.Title, FilmFonts.BOLD));
      p.Alignment = Element.ALIGN_CENTER;
      p.SpacingBefore = 16;
      ct.AddElement(p);
      if (!string.IsNullOrEmpty(movie.OriginalTitle)) {
        p = new Paragraph(movie.OriginalTitle, FilmFonts.ITALIC);
        p.Alignment = Element.ALIGN_RIGHT;
        ct.AddElement(p);
      }
      p = new Paragraph();
      p.Add(PojoToElementFactory.GetYearPhrase(movie));
      p.Add(" ");
      p.Add(PojoToElementFactory.GetDurationPhrase(movie));
      p.Alignment = Element.ALIGN_JUSTIFIED_ALL;
      ct.AddElement(p);
      p = new Paragraph(new Chunk(new StarSeparator()));
      p.SpacingAfter = 12;
      ct.AddElement(p);
  }    
        public void ImageTaggingExpansionTest() {
            String filename = "TextExpansionTest.pdf";
            Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72);
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(DEST_FOLDER + filename, FileMode.Create));
            writer.SetTagged();
            doc.Open();

            Chunk c1 = new Chunk("ABC");
            c1.SetTextExpansion("the alphabet");
            Paragraph p1 = new Paragraph();
            p1.Add(c1);
            doc.Add(p1);

            PdfTemplate t = writer.DirectContent.CreateTemplate(6, 6);
            t.SetLineWidth(1f);
            t.Circle(3f, 3f, 1.5f);
            t.SetGrayFill(0);
            t.FillStroke();
            Image i = Image.GetInstance(t);
            Chunk c2 = new Chunk(i, 100, -100);
            doc.Add(c2);

            Chunk c3 = new Chunk("foobar");
            c3.SetTextExpansion("bar bar bar");
            Paragraph p3 = new Paragraph();
            p3.Add(c3);
            doc.Add(p3);

            doc.Close();


            CompareTool compareTool = new CompareTool();
            String error = compareTool.CompareByContent(DEST_FOLDER + filename, SOURCE_FOLDER + "cmp_" + filename, DEST_FOLDER, "diff_");
            if (error != null) {
                Assert.Fail(error);
            }
        }
Beispiel #36
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var        doc  = new Document();
                string     path = @"C:\DKP.pdf";
                FileStream f    = new FileStream(path, FileMode.Create);
                PdfWriter.GetInstance(doc, f);
                doc.Open();

                BaseFont TimesNewBold      = BaseFont.CreateFont(@"C:\Windows\Fonts\timesbd.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFont TimesNewNormal    = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFont CourierBoldItalic = BaseFont.CreateFont(@"C:\Windows\Fonts\courbi.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                iTextSharp.text.Font TimesNewBlack18 = new iTextSharp.text.Font(TimesNewBold, 18, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
                iTextSharp.text.Font CourierRed14    = new iTextSharp.text.Font(CourierBoldItalic, 14, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.RED);
                iTextSharp.text.Font TimesNewBlack11 = new iTextSharp.text.Font(TimesNewNormal, 11, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

                iTextSharp.text.Paragraph Title = new iTextSharp.text.Paragraph();
                Title.Alignment = iTextSharp.text.Element.ALIGN_CENTER;

                Title.Add(new Phrase("Отчет за период " + dateTimePicker1.Value + " по " + dateTimePicker2.Value + "" + Environment.NewLine, TimesNewBlack18));

                iTextSharp.text.Paragraph Task = new iTextSharp.text.Paragraph("" + dateTimePicker1.Value.ToString() + "" + Environment.NewLine, TimesNewBlack11);
                Task.Alignment = Element.ALIGN_JUSTIFIED;


                doc.Add(Title);
                doc.Close();
                Process.Start(path);
                MessageBox.Show("PDF файл успешно создан!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #37
0
    public void Creo_Pie(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
    {
        iTextSharpText.Paragraph parrafo = new iTextSharpText.Paragraph();
        #region Creo pie pagina
        //**********************CODIGO ANTERIOR
        parrafo.Font = iTextSharpText.FontFactory.GetFont("Arial", 7, 0);                                                                                                                                                          //Asigan fuente
        parrafo.Add("fecha impresión: " + DateTime.Now.ToString("dd/MM/yyyy       HH:mm") + "                                                                                                      Página: " + writer.PageNumber); //Texto que se insertara
        parrafo.Alignment = iTextSharpText.Element.ALIGN_CENTER;

        /*iTextSharpText.HeaderFooter footer = new iTextSharpText.HeaderFooter(new iTextSharpText.Phrase(parrafo), true);
         *
         *
         * footer.Border = iTextSharpText.Rectangle.NO_BORDER;
         * footer.Alignment = iTextSharpText.Element.ALIGN_RIGHT;
         * //**********************CODIGO ANTERIOR
         *
         * footer.Bottom = 0;
         *
         * doc.Footer = footer;*/
        #endregion
        PdfPTable tabFot = new PdfPTable(1);
        tabFot.DefaultCell.Border = PdfPCell.NO_BORDER;
        PdfPCell cell;
        tabFot.TotalWidth = 1000F;

        cell = new PdfPCell(parrafo);
        cell.BorderWidthBottom = 0f;
        cell.BorderWidthLeft   = 0f;
        cell.BorderWidthTop    = 0f;
        cell.BorderWidthRight  = 0f;
        tabFot.AddCell(cell);
        tabFot.WriteSelectedRows(0, -1, 100, 50, writer.DirectContent);


        //document.Add(parrafo);
    }
        private void crtaj_fakturu()
        {
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate());
            try
            {
                PdfWriter.GetInstance(doc, new FileStream("racun.pdf", FileMode.Create));
                doc.Open();

                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("Mobile Town");
                title.Alignment = Element.ALIGN_CENTER;
                title.Font.Size = 32;
                doc.Add(title);

                iTextSharp.text.Paragraph podaci;
                podaci = new iTextSharp.text.Paragraph("\n");
                podaci.Add("\n");
                podaci.Add("           Datum:" + DateTime.Now.ToString("       dd-MM-yyyy HH-mm"));
                podaci.Add("\n");
                podaci.Add("           Prodavac:  " + prodavac);
                podaci.Font.Size = 14;
                doc.Add(podaci);

                iTextSharp.text.Paragraph razmak = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak);

                PdfPTable table = new PdfPTable(4);
                table.AddCell("Artikli");
                table.AddCell("Kolicina");
                table.AddCell("Cena");
                table.AddCell("PDV(20%)");

                table.AddCell(sifra + " " + grupa + " " + artikal);
                table.AddCell(kolicina.ToString());
                table.AddCell(cena.ToString());
                double pdv = double.Parse(cena.ToString()) * 0.2;
                table.AddCell(pdv.ToString());

                doc.Add(table);

                iTextSharp.text.Paragraph razmak1 = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak1);

                PdfPTable table_konacno = new PdfPTable(2);
                table_konacno.AddCell("Ukupno");
                table_konacno.AddCell("PDV(20%) Ukupno");


                table_konacno.AddCell(cena + " e");
                table_konacno.AddCell(pdv + " e");
                doc.Add(table_konacno);

                iTextSharp.text.Paragraph razmak2 = new iTextSharp.text.Paragraph("\n");
                razmak2.Add("\n");
                razmak2.Add("\n");
                razmak2.Add("\n");
                doc.Add(razmak2);

                PdfPTable table_potpis = new PdfPTable(2);
                table_potpis.AddCell("Racun izdaje");
                table_potpis.AddCell("Racun prima");

                table_potpis.AddCell(textBox2.Text);
                table_potpis.AddCell(textBox3.Text);

                doc.Add(table_potpis);

                System.Diagnostics.Process.Start("racun.pdf");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                doc.Close();
            }
        }
Beispiel #39
0
        private void print_but_Click(object sender, RoutedEventArgs e)
        {
            var msg = new CustomMaterialMessageBox
            {
                TxtMessage = { Text = "are you sure ? ", Foreground = Brushes.Black },
                TxtTitle   = { Text = "PURCHASE ORDER", Foreground = Brushes.Black },
                BtnOk      = { Content = "Yes" },
                BtnCancel  = { Content = "No" },
                // MainContentControl = { Background = Brushes.MediumVioletRed },
                TitleBackgroundPanel = { Background = Brushes.Yellow },

                BorderBrush = Brushes.Yellow
            };

            msg.Show();
            var results = msg.Result;

            if (results == MessageBoxResult.OK)
            {
                Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                dlg.FileName   = "purchase order";            // Default file name
                dlg.DefaultExt = ".pdf";                      // Default file extension
                dlg.Filter     = "PDF document (.pdf)|*.pdf"; // Filter files by extension
                // Show save file dialog box
                Nullable <bool> result = dlg.ShowDialog();

                // Process save file dialog box results
                if (result == true)
                {
                    string    filename = dlg.FileName;
                    Document  document = new Document(PageSize.A4, 10, 10, 10, 10);
                    PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
                    File.SetAttributes(filename, FileAttributes.Normal);
                    document.Open();
                    string h1 = "\n\n\n\n\n\n\n\n\n\nPURCHASE ORDER\n\n\n";
                    iTextSharp.text.Paragraph p1 = new iTextSharp.text.Paragraph();
                    p1.Alignment = Element.ALIGN_CENTER;
                    p1.Font      = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20f, BaseColor.BLACK);
                    p1.Add(h1);
                    document.Add(p1);
                    iTextSharp.text.Paragraph p3 = new iTextSharp.text.Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
                    document.Add(p3);
                    iTextSharp.text.Paragraph p4 = new iTextSharp.text.Paragraph("\n\n\n");
                    document.Add(p4);
                    PdfPTable table1 = new PdfPTable(2);
                    table1.AddCell("ITEM");
                    table1.AddCell("QUANTITY");
                    try
                    {
                        DataTable ds = new DataTable(typeof(Item).Name);

                        //Get all the properties
                        PropertyInfo[] Props = typeof(Item).GetProperties(BindingFlags.Public | BindingFlags.Instance);
                        foreach (PropertyInfo prop in Props)
                        {
                            //Defining type of data column gives proper data table
                            var type = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
                            //Setting column names as Property names
                            ds.Columns.Add(prop.Name, type);
                        }
                        foreach (Item item in inventory_table.ItemsSource)
                        {
                            var values = new object[Props.Length];
                            for (int i = 0; i < Props.Length; i++)
                            {
                                //inserting property values to datatable rows
                                values[i] = Props[i].GetValue(item, null);
                            }
                            ds.Rows.Add(values);
                        }
                        for (int i = 0; i < ds.Rows.Count; i++)
                        {
                            object o = ds.Rows[i][5];
                            string a = o.ToString();
                            if (o != DBNull.Value)
                            {
                                if (ds.Rows[i][6].ToString() != "0")
                                {
                                    double quantity = Convert.ToDouble(ds.Rows[i][4]) + Convert.ToDouble(ds.Rows[i][6]);
                                    if (quantity >= 0)
                                    {
                                        bool success = dbhandler.purchase_update(ds.Rows[i][1].ToString(), quantity.ToString());
                                        if (success)
                                        {
                                            //log += "ITEM:" + ds.Rows[i][0].ToString() + " PREVIOUS ORDER:" + ds.Rows[i][3].ToString() + " RECENT ORDER:" + ds.Rows[i][5].ToString() + " STATUS: ordered" + " ENTRY :" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                                            table1.AddCell(ds.Rows[i][1].ToString());
                                            table1.AddCell(ds.Rows[i][6].ToString());
                                        }

                                        else
                                        {
                                            MessageBox.Show("FAIL");
                                        }
                                    }

                                    else
                                    {
                                        MessageBox.Show(ds.Rows[i][0].ToString() + ": VALUE CAN'T BE LESS THAN ZERO", "WARNING");
                                    }
                                }
                            }
                        }



                        document.Add(table1);
                        document.Close();
                    }
                    catch (Exception m)
                    {
                        MessageBox.Show(m.Message);
                    }

                    MaterialMessageBox.Show(@"Purchase order generated in " + filename);
                    // dbhandler.log_update(dbhandler.Storelog, log);
                    Items.Clear();
                    table_update();
                }
            }
        }
Beispiel #40
0
        private void AddPageWithBackgroundSX(iTextSharp.text.Document doc)
        {
            // Add a logo
            String appPath = System.IO.Directory.GetCurrentDirectory();

            //iTextSharp.text.Image bg_sx = iTextSharp.text.Image.GetInstance(appPath + "\\sfondi\\pag12_72dpi.jpg");
            iTextSharp.text.Image bg_sx = iTextSharp.text.Image.GetInstance(appPath + "\\sfondi\\pag12.jpg");
            //bg_sx.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
            bg_sx.ScaleToFit(802, 595);
            bg_sx.Alignment = iTextSharp.text.Image.UNDERLYING;
            doc.Add(bg_sx);
            bg_sx = null;

            // Write page content.  Note the use of fonts and alignment attributes.
            //this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, new Chunk("\n\nMY SCIENCE PROJECT\n\n"));
            //this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _standardFont, new Chunk("by M. Lichtenberg\n\n\n\n"));

            // Write additional page content
            //this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, new Chunk("\n\n\nWhat kind of paper is the best for making paper airplanes?\n\n\n\n\n"));
            //this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _smallFont, new Chunk("Generated " +
            //    DateTime.Now.Day.ToString() + " " +
            //    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month) + " " +
            //    DateTime.Now.Year.ToString() + " " +
            //    DateTime.Now.ToShortTimeString()));



            //PdfPTable table = new PdfPTable(3);
            //table.WidthPercentage = 100;
            //table.AddCell("Cell 1");
            //PdfPCell cell = new PdfPCell(new Phrase("Cell 2", new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
            //cell.BorderWidthBottom = 3f;
            //cell.BorderWidthTop = 3f;
            //cell.PaddingBottom = 10f;
            //cell.PaddingLeft = 20f;
            //cell.PaddingTop = 4f;
            //table.AddCell(cell);
            //table.AddCell("Cell 3");
            //doc.Add(table);

            // Set up the fonts to be used on the pages

            BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);

            Font times = new Font(bfTimes, 12, Font.ITALIC, BaseColor.RED);


            Font pippo = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.WHITE);


            // Generate external links to be embedded in the page
            iTextSharp.text.Anchor bibliographyAnchor1 = new Anchor("TDS", _standardFont);
            bibliographyAnchor1.Reference = "link.pdf";

            // Add the links to the page
            //this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_LEFT, _standardFont, bibliographyAnchor1);


            iTextSharp.text.Paragraph paragraphTable1 = new iTextSharp.text.Paragraph();
            paragraphTable1.SpacingBefore = 100f;
            paragraphTable1.SpacingAfter  = 15f;

            PdfPTable table = new PdfPTable(7);

            table.TotalWidth  = 792f;
            table.LockedWidth = true;

            float[] colWidths = { 105, 87, 85, 67, 67, 228, 73 };
            table.SetWidths(colWidths);

            table.DefaultCell.Phrase              = new Phrase("", pippo);
            table.DefaultCell.BorderWidth         = 8;
            table.DefaultCell.HorizontalAlignment = 1;
            table.DefaultCell.VerticalAlignment   = 1;
            table.DefaultCell.BackgroundColor     = new BaseColor(219, 220, 222);
            table.DefaultCell.BorderColor         = new BaseColor(255, 255, 255);
            table.DefaultCell.MinimumHeight       = 35f;

            table.AddCell("Nome Commerciale");
            table.AddCell("INCI USA");
            table.AddCell("INCI EU");
            table.AddCell("CAS");
            table.AddCell("EINECS");
            table.AddCell("Descrizione funzione");
            table.AddCell("Categorie di utilizzo");
            table.Rows[0].GetCells()[0].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[1].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[2].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[3].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[4].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[5].BackgroundColor = new BaseColor(0, 159, 238);
            table.Rows[0].GetCells()[6].BackgroundColor = new BaseColor(0, 159, 238);

            table.AddCell("Nome Commerciale");
            table.AddCell("INCI USA");
            table.AddCell("INCI EU");
            table.AddCell("CAS");
            table.AddCell("EINECS");
            table.AddCell("Descrizione funzione");
            table.AddCell("Categorie di utilizzo");

            Phrase ph = new Phrase();

            ph.Add("testo \n");
            ph.Add(bibliographyAnchor1);
            Chunk ch = new Chunk();

            ch.Font.SetStyle(1);
            ch.Append("\n boldissssimo");

            ph.Add(ch);


            table.AddCell(ph);
            table.AddCell("INCI USA");
            table.AddCell("INCI EU");
            table.AddCell("CAS");
            table.AddCell("EINECS");
            table.AddCell("Descrizione funzione");
            table.AddCell("Categorie di utilizzo");



            paragraphTable1.Add(table);
            doc.Add(paragraphTable1);
        }
Beispiel #41
0
        public void Render(iTextSharp.text.Paragraph itextParagraph)
        {
            Chunk textChunk = new Chunk(Text, ITextFont);

            itextParagraph.Add(textChunk);
        }
Beispiel #42
0
        public static void ExportDataSetToPdf(DataSet dsTable, String strPdfPath, string strHeader)
        {
            System.IO.FileStream fs       = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            BaseFont bf      = BaseFont.CreateFont("C:/WINDOWS/FONTS/TIMES.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            Font     fntHead = new Font(bf, 20, 1, iTextSharp.text.BaseColor.GRAY);

            iTextSharp.text.Paragraph prgHeading = new iTextSharp.text.Paragraph();
            prgHeading.Alignment = Element.ALIGN_CENTER;
            prgHeading.Add(new Chunk(strHeader.ToUpper(), fntHead));
            document.Add(prgHeading);

            document.Add(new Chunk("\n", fntHead));

            iTextSharp.text.Paragraph prgAuthor = new iTextSharp.text.Paragraph();
            Font fntAuthor = new Font(bf, 10, 2, iTextSharp.text.BaseColor.GRAY);

            prgAuthor.Alignment = Element.ALIGN_RIGHT;
            prgAuthor.Add(new Chunk("Autor: Adam Posłuszny", fntAuthor));
            prgAuthor.Add(new Chunk("\n Data utworzenia: " + DateTime.Now.ToShortDateString(), fntAuthor));
            prgAuthor.Add(new Chunk("\n nr PWZF 1266", fntAuthor));
            document.Add(prgAuthor);

            document.Add(new Chunk("\n", fntHead));

            Font fontDane = new Font(bf, 12);

            document.Add(new Chunk("Imię nazwisko: " + dsTable.Tables["PacjenciOsobowe"].Rows[0][1].ToString() + " " + dsTable.Tables["PacjenciOsobowe"].Rows[0][2].ToString() + "\n", fontDane));
            document.Add(new Chunk("PESEL: " + dsTable.Tables["PacjenciOsobowe"].Rows[0][6].ToString() + "\n", fontDane));

            iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, 0, 0.0F)));
            document.Add(p);


            document.Add(new Chunk("\n"));
            document.Add(new Chunk("Dane medyczne: \n", fontDane));

            PdfPTable tableMedyczne = new PdfPTable(6);

            tableMedyczne.WidthPercentage = 95;

            PdfPCell cellTproblemyWciazy = new PdfPCell(new Phrase("Problemy w trakcie ciąży", fontDane));

            cellTproblemyWciazy.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTproblemyWciazy.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTproblemyWciazy.Padding             = 5;
            tableMedyczne.AddCell(cellTproblemyWciazy);
            PdfPCell cellProblemyWciazy = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][1].ToString(), fontDane));

            cellProblemyWciazy.Padding = 5;
            cellProblemyWciazy.Colspan = 5;
            tableMedyczne.AddCell(cellProblemyWciazy);


            PdfPCell cellTporod = new PdfPCell(new Phrase("Poród", fontDane));

            cellTporod.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTporod.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTporod.Padding             = 5;
            cellTporod.Rowspan             = 2;
            tableMedyczne.AddCell(cellTporod);

            PdfPCell cellTwTerminie = new PdfPCell(new Phrase("w terminie", fontDane));

            cellTwTerminie.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTwTerminie.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTwTerminie.Padding             = 5;
            tableMedyczne.AddCell(cellTwTerminie);
            PdfPCell cellTpozaTerminem = new PdfPCell(new Phrase("poza terminie", fontDane));

            cellTpozaTerminem.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozaTerminem.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozaTerminem.Padding             = 5;
            tableMedyczne.AddCell(cellTpozaTerminem);
            PdfPCell cellTsilamiNatury = new PdfPCell(new Phrase("siłami natury", fontDane));

            cellTsilamiNatury.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTsilamiNatury.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTsilamiNatury.Padding             = 5;
            tableMedyczne.AddCell(cellTsilamiNatury);
            PdfPCell cellTcesarskieCieciePlanowane = new PdfPCell(new Phrase("cesarskie cięcie planowane", fontDane));

            cellTcesarskieCieciePlanowane.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTcesarskieCieciePlanowane.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTcesarskieCieciePlanowane.Padding             = 5;
            tableMedyczne.AddCell(cellTcesarskieCieciePlanowane);
            PdfPCell cellTcesarskieCiecieZkoniecznosci = new PdfPCell(new Phrase("cesarskie cięcie z konieczności", fontDane));

            cellTcesarskieCiecieZkoniecznosci.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTcesarskieCiecieZkoniecznosci.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTcesarskieCiecieZkoniecznosci.Padding             = 5;
            tableMedyczne.AddCell(cellTcesarskieCiecieZkoniecznosci);

            PdfPCell cellwTerminie = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][2].ToString(), fontDane));

            cellwTerminie.HorizontalAlignment = Element.ALIGN_CENTER;
            cellwTerminie.VerticalAlignment   = Element.ALIGN_CENTER;
            cellwTerminie.Padding             = 5;
            tableMedyczne.AddCell(cellwTerminie);
            PdfPCell cellpozaTerminem = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][3].ToString(), fontDane));

            cellpozaTerminem.HorizontalAlignment = Element.ALIGN_CENTER;
            cellpozaTerminem.VerticalAlignment   = Element.ALIGN_CENTER;
            cellpozaTerminem.Padding             = 5;
            tableMedyczne.AddCell(cellpozaTerminem);
            PdfPCell cellsilamiNatury = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][4].ToString(), fontDane));

            cellsilamiNatury.HorizontalAlignment = Element.ALIGN_CENTER;
            cellsilamiNatury.VerticalAlignment   = Element.ALIGN_CENTER;
            cellsilamiNatury.Padding             = 5;
            tableMedyczne.AddCell(cellsilamiNatury);
            PdfPCell cellcesarskieCieciePlanowane = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][5].ToString(), fontDane));

            cellcesarskieCieciePlanowane.HorizontalAlignment = Element.ALIGN_CENTER;
            cellcesarskieCieciePlanowane.VerticalAlignment   = Element.ALIGN_CENTER;
            cellcesarskieCieciePlanowane.Padding             = 5;
            tableMedyczne.AddCell(cellcesarskieCieciePlanowane);
            PdfPCell cellcesarskieCiecieZkoniecznosci = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][6].ToString(), fontDane));

            cellcesarskieCiecieZkoniecznosci.HorizontalAlignment = Element.ALIGN_CENTER;
            cellcesarskieCiecieZkoniecznosci.VerticalAlignment   = Element.ALIGN_CENTER;
            cellcesarskieCiecieZkoniecznosci.Padding             = 5;
            tableMedyczne.AddCell(cellcesarskieCiecieZkoniecznosci);


            PdfPCell cellTproblemyPoPorodzie = new PdfPCell(new Phrase("Problemy po porodzie", fontDane));

            cellTproblemyPoPorodzie.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTproblemyPoPorodzie.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTproblemyPoPorodzie.Padding             = 5;
            tableMedyczne.AddCell(cellTproblemyPoPorodzie);
            PdfPCell cellproblemyPoPorodzie = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][7].ToString(), fontDane));

            cellproblemyPoPorodzie.Padding = 5;
            cellproblemyPoPorodzie.Colspan = 5;
            tableMedyczne.AddCell(cellproblemyPoPorodzie);

            PdfPCell cellTdaneUzyskane = new PdfPCell(new Phrase("Dane uzyskane z wypisów i badań medycznych", fontDane));

            cellTdaneUzyskane.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTdaneUzyskane.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTdaneUzyskane.Padding             = 5;
            tableMedyczne.AddCell(cellTdaneUzyskane);
            PdfPCell celldaneUzyskane = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][8].ToString(), fontDane));

            celldaneUzyskane.Padding = 5;
            celldaneUzyskane.Colspan = 5;
            tableMedyczne.AddCell(celldaneUzyskane);

            PdfPCell cellTzauwaznoeProblemy = new PdfPCell(new Phrase("Problemy zauważone przez rodziców", fontDane));

            cellTzauwaznoeProblemy.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTzauwaznoeProblemy.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTzauwaznoeProblemy.Padding             = 5;
            tableMedyczne.AddCell(cellTzauwaznoeProblemy);
            PdfPCell cellzauwaznoeProblemy = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][9].ToString(), fontDane));

            cellzauwaznoeProblemy.Padding = 5;
            cellzauwaznoeProblemy.Colspan = 5;
            tableMedyczne.AddCell(cellzauwaznoeProblemy);

            PdfPCell cellTinfoPrzetwarzanie = new PdfPCell(new Phrase("Informacje dotyczące przetwarzania sensorycznego", fontDane));

            cellTinfoPrzetwarzanie.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTinfoPrzetwarzanie.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTinfoPrzetwarzanie.Padding             = 5;
            tableMedyczne.AddCell(cellTinfoPrzetwarzanie);
            PdfPCell cellinfoPrzetwarzanie = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][10].ToString(), fontDane));

            cellinfoPrzetwarzanie.Padding = 5;
            cellinfoPrzetwarzanie.Colspan = 5;
            tableMedyczne.AddCell(cellinfoPrzetwarzanie);

            PdfPCell cellTinneSchorzenia = new PdfPCell(new Phrase("Inne schorzenia, alergie, epilepsja, zabiegi", fontDane));

            cellTinneSchorzenia.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTinneSchorzenia.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTinneSchorzenia.Padding             = 5;
            tableMedyczne.AddCell(cellTinneSchorzenia);
            PdfPCell cellinneSchorzenia = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][11].ToString(), fontDane));

            cellinneSchorzenia.Padding = 5;
            cellinneSchorzenia.Colspan = 5;
            tableMedyczne.AddCell(cellinneSchorzenia);

            document.Add(tableMedyczne);

            document.NewPage();

            document.Add(new Chunk("\n"));
            document.Add(new Chunk("Obserwacje: \n", fontDane));

            PdfPTable tableObserwacje = new PdfPTable(6);

            tableObserwacje.WidthPercentage = 95;

            PdfPCell cellTpozycjaSupinacyjna = new PdfPCell(new Phrase("Pozycja supinacyjna", fontDane));

            cellTpozycjaSupinacyjna.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaSupinacyjna.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaSupinacyjna.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaSupinacyjna);
            PdfPCell cellpozycjaSupinacyjna = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][12].ToString(), fontDane));

            cellpozycjaSupinacyjna.Padding = 5;
            cellpozycjaSupinacyjna.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaSupinacyjna);

            PdfPCell cellTpozycjaPronacyjna = new PdfPCell(new Phrase("Pozycja pronacyjna", fontDane));

            cellTpozycjaPronacyjna.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaPronacyjna.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaPronacyjna.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaPronacyjna);
            PdfPCell cellpozycjaPronacyjna = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][13].ToString(), fontDane));

            cellpozycjaPronacyjna.Padding = 5;
            cellpozycjaPronacyjna.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaPronacyjna);

            PdfPCell cellTpozycjaBocznaL = new PdfPCell(new Phrase("Pozycja boczna lewa", fontDane));

            cellTpozycjaBocznaL.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaBocznaL.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaBocznaL.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaBocznaL);
            PdfPCell cellpozycjaBocznaL = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][14].ToString(), fontDane));

            cellpozycjaBocznaL.Padding = 5;
            cellpozycjaBocznaL.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaBocznaL);

            PdfPCell cellTpozycjaBocznaP = new PdfPCell(new Phrase("Pozycja boczna prawa", fontDane));

            cellTpozycjaBocznaP.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaBocznaP.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaBocznaP.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaBocznaP);
            PdfPCell cellpozycjaBocznaP = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][15].ToString(), fontDane));

            cellpozycjaBocznaP.Padding = 5;
            cellpozycjaBocznaP.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaBocznaP);

            PdfPCell cellTpozycjaSiedzaca = new PdfPCell(new Phrase("Pozycja siedząca", fontDane));

            cellTpozycjaSiedzaca.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaSiedzaca.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaSiedzaca.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaSiedzaca);
            PdfPCell cellpozycjaSiedzaca = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][16].ToString(), fontDane));

            cellpozycjaSiedzaca.Padding = 5;
            cellpozycjaSiedzaca.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaSiedzaca);

            PdfPCell cellTklekPodparty = new PdfPCell(new Phrase("Klęk podparty", fontDane));

            cellTklekPodparty.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTklekPodparty.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTklekPodparty.Padding             = 5;
            tableObserwacje.AddCell(cellTklekPodparty);
            PdfPCell cellklekPodparty = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][17].ToString(), fontDane));

            cellklekPodparty.Padding = 5;
            cellklekPodparty.Colspan = 5;
            tableObserwacje.AddCell(cellklekPodparty);

            PdfPCell cellTklekJednonoz = new PdfPCell(new Phrase("Klęk jednonóż", fontDane));

            cellTklekJednonoz.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTklekJednonoz.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTklekJednonoz.Padding             = 5;
            tableObserwacje.AddCell(cellTklekJednonoz);
            PdfPCell cellklekJednonoz = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][18].ToString(), fontDane));

            cellklekJednonoz.Padding = 5;
            cellklekJednonoz.Colspan = 5;
            tableObserwacje.AddCell(cellklekJednonoz);

            PdfPCell cellTpozycjaStojaca = new PdfPCell(new Phrase("Pozycja stojąca", fontDane));

            cellTpozycjaStojaca.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTpozycjaStojaca.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTpozycjaStojaca.Padding             = 5;
            tableObserwacje.AddCell(cellTpozycjaStojaca);
            PdfPCell cellpozycjaStojaca = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][19].ToString(), fontDane));

            cellpozycjaStojaca.Padding = 5;
            cellpozycjaStojaca.Colspan = 5;
            tableObserwacje.AddCell(cellpozycjaStojaca);

            PdfPCell cellTchod = new PdfPCell(new Phrase("Chód", fontDane));

            cellTchod.HorizontalAlignment = Element.ALIGN_CENTER;
            cellTchod.VerticalAlignment   = Element.ALIGN_CENTER;
            cellTchod.Padding             = 5;
            tableObserwacje.AddCell(cellTchod);
            PdfPCell cellchod = new PdfPCell(new Phrase(dsTable.Tables["PacjenciMedyczne"].Rows[0][20].ToString(), fontDane));

            cellchod.Padding = 5;
            cellchod.Colspan = 5;
            tableObserwacje.AddCell(cellchod);

            document.Add(tableObserwacje);

            document.NewPage();

            document.Add(new Chunk("\n"));
            document.Add(new Chunk("Wizyty: \n", fontDane));


            for (int i = 0; i < dsTable.Tables["Wizyty"].Rows.Count; i++)
            {
                if (i % 2 == 0 && i != 0)
                {
                    document.NewPage();
                }
                PdfPTable tableWizyty = new PdfPTable(7);
                tableWizyty.WidthPercentage = 95;

                PdfPCell cellTdata = new PdfPCell(new Phrase("Data wizyty", fontDane));
                cellTdata.HorizontalAlignment = Element.ALIGN_CENTER;
                cellTdata.VerticalAlignment   = Element.ALIGN_CENTER;
                cellTdata.Padding             = 5;
                tableWizyty.AddCell(cellTdata);

                PdfPCell cellTZmiany = new PdfPCell(new Phrase("Zmiany", fontDane));
                cellTZmiany.Colspan             = 3;
                cellTZmiany.HorizontalAlignment = Element.ALIGN_CENTER;
                cellTZmiany.VerticalAlignment   = Element.ALIGN_CENTER;
                cellTZmiany.Padding             = 5;
                tableWizyty.AddCell(cellTZmiany);

                PdfPCell cellTZalecenia = new PdfPCell(new Phrase("Zalecenia", fontDane));
                cellTZalecenia.Colspan             = 3;
                cellTZalecenia.HorizontalAlignment = Element.ALIGN_CENTER;
                cellTZalecenia.VerticalAlignment   = Element.ALIGN_CENTER;
                cellTZalecenia.Padding             = 5;
                tableWizyty.AddCell(cellTZalecenia);

                PdfPCell celldata = new PdfPCell(new Phrase(Convert.ToDateTime(dsTable.Tables["Wizyty"].Rows[i][1]).ToShortDateString(), fontDane));
                celldata.Padding = 5;
                tableWizyty.AddCell(celldata);

                PdfPCell cellZmiany = new PdfPCell(new Phrase(dsTable.Tables["Wizyty"].Rows[i][2].ToString(), fontDane));
                cellZmiany.Colspan = 3;
                cellZmiany.Padding = 5;
                tableWizyty.AddCell(cellZmiany);

                PdfPCell cellZalecenia = new PdfPCell(new Phrase(dsTable.Tables["Wizyty"].Rows[i][3].ToString(), fontDane));
                cellZalecenia.Colspan = 3;
                cellZalecenia.Padding = 5;
                tableWizyty.AddCell(cellZalecenia);

                PdfPCell cellTZabiegi = new PdfPCell(new Phrase("Zabiegi", fontDane));
                cellTZabiegi.Colspan             = 7;
                cellTZabiegi.HorizontalAlignment = Element.ALIGN_CENTER;
                cellTZabiegi.VerticalAlignment   = Element.ALIGN_CENTER;
                cellTZabiegi.Padding             = 5;
                tableWizyty.AddCell(cellTZabiegi);

                PdfPCell cellZabiegi = new PdfPCell(new Phrase(dsTable.Tables["Wizyty"].Rows[i][4].ToString(), fontDane));
                cellZabiegi.Colspan = 7;
                cellZabiegi.Padding = 5;
                tableWizyty.AddCell(cellZabiegi);

                document.Add(tableWizyty);
                document.Add(new Chunk("\n"));
            }

            document.Close();
            writer.Close();
            fs.Close();
        }
Beispiel #43
0
        private void bntSavePdf_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog()
            {
                FileName = comboBox1.Text + ".pdf", ValidateNames = true
            })
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    iTextSharp.text.Rectangle bussinessCard = new iTextSharp.text.Rectangle(241, 156);

                    Document doc = new Document(PageSize.A7);
                    doc.SetMargins(14.2f, 0, 0, 0);
                    //doc.SetMargins(14.5f, 14, 0, 0);
                    doc.SetPageSize(bussinessCard);
                    iTextSharp.text.Font font_01 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gill Sans.ttf", 9, BaseColor.BLACK);
                    font_01.BaseFont.IsEmbedded();
                    iTextSharp.text.Font font_02 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gill Sans.ttf", 7, BaseColor.BLACK);
                    font_02.BaseFont.IsEmbedded();
                    iTextSharp.text.Font font_03 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gnl____.ttf", 7, BaseColor.BLACK);
                    font_03.BaseFont.IsEmbedded();
                    iTextSharp.text.Font font_04 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gnl____.ttf", 5, BaseColor.BLACK);
                    font_04.BaseFont.IsEmbedded();
                    iTextSharp.text.Chunk C00 = new iTextSharp.text.Chunk(" ", font_01);
                    iTextSharp.text.Chunk C01 = new iTextSharp.text.Chunk(tbName.Text + " ", font_01);
                    iTextSharp.text.Chunk C02 = new iTextSharp.text.Chunk(tbTitle.Text + " ", font_02);
                    iTextSharp.text.Chunk C03 = new iTextSharp.text.Chunk(tbQuaifications.Text + " ", font_02);
                    iTextSharp.text.Chunk C04 = new iTextSharp.text.Chunk(tbTelephone.Text + " ", font_03);
                    iTextSharp.text.Chunk C05 = new iTextSharp.text.Chunk(tbMobile.Text + " ", font_03);
                    iTextSharp.text.Chunk C06 = new iTextSharp.text.Chunk(tbEmail.Text + " ", font_03);
                    iTextSharp.text.Chunk C07 = new iTextSharp.text.Chunk(tbComName.Text, font_04);
                    iTextSharp.text.Chunk C08 = new iTextSharp.text.Chunk(tbRegNo.Text, font_04);
                    iTextSharp.text.Chunk C09 = new iTextSharp.text.Chunk(tbOffice.Text, font_03);
                    iTextSharp.text.Chunk C10 = new iTextSharp.text.Chunk(tbStreet.Text, font_03);
                    iTextSharp.text.Chunk C11 = new iTextSharp.text.Chunk(tbArea.Text, font_03);
                    iTextSharp.text.Chunk C12 = new iTextSharp.text.Chunk(tbRegion.Text, font_03);
                    iTextSharp.text.Chunk C13 = new iTextSharp.text.Chunk(tbPostalCode.Text, font_03);
                    iTextSharp.text.Chunk C14 = new iTextSharp.text.Chunk(tbWeb.Text, font_03);

                    Paragraph pa00 = new iTextSharp.text.Paragraph();
                    pa00.Add(C00);
                    Paragraph pa01 = new iTextSharp.text.Paragraph();
                    pa01.Add(C01);
                    pa01.SpacingBefore = 37.5f;
                    Paragraph pa02 = new iTextSharp.text.Paragraph();
                    pa02.Add(C02);
                    pa02.SpacingBefore = -7f;
                    Paragraph pa03 = new iTextSharp.text.Paragraph();
                    pa03.Add(C03);
                    pa03.SpacingBefore = -7f;
                    Paragraph pa04 = new iTextSharp.text.Paragraph();
                    pa04.Add(C04);
                    pa04.SpacingBefore = 1.6f;
                    Paragraph pa05 = new iTextSharp.text.Paragraph();
                    pa05.Add(C05);
                    pa05.SpacingBefore = -6.9f;
                    Paragraph pa06 = new iTextSharp.text.Paragraph();
                    pa06.Add(C06);
                    pa06.SpacingBefore = -6.9f;
                    Paragraph pa07 = new iTextSharp.text.Paragraph();
                    pa07.Add(C07);
                    pa07.SpacingBefore = -3f;
                    Paragraph pa08 = new iTextSharp.text.Paragraph();
                    pa08.Add(C08);
                    pa08.SpacingBefore = 11f;
                    Paragraph pa09 = new iTextSharp.text.Paragraph();
                    pa09.Add(C09);
                    pa09.SpacingBefore   = -74f;
                    pa09.IndentationLeft = 127f;
                    Paragraph pa10 = new iTextSharp.text.Paragraph();
                    pa10.Add(C10);
                    pa10.SpacingBefore   = -7f;
                    pa10.IndentationLeft = 127f;
                    Paragraph pa11 = new iTextSharp.text.Paragraph();
                    pa11.Add(C11);
                    pa11.IndentationLeft = 127f;
                    pa11.SpacingBefore   = -7f;
                    Paragraph pa12 = new iTextSharp.text.Paragraph();
                    pa12.Add(C12);
                    pa12.IndentationLeft = 127f;
                    pa12.SpacingBefore   = -7f;
                    Paragraph pa13 = new iTextSharp.text.Paragraph();
                    pa13.Add(C13);
                    pa13.IndentationLeft = 127f;
                    pa13.SpacingBefore   = -7f;
                    Paragraph pa14 = new iTextSharp.text.Paragraph();
                    pa14.Add(C14);
                    pa14.IndentationLeft = 127f;
                    pa14.SpacingBefore   = 11f;
                    iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("Logo.jpg");
                    logo.Alignment = iTextSharp.text.Image.UNDERLYING;
                    logo.ScaleAbsolute(241, 156);
                    logo.SetAbsolutePosition(0, 0);



                    try
                    {
                        PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                        doc.Open();
                        if (checkBox1.Checked)
                        {
                            doc.Add(logo);
                        }
                        //doc.Add(logo);

                        doc.Add(pa00);
                        doc.Add(pa01);
                        doc.Add(pa02);
                        doc.Add(pa03);
                        doc.Add(pa04);
                        doc.Add(pa05);
                        doc.Add(pa06);
                        doc.Add(pa07);
                        //doc.Add(pa08);
                        doc.Add(pa09);
                        doc.Add(pa10);
                        doc.Add(pa11);
                        doc.Add(pa12);
                        doc.Add(pa13);
                        doc.Add(pa08);
                        //doc.Add(logo);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        doc.Close();
                    }
                }
            }
        }
Beispiel #44
0
        /**
         * Applies the tab interval of the p tag on its {@link TabbedChunk} elements. <br />
         * The style "xfa-tab-count" of the {@link TabbedChunk} is multiplied with the tab interval of the p tag. This width is then added to a new {@link TabbedChunk}.
         *
         * @param currentContent containing the elements inside the p tag.
         * @param p paragraph to which the tabbed chunks will be added.
         * @param value the value of style "tab-interval".
         */
        private void AddTabIntervalContent(IWorkerContext ctx, Tag tag, IList<IElement> currentContent, Paragraph p, String value) {
        float width = 0;
		foreach(IElement e in currentContent) {
		    if (e is TabbedChunk) {
			    width += ((TabbedChunk) e).TabCount * CssUtils.GetInstance().ParsePxInCmMmPcToPt(value);
                TabbedChunk tab = new TabbedChunk(new VerticalPositionMark(), width, false);
			    p.Add(new Chunk(tab));
			    p.Add(new Chunk((TabbedChunk) e));
            } else {
                if (e is LineSeparator) {
                    try {
                        HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                        Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext);
                        p.Add(newLine);
                    } catch (NoCustomContextException exc) {
                        throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc);
                    }
                }
			    p.Add(e);
            }
        }
    }
        private void stampaj_racun()
        {
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate());
            string date_time             = (DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second).ToString();

            try
            {
                string dir_mb = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MobileTown_racuni";

                if (Directory.Exists(dir_mb))
                {
                    PdfWriter.GetInstance(doc, new FileStream(dir_mb + "\\servis" + date_time + ".pdf", FileMode.Create));
                    doc.Open();
                }
                else
                {
                    Directory.CreateDirectory(dir_mb);
                    PdfWriter.GetInstance(doc, new FileStream(dir_mb + "\\servis" + date_time + ".pdf", FileMode.Create));
                    doc.Open();
                }

                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("Mobile Town");
                title.Alignment = Element.ALIGN_CENTER;
                title.Font.Size = 32;
                doc.Add(title);

                iTextSharp.text.Paragraph podaci;
                podaci = new iTextSharp.text.Paragraph("\n");
                podaci.Add("\n");
                podaci.Add("           Datum:" + DateTime.Now.ToString("       dd-MM-yyyy HH-mm"));
                podaci.Add("\n");
                podaci.Add("           " + "Servis");
                podaci.Font.Size = 14;
                doc.Add(podaci);

                iTextSharp.text.Paragraph razmak = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak);

                PdfPTable table = new PdfPTable(4);
                table.AddCell("id Servisa");
                table.AddCell("Opis kvara");
                table.AddCell("Datum izdavanja");
                table.AddCell("Iznos");

                table.AddCell(sifra.ToString());
                table.AddCell(opis_kvara);
                table.AddCell(DateTime.Now.ToString("dd-MM-yyyy HH:mm"));
                table.AddCell(textBox1.Text);

                doc.Add(table);

                iTextSharp.text.Paragraph razmak1 = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak1);

                PdfPTable table_konacno = new PdfPTable(2);
                table_konacno.AddCell("Ukupno");
                table_konacno.AddCell("PDV(20%) Ukupno");

                table_konacno.AddCell(textBox1.Text);
                table_konacno.AddCell((double.Parse(textBox1.Text) * 0.2).ToString());
                doc.Add(table_konacno);

                iTextSharp.text.Paragraph razmak2 = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak2);

                PdfPTable potpis_pecat = new PdfPTable(2);
                potpis_pecat.AddCell("Racun izdaje");
                potpis_pecat.AddCell("Racun prima");

                potpis_pecat.AddCell(ime_prezime);
                potpis_pecat.AddCell("");
                doc.Add(potpis_pecat);

                System.Diagnostics.Process.Start(dir_mb + "\\servis" + date_time + ".pdf");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                doc.Close();
            }
        }
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter   = "PDF Document (.pdf)|*.pdf";
            saveFileDialog.FileName = Guid.NewGuid().ToString();

            var context = (this.DataContext as CalculatorHomeViewModel);

            if (context.Diagnose == null)
            {
                context.Diagnose = "";
            }
            if (context.FirstName == null)
            {
                context.FirstName = "";
            }
            if (context.LastName == null)
            {
                context.LastName = "";
            }
            if (context.Doctor == null)
            {
                context.Doctor = "";
            }
            if (context.Note == null)
            {
                context.Note = "";
            }
            if (saveFileDialog.ShowDialog() == true)
            {
                var path = saveFileDialog.FileName;

                using (MemoryStream myMemoryStream = new MemoryStream())
                {
                    Document myDocument = new Document();


                    PdfWriter myPDFWriter = PdfWriter.GetInstance(myDocument, myMemoryStream);

                    Assembly ass    = Assembly.GetExecutingAssembly();
                    string   arPath = System.IO.Path.GetDirectoryName(ass.Location);
                    string   resourcesFolderPath = System.IO.Path.Combine(
                        Directory.GetParent(arPath).Parent.FullName, "Resources");
                    string ARIALUNI_TFF = System.IO.Path.Combine(resourcesFolderPath, "ARIALUNI.TTF");

                    //Create a base font object making sure to specify IDENTITY-H
                    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                    //Create a specific font object
                    Font f = new Font(bf, 12, Font.NORMAL);

                    myDocument.Open();

                    Font titleFont = new Font(bf, 22, Font.NORMAL);
                    var  title     = new iTextSharp.text.Paragraph("План за лечение", titleFont);
                    title.Alignment = Element.ALIGN_CENTER;

                    myDocument.Add(title);
                    myDocument.Add(new Chunk("\n"));

                    iTextSharp.text.Paragraph par  = new iTextSharp.text.Paragraph("Пациент: " + context.FirstName + " " + context.LastName, f);
                    iTextSharp.text.Paragraph par1 = new iTextSharp.text.Paragraph("Доктор: " + context.Doctor, f);
                    iTextSharp.text.Paragraph par2 = new iTextSharp.text.Paragraph("Диагноза: " + context.Diagnose, f);
                    iTextSharp.text.Paragraph par3 = new iTextSharp.text.Paragraph("Бележка: " + context.Note, f);

                    myDocument.Add(par);
                    myDocument.Add(par1);
                    myDocument.Add(par2);
                    myDocument.Add(par3);
                    myDocument.Add(new Chunk("\n"));

                    var  tableTit   = new PdfPTable(4);
                    Font titB       = new Font(bf, 12, Font.BOLD);
                    var  firstTCell = new PdfPCell((new iTextSharp.text.Paragraph("Дейност", titB)));
                    firstTCell.BorderColor = BaseColor.WHITE;
                    var secondTCell = new PdfPCell((new iTextSharp.text.Paragraph("Брой", titB)));
                    secondTCell.BorderColor = BaseColor.WHITE;
                    var thirdTCell = new PdfPCell((new iTextSharp.text.Paragraph("Цена", titB)));
                    thirdTCell.BorderColor = BaseColor.WHITE;

                    var fourthTCell = new PdfPCell((new iTextSharp.text.Paragraph("Ед.цена", titB)));
                    fourthTCell.BorderColor = BaseColor.WHITE;
                    tableTit.AddCell(firstTCell);
                    tableTit.AddCell(fourthTCell);
                    tableTit.AddCell(secondTCell);
                    tableTit.AddCell(thirdTCell);
                    myDocument.Add(tableTit);

                    var table1 = new PdfPTable(4);
                    foreach (var item in context.Rows)
                    {
                        if (item.SelectedActivity != null)
                        {
                            var f1 = new PdfPCell(new iTextSharp.text.Paragraph(item.SelectedActivity.Name.ToString(), f));
                            f1.Border         = 0;
                            f1.BorderWidthTop = 1;
                            var s1 = new PdfPCell(new iTextSharp.text.Paragraph(item.CountProcedures.ToString(), f));
                            s1.Border         = 0;
                            s1.BorderWidthTop = 1;
                            var t1 = new PdfPCell(new iTextSharp.text.Paragraph(item.RowPrice.ToString() + " лв.", f));
                            t1.Border         = 0;
                            t1.BorderWidthTop = 1;
                            var fo1 = new PdfPCell(new iTextSharp.text.Paragraph(item.SelectedActivity.Price.ToString() + " лв.", f));
                            fo1.Border         = 0;
                            fo1.BorderWidthTop = 1;
                            table1.AddCell(f1);
                            table1.AddCell(fo1);
                            table1.AddCell(s1);
                            table1.AddCell(t1);
                        }
                    }
                    myDocument.Add(table1);


                    myDocument.Add(new Chunk("\n"));

                    Font totalFont = new Font(bf, 14, Font.BOLD);
                    var  table3    = new PdfPTable(4);

                    var totalCell4 = new PdfPCell((new iTextSharp.text.Paragraph(" ", totalFont)));
                    totalCell4.BorderColor         = BaseColor.WHITE;
                    totalCell4.HorizontalAlignment = Element.ALIGN_RIGHT;
                    table3.AddCell(totalCell4);

                    var totalCell3 = new PdfPCell((new iTextSharp.text.Paragraph(" ", totalFont)));
                    totalCell3.BorderColor         = BaseColor.WHITE;
                    totalCell3.HorizontalAlignment = Element.ALIGN_RIGHT;
                    table3.AddCell(totalCell3);

                    var totalCell = new PdfPCell((new iTextSharp.text.Paragraph("Общо: ", totalFont)));
                    totalCell.BorderColor         = BaseColor.WHITE;
                    totalCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    table3.AddCell(totalCell);


                    var totalCell2 = new PdfPCell((new iTextSharp.text.Paragraph(context.Total.ToString() + " лв.", totalFont)));
                    totalCell2.BorderColor         = BaseColor.WHITE;
                    totalCell2.HorizontalAlignment = Element.ALIGN_LEFT;
                    table3.AddCell(totalCell2);
                    myDocument.Add(table3);

                    myDocument.Add(new Chunk("\n"));
                    myDocument.Add(new Chunk("\n"));
                    myDocument.Add(new Chunk("\n"));
                    Chunk glue = new Chunk(new VerticalPositionMark());

                    var datePar = new iTextSharp.text.Paragraph(DateTime.Now.ToShortDateString(), f);
                    datePar.Add(new Chunk(glue));


                    datePar.Add("Подпис                                       ");

                    myDocument.Add(datePar);
                    // We're done adding stuff to our PDF.
                    myDocument.Close();

                    myPDFWriter.Close();
                    byte[] content = myMemoryStream.ToArray();

                    // Write out PDF from memory stream.
                    using (FileStream fs = File.Create(path))
                    {
                        fs.Write(content, 0, (int)content.Length);
                    }
                }
            }
        }
Beispiel #47
0
        void ExportDataTableToPdf(DataTable dtblTable, String strPdfPath, string strHeader)
        {
            System.IO.FileStream fs       = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            //Report Header
            BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntHead  = new Font(bfntHead, 16, 1);

            iTextSharp.text.Paragraph prgHeading = new iTextSharp.text.Paragraph();
            prgHeading.Alignment = Element.ALIGN_CENTER;
            prgHeading.Add(new Chunk(strHeader.ToUpper(), fntHead));
            document.Add(prgHeading);

            //Author
            iTextSharp.text.Paragraph prgAuthor = new iTextSharp.text.Paragraph();
            BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntAuthor = new Font(btnAuthor, 8, 2);

            prgAuthor.Alignment = Element.ALIGN_LEFT;
            //prgAuthor.Add(new Chunk("Emitido por : Dotnet Mob", fntAuthor));
            prgAuthor.Add(new Chunk("\nFecha de Emisión : " + DateTime.Now.ToShortDateString(), fntAuthor));
            document.Add(prgAuthor);


            //Empleado
            iTextSharp.text.Paragraph prgEmp = new iTextSharp.text.Paragraph();
            BaseFont btnEmp = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntEmp = new Font(btnEmp, 8, 2);

            prgEmp.Alignment = Element.ALIGN_LEFT;
            prgEmp.Add(new Chunk("Empleado: " + empSelected.Nombres + " " + empSelected.Apellidos + "\n", fntAuthor));
            prgEmp.Add(new Chunk("Fecha de liquidación: " + lmSelected.Mes + "/" + lmSelected.Anho, fntAuthor));
            document.Add(prgEmp);

            //Add a line seperation
            iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
            document.Add(p);

            //Add line break
            document.Add(new Chunk("\n", fntHead));

            //Write the table
            PdfPTable table = new PdfPTable(dtblTable.Columns.Count);
            //Table header
            BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntColumnHeader = new Font(btnColumnHeader, 10, 1 /*, BaseColor.WHITE*/);

            for (int i = 0; i < dtblTable.Columns.Count; i++)
            {
                PdfPCell cell = new PdfPCell();
                cell.BackgroundColor = BaseColor.GRAY;
                cell.AddElement(new Chunk(dtblTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
                table.AddCell(cell);
            }
            //table Data
            for (int i = 0; i < dtblTable.Rows.Count; i++)
            {
                for (int j = 0; j < dtblTable.Columns.Count; j++)
                {
                    table.AddCell(dtblTable.Rows[i][j].ToString());
                }
            }

            document.Add(table);
            document.Close();
            writer.Close();
            fs.Close();
        }
Beispiel #48
0
        private void crtaj_fakturu()
        {
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate());
            try
            {
                PdfWriter.GetInstance(doc, new FileStream("racun.pdf", FileMode.Create));
                doc.Open();

                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("Mobile Town");
                title.Alignment = Element.ALIGN_CENTER;
                title.Font.Size = 32;
                doc.Add(title);

                iTextSharp.text.Paragraph podaci;
                podaci = new iTextSharp.text.Paragraph("\n");
                podaci.Add("\n");
                podaci.Add("           Datum:" + DateTime.Now.ToString("       dd-MM-yyyy HH-mm"));
                podaci.Add("\n");
                podaci.Add("           " + izvestaj);
                podaci.Font.Size = 14;
                doc.Add(podaci);

                iTextSharp.text.Paragraph razmak = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak);

                PdfPTable table = new PdfPTable(5);
                table.AddCell("id Racuna");
                table.AddCell("Prodavac");
                table.AddCell("Artikli");
                table.AddCell("Datum izdavanja");
                table.AddCell("Iznos");
                double suma = 0;
                foreach (DataGridViewRow datarow in dataGridView1.Rows)
                {
                    table.AddCell(datarow.Cells[0].Value.ToString());
                    table.AddCell(datarow.Cells[1].Value.ToString());
                    table.AddCell(datarow.Cells[3].Value.ToString());
                    table.AddCell(datarow.Cells[2].Value.ToString());
                    table.AddCell(datarow.Cells[4].Value.ToString());

                    suma += double.Parse(datarow.Cells[4].Value.ToString());
                }

                doc.Add(table);

                iTextSharp.text.Paragraph razmak1 = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak1);

                PdfPTable table_konacno = new PdfPTable(2);
                table_konacno.AddCell("Ukupno");
                table_konacno.AddCell("PDV(20%) Ukupno");

                table_konacno.AddCell(suma.ToString());
                table_konacno.AddCell((suma * 0.2).ToString());
                doc.Add(table_konacno);

                System.Diagnostics.Process.Start("racun.pdf");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                doc.Close();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)   //Sauvgarder le profile topographique en pdf
        {
            RenderTargetBitmap rtb = new RenderTargetBitmap((int)chart.ActualWidth, (int)chart.ActualHeight, 96, 96, PixelFormats.Pbgra32);

            rtb.Render(visual: chart);
            PngBitmapEncoder png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(rtb));
            MemoryStream stream = new MemoryStream();

            png.Save(stream);
            SaveToPng(chart, "MyChart.png");                                                                          //le nom de l'image

            iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3, 10, 40, 42, 35); //les dimensions du fichier pdf


            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "Document"; // Default file name
            dlg.DefaultExt = ".pdf";     // Default file extension
                                         //dlg.Filter = "Text documents (.topo)|*.topo"; // Filter files by extension

            // Show open file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            string filename = null;

            if (result == true)
            {
                // Open document
                filename = dlg.FileName;
            }
            try
            {
                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create));
            }
            catch (ArgumentNullException excp)
            {
                MessageBox.Show("il faut specifier un fichier pdf"); //le cas de ne pas selectioner un fichier
            }


            //L'exportation en pdf


            doc.Open();
            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("./MyChart.PNG");
            jpg.Border      = iTextSharp.text.Rectangle.BOX;
            jpg.BorderWidth = 5f;
            doc.Add(jpg);
            iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
            paragraph.Font      = new Font(FontFactory.GetFont("Arial", 16, Font.BOLD));
            paragraph.Alignment = Element.ALIGN_CENTER;//here is the change
            paragraph.Add("Profile Topographique");
            doc.Add(paragraph);

            Viewbox viewbox = new Viewbox(); //Ajuster la photo dans un cadre



            doc.Close();
            Export.IsEnabled = false; //desactivation du button de l'exportation
        }
Beispiel #50
0
        public void Print()
        {
            //logger.Info("Inicio Imprimir Resultados");
            List <DataTable> resultsTable = createResultsTables(stages);

            //var fileName = simulationPath + "\\resultados.pdf";
            System.IO.FileStream fs       = new System.IO.FileStream(simulationPath + "\\" + fileName, FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            // calling PDFFooter class to Include in document
            writer.PageEvent = new PDFFooter();

            document.Open();

            //Report Header
            BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntHead  = new Font(bfntHead, 16, 1, BaseColor.BLACK);

            iTextSharp.text.Paragraph prgHeading = new iTextSharp.text.Paragraph();
            prgHeading.Alignment = Element.ALIGN_LEFT;
            prgHeading.Add(new Chunk("Análisis de Sensibilidad", fntHead));
            document.Add(prgHeading);

            //Formato de textos
            BaseFont bfntStage       = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntStage        = new Font(bfntStage, 14, 1, BaseColor.BLACK);
            BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntColumnHeader = new Font(btnColumnHeader, 14, 1, BaseColor.WHITE);

            //CARGO LAS TABLAS SEGUN LA CANTIDAD DE STAGES
            foreach (var tbl in resultsTable)
            {
                if (tbl.TableName != "")
                {
                    //LINEA
                    iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100, BaseColor.BLACK, Element.ALIGN_LEFT, 0)));
                    document.Add(p);
                    document.Add(new Chunk("\n", fntHead));
                    //NOMBRE DEL STAGE
                    iTextSharp.text.Paragraph stageHeading = new iTextSharp.text.Paragraph();
                    stageHeading.Alignment = Element.ALIGN_CENTER;
                    stageHeading.Add(new Chunk(tbl.TableName, fntStage));
                    document.Add(stageHeading);
                }
                document.Add(new Chunk("\n", fntStage));
                //ESCRIBO TABLA
                PdfPTable table = new iTextSharp.text.pdf.PdfPTable(tbl.Columns.Count);
                //HEADER DE TABLA
                for (int i = 0; i < tbl.Columns.Count; i++)
                {
                    PdfPCell cell = new iTextSharp.text.pdf.PdfPCell();
                    cell.BackgroundColor = new BaseColor(67, 142, 185);
                    cell.AddElement(new Chunk(tbl.Columns[i].ColumnName, fntColumnHeader));
                    table.AddCell(cell);
                }

                //DATOS TABLA
                for (int i = 0; i < tbl.Rows.Count; i++)
                {
                    for (int j = 0; j < tbl.Columns.Count; j++)
                    {
                        table.AddCell(tbl.Rows[i][j].ToString());
                    }
                }

                document.Add(table);
            }
            //LINEA
            iTextSharp.text.Paragraph line = new iTextSharp.text.Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100, BaseColor.BLACK, Element.ALIGN_LEFT, 0)));
            document.Add(line);
            document.Add(new Chunk("\n", fntHead));
            //Tiempo total
            BaseFont bfntTime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntTime  = new Font(bfntTime, 14, 1, BaseColor.BLACK);

            iTextSharp.text.Paragraph prgTime = new iTextSharp.text.Paragraph();
            prgTime.Alignment = Element.ALIGN_LEFT;
            prgTime.Add(new Chunk("Tiempo total de ejecución: " + simulationTotalTime.ToString(@"hh\:mm\:ss"), fntTime));
            document.Add(prgTime);

            document.Close();
            writer.Close();
            fs.Close();
            //logger.Info("Fin Imprimir Resultados");
        }
Beispiel #51
0
        public static byte[] Download(
            int stationLocationId,
            string stationName,
            string locationName,
            string code,
            int Sno,
            IHostingEnvironment _hostingEnvironment)
        {
            try
            {
                var       memoryStream = new System.IO.MemoryStream();
                var       document     = new iTextSharp.text.Document(new Rectangle(288f, 432f));
                PdfWriter writer       = PdfWriter.GetInstance(document, memoryStream);
                document.Open();
                Phrase phrase = new Phrase();
                document.Add(phrase);

                var path = Path.Combine(_hostingEnvironment.WebRootPath, @"images\Eco.jpg");

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path);
                image.ScaleAbsolute(145f, 70f);
                image.SetAbsolutePosition(70f, 345f);
                image.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                //image.SpacingAfter = 40;
                document.Add(image);


                string Phone = @"Phone:021-34829161/63";

                List <iTextSharp.text.Paragraph> paragraph = new List <iTextSharp.text.Paragraph>();


                iTextSharp.text.Paragraph phone = new iTextSharp.text.Paragraph();

                phone.SpacingBefore = 50;
                phone.SpacingAfter  = 1;
                phone.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                phone.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                phone.Add(Phone);
                document.Add(phone);

                string Email = @"Email:[email protected]";
                iTextSharp.text.Paragraph email = new iTextSharp.text.Paragraph();

                email.SpacingBefore = 1;
                email.SpacingAfter  = 1;
                email.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                email.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                email.Add(Email);
                document.Add(email);

                string Web = @"Web: www.ecoservices.com.pk";
                iTextSharp.text.Paragraph web = new iTextSharp.text.Paragraph();

                web.SpacingBefore = 1;
                web.SpacingAfter  = 30;
                web.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                web.Font          = FontFactory.GetFont(FontFactory.TIMES, 16F, BaseColor.DarkGray);
                web.Add(Web);
                document.Add(web);



                /*  PdfContentByte cb = writer.DirectContent;
                 *                 var Rectangular = new Rectangle(7, 420, 280, 25); //left width,top height,right width,bottom height
                 *                  Rectangular.BorderWidthLeft = 1.1f;
                 *                  Rectangular.BorderWidthRight = 1.1f;
                 *                  Rectangular.BorderWidthTop = 1.1f;
                 *                  Rectangular.BorderWidthBottom = 1.1f;*/

                string Station = stationName;
                iTextSharp.text.Paragraph station = new iTextSharp.text.Paragraph();

                station.SpacingBefore = 10;
                station.SpacingAfter  = 25;
                station.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                station.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                station.Add(Station);
                document.Add(station);

                int StationNo = Sno;
                iTextSharp.text.Paragraph stationno = new iTextSharp.text.Paragraph();

                stationno.SpacingBefore = 10;
                stationno.SpacingAfter  = 10;
                stationno.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                stationno.Font          = FontFactory.GetFont(FontFactory.TIMES_BOLD, 60f, BaseColor.Black);
                stationno.Add("" + Sno);
                document.Add(stationno);



                string LocationName = locationName;
                iTextSharp.text.Paragraph locationname = new iTextSharp.text.Paragraph();

                locationname.SpacingBefore = 10;
                locationname.SpacingAfter  = 1;
                locationname.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                locationname.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                locationname.Add(LocationName);
                document.Add(locationname);

                BarcodeQRCode barcodeQRCode = new BarcodeQRCode(code, 1000, 1000, null);
                Image         codeQrImage   = barcodeQRCode.GetImage();
                codeQrImage.ScaleAbsolute(95, 95);
                codeQrImage.Alignment = iTextSharp.text.Element.ALIGN_LEFT;
                codeQrImage.Alignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                document.Add(codeQrImage);

                /*    cb.Rectangle(Rectangular);
                 *  cb.Stroke();
                 *
                 *
                 *  cb.SetLineWidth(1);
                 *  cb.Rectangle(15, 230, 140, 50); //left width,top height,right width,bottom height
                 *  cb.BeginText();
                 *  BaseFont f_cn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 *  cb.SetFontAndSize(f_cn, 18);
                 *  cb.SetTextMatrix(28, 250);
                 *  cb.ShowText("StationID:  " + Sno);
                 *  cb.EndText();
                 *
                 *  cb.Rectangle(15, 160, 140, 50);
                 *  cb.SetLineWidth(3);
                 *  cb.Stroke();
                 *  cb.BeginText();
                 *  BaseFont f_cnn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 *  cb.SetFontAndSize(f_cnn, 18);
                 *  cb.SetTextMatrix(22, 180);
                 *  cb.ShowText("Station Name:  " + stationName);
                 *  cb.EndText();
                 *
                 *
                 *  cb.Rectangle(15, 90, 140, 50);
                 *  cb.SetLineWidth(3);
                 *  cb.Stroke();
                 *  cb.BeginText();
                 *  BaseFont f_cnnn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 *  cb.SetFontAndSize(f_cnnn, 18);
                 *  cb.SetTextMatrix(19, 110);
                 *  cb.ShowText("Location Name: " + locationName);
                 *  cb.EndText();
                 */


                // Page 2

                document.NewPage();


                iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(path);
                image1.ScaleAbsolute(75f, 75f);
                image1.SetAbsolutePosition(30f, 345f);
                image1.Alignment = iTextSharp.text.Element.ALIGN_LEFT;
                document.Add(image);

                string Phone1 = @"Phone:021-34829161/63";

                List <iTextSharp.text.Paragraph> paragraph1 = new List <iTextSharp.text.Paragraph>();


                iTextSharp.text.Paragraph phone1 = new iTextSharp.text.Paragraph();

                phone1.SpacingBefore = 50;
                phone1.SpacingAfter  = 1;
                phone1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                phone1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                phone1.Add(Phone1);
                document.Add(phone1);

                string Email1 = @"Email:[email protected]";
                iTextSharp.text.Paragraph email1 = new iTextSharp.text.Paragraph();

                email1.SpacingBefore = 1;
                email1.SpacingAfter  = 1;
                email1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                email1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                email1.Add(Email1);
                document.Add(email1);

                string Web1 = @"Web: www.ecoservices.com.pk";
                iTextSharp.text.Paragraph web1 = new iTextSharp.text.Paragraph();

                web1.SpacingBefore = 1;
                web1.SpacingAfter  = 30;
                web1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                web1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16F, BaseColor.DarkGray);
                web1.Add(Web1);
                document.Add(web1);



                /*  PdfContentByte cb = writer.DirectContent;
                 *                 var Rectangular = new Rectangle(7, 420, 280, 25); //left width,top height,right width,bottom height
                 *                  Rectangular.BorderWidthLeft = 1.1f;
                 *                  Rectangular.BorderWidthRight = 1.1f;
                 *                  Rectangular.BorderWidthTop = 1.1f;
                 *                  Rectangular.BorderWidthBottom = 1.1f;*/

                string Station1 = stationName;
                iTextSharp.text.Paragraph station1 = new iTextSharp.text.Paragraph();

                station1.SpacingBefore = 10;
                station1.SpacingAfter  = 25;
                station1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                station1.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                station1.Add(Station1);
                document.Add(station1);

                int StationNo1 = Sno;
                iTextSharp.text.Paragraph stationno1 = new iTextSharp.text.Paragraph();

                stationno1.SpacingBefore = 10;
                stationno1.SpacingAfter  = 10;
                stationno1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                stationno1.Font          = FontFactory.GetFont(FontFactory.TIMES_BOLD, 60f, BaseColor.Black);
                stationno1.Add("" + Sno);
                document.Add(stationno1);



                string LocationName1 = locationName;
                iTextSharp.text.Paragraph locationname1 = new iTextSharp.text.Paragraph();

                locationname1.SpacingBefore = 10;
                locationname1.SpacingAfter  = 1;
                locationname1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                locationname1.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                locationname1.Add(LocationName1);
                document.Add(locationname1);

                var path1 = Path.Combine(_hostingEnvironment.WebRootPath, @"images\Caution.png");

                iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance(path1);
                image2.ScaleAbsolute(165f, 120f);
                image2.SetAbsolutePosition(60f, 30f);
                image2.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                //image.SpacingAfter = 40;
                document.Add(image2);

                //  PdfContentByte cb1 = writer.DirectContent;

                /*  var Rectangular1 = new Rectangle(7, 420, 280, 25); //left width,top height,right width,bottom height
                 * Rectangular.BorderWidthLeft = 1.1f;
                 * Rectangular.BorderWidthRight = 1.1f;
                 * Rectangular.BorderWidthTop = 1.1f;
                 * Rectangular.BorderWidthBottom = 1.1f;*/

                /*   cb.Rectangle(Rectangular);
                 * cb.Stroke();
                 *
                 *
                 * cb.SetLineWidth(1);
                 * cb.Rectangle(45, 230, 190, 50); //left width,top height,right width,bottom height
                 * cb.BeginText();
                 * BaseFont f_cn1 = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 * cb.SetFontAndSize(f_cn, 10);
                 * cb.SetTextMatrix(95, 250);
                 * cb.ShowText("StationID:  " + Sno);
                 * cb.EndText();
                 *
                 * cb.Rectangle(45, 160, 190, 50);
                 * cb.SetLineWidth(3);
                 * cb.Stroke();
                 * cb.BeginText();
                 * BaseFont f_cnn1 = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 * cb.SetFontAndSize(f_cnn, 10);
                 * cb.SetTextMatrix(85, 180);
                 * cb.ShowText("Station Name:  " + stationName);
                 * cb.EndText();
                 *
                 *
                 * cb.Rectangle(45, 90, 190, 50);
                 * cb.SetLineWidth(3);
                 * cb.Stroke();
                 * cb.BeginText();
                 * BaseFont f_cnnn1 = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                 * cb.SetFontAndSize(f_cnnn, 10);
                 * cb.SetTextMatrix(85, 110);
                 * cb.ShowText("Location Name: " + locationName);
                 * cb.EndText();
                 *
                 */
                document.Close();
                byte[] bytes = memoryStream.ToArray();
                memoryStream.Close();
                return(bytes);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        private void Relatorio_Click(object sender, RoutedEventArgs e)
        {
            Conexao con = new Conexao();

            Document doc = new Document(PageSize.A4);           //tipo da página

            doc.SetMargins(40, 40, 40, 80);                     //margens da página
            string caminho = @"C:\Relatorio\" + "RelatórioVazãoeNível.pdf";

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(caminho, FileMode.Create));

            doc.Open();

            try
            {
                con.conectar();

                string           sqlite = "SELECT Vertedor, Vazao1, Vazao2, CargaHidraulica, Setpoint FROM AtualizacaoVariaveis";
                var              cmd    = new SQLiteCommand(sqlite, con.conn2);
                SQLiteDataReader rdr    = cmd.ExecuteReader();

                string           sqlite2 = "SELECT Nome FROM Login";
                var              cmd2    = new SQLiteCommand(sqlite2, con.conn);
                SQLiteDataReader rdr2    = cmd2.ExecuteReader();

                rdr.Read();
                rdr2.Read();

                Paragraph titulo = new Paragraph();
                titulo.Font      = new Font(Font.FontFamily.COURIER, 16);       //fonte e tamanho do título
                titulo.Alignment = Element.ALIGN_CENTER;                        // alinhamento do título no centro
                titulo.Add("Sistema de Supervisão e Controle - Relatório\n\n"); //título
                doc.Add(titulo);                                                //adiciona o parágrafo no documento


                Paragraph Usuario = new Paragraph("", new Font(Font.NORMAL, 12));
                string    login   = "******" + " " + rdr2["Nome"].ToString() + "\n";
                Usuario.Add(login);
                doc.Add(Usuario);

                Paragraph TextoTabela2 = new Paragraph("", new Font(Font.NORMAL, 12));
                string    textotabela2 = "Tabela 1: Contém as leituras das variáveis relacionadas ao sistema de controle.\n\n";
                TextoTabela2.Add(textotabela2);
                doc.Add(TextoTabela2);

                PdfPTable tabela2 = new PdfPTable(2); //número de colunas

                tabela2.AddCell(" ");
                tabela2.AddCell("Último Valor Lido");

                tabela2.AddCell("Vazão - Leitura 1");
                tabela2.AddCell(rdr["Vazao1"].ToString() + " " + "m³/s");

                tabela2.AddCell("Vazão - Leitura 2");
                tabela2.AddCell(rdr["Vazao2"].ToString() + " " + "litros/s");

                tabela2.AddCell("Vertedor");
                tabela2.AddCell(rdr["Vertedor"].ToString());

                tabela2.AddCell("Carga Hidraulica");
                tabela2.AddCell(rdr["CargaHidraulica"].ToString() + " " + "cm");

                tabela2.AddCell("Setpoint");
                tabela2.AddCell(rdr["Setpoint"].ToString());

                doc.Add(tabela2);


                con.desconectar();
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message.ToString(), "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
            }


            doc.Close();
        }
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController {
                UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false
            };
            var Response = context.HttpContext.Response;

            IEnumerable <MailingController.MailingInfo> q = null;

            switch (format)
            {
            case "Individual":
                q = ctl.FetchIndividualList(sort, id);
                break;

            case "GroupAddress":
                q = ctl.GroupByAddress(sort, id);
                break;

            case "Family":
            case "FamilyMembers":
                q = ctl.FetchFamilyList(sort, id);
                break;

            case "ParentsOf":
                q = ctl.FetchParentsOfList(sort, id);
                break;

            case "CouplesEither":
                q = ctl.FetchCouplesEitherList(sort, id);
                break;

            case "CouplesBoth":
                q = ctl.FetchCouplesBothList(sort, id);
                break;

            default:
                Response.Write("unknown format");
                return;
            }
            if (!q.Any())
            {
                Response.Write("no data found");
                return;
            }
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);

            document.SetMargins(50f, 36f, 32f, 36f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);

            document.Open();
            dc = w.DirectContent;

            var cols = new float[] { W, W, W - 25f };
            var t    = new PdfPTable(cols);

            t.SetTotalWidth(cols);
            t.HorizontalAlignment           = Element.ALIGN_CENTER;
            t.LockedWidth                   = true;
            t.DefaultCell.Border            = PdfPCell.NO_BORDER;
            t.DefaultCell.FixedHeight       = H;
            t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
            t.DefaultCell.PaddingLeft       = 8f;
            t.DefaultCell.PaddingRight      = 8f;
            t.DefaultCell.SetLeading(2.0f, 1f);

            if (skip > 0)
            {
                var blankCell = new PdfPCell(t.DefaultCell);

                for (int iX = 0; iX < skip; iX++)
                {
                    t.AddCell(blankCell);
                }
            }

            foreach (var m in q)
            {
                var c  = new PdfPCell(t.DefaultCell);
                var ph = new Paragraph();
                if (format == "GroupAddress")
                {
                    ph.AddLine(m.LabelName + " " + m.LastName, font);
                }
                else if ((format == "CouplesEither" || format == "CouplesBoth") && m.CoupleName.HasValue())
                {
                    ph.AddLine(m.CoupleName, font);
                }
                else
                {
                    ph.AddLine(m.LabelName, font);
                }
                if (m.MailingAddress.HasValue())
                {
                    ph.AddLine(m.MailingAddress.Trim(), font);
                }
                else
                {
                    ph.AddLine(m.Address, font);
                    ph.AddLine(m.Address2, font);
                    ph.AddLine(m.CSZ, font);
                }
                c.AddElement(ph);
                if (usephone)
                {
                    var phone = Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "));
                    var p     = new Paragraph();
                    c.PaddingRight = 7f;
                    p.Alignment    = Element.ALIGN_RIGHT;
                    p.Add(new Chunk(phone, smfont));
                    p.ExtraParagraphSpace = 0f;
                    c.AddElement(p);
                }
                t.AddCell(c);
            }
            t.CompleteRow();
            document.Add(t);

            document.Close();
        }
Beispiel #54
0
        public static byte[] DownloadAllPdf(List <DownloadPdfDto> downloadAllPdf, string locationName, IHostingEnvironment _hostingEnvironment)
        {
            try
            {
                var document = new iTextSharp.text.Document(new Rectangle(288f, 432f));
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
                byte[]    bytes;
                PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
                var       path   = Path.Combine(_hostingEnvironment.WebRootPath, @"images\Eco.jpg");
                foreach (var s in downloadAllPdf)
                {
                    document.Open();
                    Phrase phrase = new Phrase();
                    document.Add(phrase);


                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path);
                    image.ScaleAbsolute(145f, 70f);
                    image.SetAbsolutePosition(70f, 345f);
                    image.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                    document.Add(image);


                    string Phone = @"Phone:021-34829161/63";

                    List <iTextSharp.text.Paragraph> paragraph = new List <iTextSharp.text.Paragraph>();


                    iTextSharp.text.Paragraph phone = new iTextSharp.text.Paragraph();

                    phone.SpacingBefore = 50;
                    phone.SpacingAfter  = 1;
                    phone.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    phone.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                    phone.Add(Phone);
                    document.Add(phone);

                    string Email = @"Email:[email protected]";
                    iTextSharp.text.Paragraph email = new iTextSharp.text.Paragraph();

                    email.SpacingBefore = 1;
                    email.SpacingAfter  = 1;
                    email.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    email.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                    email.Add(Email);
                    document.Add(email);

                    string Web = @"Web: www.ecoservices.com.pk";
                    iTextSharp.text.Paragraph web = new iTextSharp.text.Paragraph();

                    web.SpacingBefore = 1;
                    web.SpacingAfter  = 30;
                    web.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    web.Font          = FontFactory.GetFont(FontFactory.TIMES, 16F, BaseColor.DarkGray);
                    web.Add(Web);
                    document.Add(web);

                    string Station = s.StationName;
                    iTextSharp.text.Paragraph station = new iTextSharp.text.Paragraph();

                    station.SpacingBefore = 10;
                    station.SpacingAfter  = 25;
                    station.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    station.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                    station.Add(Station);
                    document.Add(station);

                    int StationNo = s.SNo;
                    iTextSharp.text.Paragraph stationno = new iTextSharp.text.Paragraph();

                    stationno.SpacingBefore = 10;
                    stationno.SpacingAfter  = 10;
                    stationno.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    stationno.Font          = FontFactory.GetFont(FontFactory.TIMES_BOLD, 60f, BaseColor.Black);
                    stationno.Add("" + s.SNo);
                    document.Add(stationno);



                    string LocationName = s.LocationName;
                    iTextSharp.text.Paragraph locationname = new iTextSharp.text.Paragraph();

                    locationname.SpacingBefore = 10;
                    locationname.SpacingAfter  = 1;
                    locationname.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    locationname.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                    locationname.Add(LocationName);
                    document.Add(locationname);

                    BarcodeQRCode barcodeQRCode = new BarcodeQRCode(s.Code, 1000, 1000, null);
                    Image         codeQrImage   = barcodeQRCode.GetImage();
                    codeQrImage.ScaleAbsolute(95, 95);
                    codeQrImage.Alignment = iTextSharp.text.Element.ALIGN_LEFT;
                    codeQrImage.Alignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                    document.Add(codeQrImage);

                    // Page 2

                    document.NewPage();


                    iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(path);
                    image1.ScaleAbsolute(75f, 75f);
                    image1.SetAbsolutePosition(30f, 345f);
                    image1.Alignment = iTextSharp.text.Element.ALIGN_LEFT;
                    document.Add(image);

                    string Phone1 = @"Phone:021-34829161/63";

                    List <iTextSharp.text.Paragraph> paragraph1 = new List <iTextSharp.text.Paragraph>();


                    iTextSharp.text.Paragraph phone1 = new iTextSharp.text.Paragraph();

                    phone1.SpacingBefore = 50;
                    phone1.SpacingAfter  = 1;
                    phone1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    phone1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                    phone1.Add(Phone1);
                    document.Add(phone1);

                    string Email1 = @"Email:[email protected]";
                    iTextSharp.text.Paragraph email1 = new iTextSharp.text.Paragraph();

                    email1.SpacingBefore = 1;
                    email1.SpacingAfter  = 1;
                    email1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    email1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16f, BaseColor.DarkGray);
                    email1.Add(Email1);
                    document.Add(email1);

                    string Web1 = @"Web: www.ecoservices.com.pk";
                    iTextSharp.text.Paragraph web1 = new iTextSharp.text.Paragraph();

                    web1.SpacingBefore = 1;
                    web1.SpacingAfter  = 30;
                    web1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    web1.Font          = FontFactory.GetFont(FontFactory.TIMES, 16F, BaseColor.DarkGray);
                    web1.Add(Web1);
                    document.Add(web1);



                    /*  PdfContentByte cb = writer.DirectContent;
                     *                 var Rectangular = new Rectangle(7, 420, 280, 25); //left width,top height,right width,bottom height
                     *                  Rectangular.BorderWidthLeft = 1.1f;
                     *                  Rectangular.BorderWidthRight = 1.1f;
                     *                  Rectangular.BorderWidthTop = 1.1f;
                     *                  Rectangular.BorderWidthBottom = 1.1f;*/

                    string Station1 = s.StationName;
                    iTextSharp.text.Paragraph station1 = new iTextSharp.text.Paragraph();

                    station1.SpacingBefore = 10;
                    station1.SpacingAfter  = 25;
                    station1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    station1.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                    station1.Add(Station1);
                    document.Add(station1);

                    int StationNo1 = s.SNo;
                    iTextSharp.text.Paragraph stationno1 = new iTextSharp.text.Paragraph();

                    stationno1.SpacingBefore = 10;
                    stationno1.SpacingAfter  = 10;
                    stationno1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    stationno1.Font          = FontFactory.GetFont(FontFactory.TIMES_BOLD, 60f, BaseColor.Black);
                    stationno1.Add("" + s.SNo);
                    document.Add(stationno1);



                    string LocationName1 = locationName;
                    iTextSharp.text.Paragraph locationname1 = new iTextSharp.text.Paragraph();

                    locationname1.SpacingBefore = 10;
                    locationname1.SpacingAfter  = 1;
                    locationname1.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;
                    locationname1.Font          = FontFactory.GetFont(FontFactory.TIMES, 20f, BaseColor.Black);
                    locationname1.Add(LocationName1);
                    document.Add(locationname1);

                    var path1 = Path.Combine(_hostingEnvironment.WebRootPath, @"images\Caution.png");

                    iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance(path1);
                    image2.ScaleAbsolute(165f, 120f);
                    image2.SetAbsolutePosition(60f, 30f);
                    image2.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                    //image.SpacingAfter = 40;
                    document.Add(image2);
                    document.NewPage();
                }
                document.Close();
                bytes = memoryStream.ToArray();
                memoryStream.Close();
                return(bytes);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #55
0
        void ExportDataTableToPdf(Case myobject, String strPdfPath)
        {
            System.IO.FileStream fs       = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4);
            document.SetMargins(20, 20, 20, 20);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance("D:/studdy/7th Semester/SDT/Semester Project/Lawyer Diary/Lawyer Diary/images/main.png");
            imageLogo.ScaleToFit(400, 80);
            imageLogo.SpacingAfter = 1f;
            document.Add(imageLogo);

            // Chamber Name
            BaseFont bfnChamber = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntChamber = new Font(bfnChamber, 20, 1, BaseColor.BLACK);

            iTextSharp.text.Paragraph prgCompany = new iTextSharp.text.Paragraph();
            prgCompany.Alignment = Element.ALIGN_CENTER;
            prgCompany.Add(new Chunk("Gondal Law Chamber", fntChamber));
            document.Add(prgCompany);

            //Chamber details
            iTextSharp.text.Paragraph prgDetails = new iTextSharp.text.Paragraph();
            BaseFont btnDetails = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntDetails = new Font(btnDetails, 13, 1, BaseColor.BLACK);

            prgDetails.Alignment = Element.ALIGN_CENTER;
            prgDetails.Add(new Chunk("Main Street near Library, Kchehri Rawalpindi", fntDetails));
            prgDetails.Add(new Chunk("\nPhone 0312-5197653", fntDetails));
            document.Add(prgDetails);

            //Client Details
            // fonts for Details
            BaseFont btnBOld  = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntbold  = new Font(btnBOld, 12, 1, BaseColor.BLACK);
            BaseFont btnsoft  = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntsoft  = new Font(btnsoft, 12, 2, BaseColor.DARK_GRAY);
            BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntHead  = new Font(bfntHead, 20, 1, BaseColor.DARK_GRAY);

            iTextSharp.text.Paragraph prgClientInfo = new iTextSharp.text.Paragraph();
            prgClientInfo.Alignment = Element.ALIGN_LEFT;
            prgClientInfo.Add(new Chunk("\nClient Name: ", fntbold));
            prgClientInfo.Add(new Chunk("" + selectedForPrintClient.ClientName, fntsoft));
            //prgInvoiceno.Add(new Chunk("                                                                 Customer Name:", fntbold));
            //prgInvoiceno.Add(new Chunk("" + myobject.CustomerName, fntsoft));
            document.Add(prgClientInfo);

            //Add a line seperation
            iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(new Chunk
                                                                            (new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F,
                                                                                                                        iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
            document.Add(p);
            //Add line break
            document.Add(new Chunk("\n", fntHead));
            DataTable tableData = caseDataTable();
            PdfPTable table     = new PdfPTable(tableData.Columns.Count);

            for (int i = 0; i < tableData.Rows.Count; i++)
            {
                for (int j = 0; j < tableData.Columns.Count; j++)
                {
                    table.AddCell(tableData.Rows[i][j].ToString());
                }
            }
            document.Add(table);
            document.Add(new Chunk("\n\nCase Description ", fntbold));
            iTextSharp.text.Paragraph desc = new iTextSharp.text.Paragraph("               " + selectedForPrint.CaseDiscription);
            desc.Alignment = Element.ALIGN_JUSTIFIED;
            document.Add(desc);

            document.Close();
            writer.Close();
            fs.Close();
        }
Beispiel #56
0
        private void GenerarReporteAeronave()
        {
            var documento = new Document();

            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "PDF (*.pdf)|*.pdf";
            if (save.ShowDialog() == false)
            {
                return;
            }

            string path = save.FileName;

            try
            {
                PdfWriter.GetInstance(documento, new FileStream(path, FileMode.Create));
            }
            catch (IOException)
            {
                MessageBox.Show("Hubo un error al tratar de guardar el archivo.");
                return;
            }

            PdfPTable pdf = new PdfPTable(6);

            Aeronave aero = null;

            try
            {
                aero = Aeronave.GetAeronave(Matricula.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Error al conseguir la aeronave. ¿La matrícula ingresada existe?");
                return;
            }



            pdf.AddCell("Numero de vuelo");
            pdf.AddCell("Condicion de vuelo");
            pdf.AddCell("Tiempo de vuelo");
            pdf.AddCell("Origen de vuelo");
            pdf.AddCell("Destino de vuelo");
            pdf.AddCell("Matricula de aeronave");

            List <Vuelo> lista = Vuelo.getAllVuelosFromAeronave(aero.Matricula);

            foreach (var item in lista)
            {
                pdf.AddCell(item.NumeroVuelo.ToString());
                pdf.AddCell(item.CondicionVuelo.ToString());
                pdf.AddCell(item.TotalTiempoVuelo.ToString());
                pdf.AddCell(item.OrigenVuelo.ToString());
                pdf.AddCell(item.DestinoVuelo.ToString());
                pdf.AddCell(item.Aeronave.Matricula.ToString());
            }

            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph();

            par.Add("Lista de vuelos para la aeronave cuya matrícula es " + aero.Matricula);

            documento.Open();
            documento.Add(par);
            documento.Add(Chunk.NEWLINE);
            documento.Add(Chunk.NEWLINE);
            documento.Add(pdf);
            documento.Close();
            MessageBox.Show("Reporte correctamente guardado.");
        }
Beispiel #57
0
        public void CreateTaggedPdf20() {
            InitializeDocument("20");

            Paragraph paragraph = new Paragraph();
            paragraph.Font.Color = BaseColor.RED;
            Chunk c = new Chunk("Hello ");
            paragraph.Add(c);
            c = new Chunk("  world\n\n");
            paragraph.Add(c);

            ColumnText columnText = new ColumnText(writer.DirectContent);
            columnText.SetSimpleColumn(36, 36, 250, 800);
            columnText.AddElement(paragraph);
            columnText.Go();

            PdfTemplate template = writer.DirectContent.CreateTemplate(PageSize.A4.Width, PageSize.A4.Height);
            writer.DirectContent.AddTemplate(template, 0, 0, true);

            columnText = new ColumnText(template);
            columnText.SetSimpleColumn(36, 36, 250, 750);
            columnText.AddText(new Phrase(new Chunk("Hello word \n")));
            columnText.Go();

            document.NewPage();

            paragraph = new Paragraph();
            paragraph.Font.Color = BaseColor.RED;
            c = new Chunk("Hello ");
            paragraph.Add(c);
            c = new Chunk("  world\n");
            paragraph.Add(c);

            columnText = new ColumnText(template);
            columnText.SetSimpleColumn(36, 36, 250, 700);
            columnText.AddElement(paragraph);
            columnText.Go();

            template = writer.DirectContent.CreateTemplate(PageSize.A4.Width, PageSize.A4.Height);
            writer.DirectContent.AddTemplate(template, 0, 0, true);

            paragraph = new Paragraph();
            paragraph.Font.Color = BaseColor.GREEN;
            c = new Chunk("Hello ");
            paragraph.Add(c);
            c = new Chunk("  world\n");
            paragraph.Add(c);

            columnText = new ColumnText(template);
            columnText.SetSimpleColumn(36, 36, 250, 800);
            columnText.AddElement(paragraph);
            columnText.Go();

            paragraph = new Paragraph();
            paragraph.Font.Color = BaseColor.BLUE;
            c = new Chunk("Hello ");
            paragraph.Add(c);
            c = new Chunk("  world\n");
            paragraph.Add(c);

            template = writer.DirectContent.CreateTemplate(PageSize.A4.Width, PageSize.A4.Height);

            columnText = new ColumnText(template);
            columnText.SetSimpleColumn(36, 36, 250, 650);
            columnText.AddElement(paragraph);
            columnText.Go();

            writer.DirectContent.AddTemplate(template, 0, 100);

            writer.DirectContent.AddTemplate(template, 0, 50);

            writer.DirectContent.AddTemplate(template, 0, 0);

            document.Close();
            CompareResults("20");
        }
Beispiel #58
0
        private void GenerarReporteUsuario()
        {
            var documento = new Document();

            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "PDF (*.pdf)|*.pdf";
            if (save.ShowDialog() == false)
            {
                return;
            }

            string path = save.FileName;

            try
            {
                PdfWriter.GetInstance(documento, new FileStream(path, FileMode.Create));
            }catch (IOException)
            {
                MessageBox.Show("Hubo un error al tratar de guardar el archivo.");
                return;
            }

            PdfPTable pdf = new PdfPTable(6);

            Usuario user = null;

            try
            {
                user = Usuario.getUsuarioDeBD(Usuario.getRutFromString(RUT.Text));
            }
            catch (Exception)
            {
                MessageBox.Show("Error al conseguir el usuario. ¿El rut ingresado existe?");
                return;
            }


            pdf.AddCell("Numero de vuelo");
            pdf.AddCell("Condicion de vuelo");
            pdf.AddCell("Tiempo de vuelo");
            pdf.AddCell("Origen de vuelo");
            pdf.AddCell("Destino de vuelo");
            pdf.AddCell("Matricula de aeronave");

            List <Vuelo> lista = Vuelo.getAllVuelosFromUsuario(user.Rut);

            foreach (var item in lista)
            {
                pdf.AddCell(item.NumeroVuelo.ToString());
                pdf.AddCell(item.CondicionVuelo.ToString());
                pdf.AddCell(item.TotalTiempoVuelo.ToString());
                pdf.AddCell(item.OrigenVuelo.ToString());
                pdf.AddCell(item.DestinoVuelo.ToString());
                pdf.AddCell(item.Aeronave.Matricula.ToString());
            }

            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph();

            par.Add("Lista de vuelos para el usuario con RUT: " + user.Rut + ", cuyo nombre completo es " + user.Nombre + " " + user.Apellido);

            documento.Open();
            documento.Add(par);
            documento.Add(Chunk.NEWLINE);
            documento.Add(Chunk.NEWLINE);
            documento.Add(pdf);
            documento.Close();
            MessageBox.Show("Reporte correctamente guardado.");
        }
Beispiel #59
0
     /**
      * Applies the tab stops of the p tag on its {@link TabbedChunk} elements.
      *
      * @param currentContent containing the elements inside the p tag.
      * @param p paragraph to which the tabbed chunks will be added.
      * @param value the value of style "tab-stops".
      */
     private void AddTabStopsContent(IList<IElement> currentContent, Paragraph p, String value) {
         IList<Chunk> tabs = new List<Chunk>();
         String[] alignAndWidth = value.Split(' ');
         float tabWidth = 0;
         for (int i = 0 , j = 1; j < alignAndWidth.Length ; i+=2, j+=2) {
             tabWidth += CssUtils.GetInstance().ParsePxInCmMmPcToPt(alignAndWidth[j]);
             TabbedChunk tab = new TabbedChunk(new VerticalPositionMark(), tabWidth, true, alignAndWidth[i]);
             tabs.Add(tab);
         }
         int tabsPerRow = tabs.Count;
         int currentTab = 0;
         foreach (IElement e in currentContent) {
             if (e is TabbedChunk) {
                 if (currentTab == tabsPerRow) {
                     currentTab = 0;
                 }
                 if (((TabbedChunk) e).TabCount != 0 /* == 1*/) {
                     p.Add(new Chunk(tabs[currentTab]));
                     p.Add(new Chunk((TabbedChunk) e));
                     ++currentTab;
 //              } else { // wat doet een tabCount van groter dan 1? sla een tab over of count * tabWidth?
 //                  int widthMultiplier = ((TabbedChunk) e).GetTabCount();
                 }
             }
         }
     }
        private void crtaj_fakturu()
        {
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate());
            string date_time             = (DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second).ToString();

            try
            {
                string dir_mb = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MobileTown_racuni";

                if (Directory.Exists(dir_mb))
                {
                    PdfWriter.GetInstance(doc, new FileStream(dir_mb + "\\izvestaj" + date_time + ".pdf", FileMode.Create));
                    doc.Open();
                }
                else
                {
                    Directory.CreateDirectory(dir_mb);
                    PdfWriter.GetInstance(doc, new FileStream(dir_mb + "\\izvestaj" + date_time + ".pdf", FileMode.Create));
                    doc.Open();
                }

                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("Mobile Town");
                title.Alignment = Element.ALIGN_CENTER;
                title.Font.Size = 32;
                doc.Add(title);

                iTextSharp.text.Paragraph podaci;
                podaci = new iTextSharp.text.Paragraph("\n");
                podaci.Add("\n");
                podaci.Add("           Datum:" + DateTime.Now.ToString("       dd-MM-yyyy HH-mm"));
                podaci.Add("\n");
                podaci.Add("           " + izvestaj);
                podaci.Font.Size = 14;
                doc.Add(podaci);

                iTextSharp.text.Paragraph razmak = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak);

                PdfPTable table = new PdfPTable(4);
                table.AddCell("id Racuna");
                table.AddCell("Artikli");
                table.AddCell("Datum izdavanja");
                table.AddCell("Iznos");
                double suma = 0;
                foreach (DataGridViewRow datarow in dataGridView1.Rows)
                {
                    table.AddCell(datarow.Cells[0].Value.ToString());
                    table.AddCell(datarow.Cells[3].Value.ToString());
                    table.AddCell(datarow.Cells[2].Value.ToString());
                    table.AddCell(datarow.Cells[4].Value.ToString());

                    suma += double.Parse(datarow.Cells[4].Value.ToString());
                }

                doc.Add(table);

                iTextSharp.text.Paragraph razmak1 = new iTextSharp.text.Paragraph("\n");
                doc.Add(razmak1);

                PdfPTable table_konacno = new PdfPTable(2);
                table_konacno.AddCell("Ukupno");
                table_konacno.AddCell("PDV(20%) Ukupno");

                table_konacno.AddCell(suma.ToString());
                table_konacno.AddCell((suma * 0.2).ToString());
                doc.Add(table_konacno);

                System.Diagnostics.Process.Start(dir_mb + "\\izvestaj" + date_time + ".pdf");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                doc.Close();
            }
        }