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

Sets the style using a String containing one of more of the following values: normal, bold, italic, underline, strike.
public SetStyle ( String style ) : void
style String A String representing a certain style.
Результат void
Пример #1
0
        private static void addCell(PdfPTable table, string text, int rowspan, string fontStyle)
        {
            BaseFont bfTimes = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);

            iTextSharp.text.Font fuente = new iTextSharp.text.Font(bfTimes, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

            if (fontStyle.ToLower() == "n")
            {
                fuente.SetStyle(Font.NORMAL);
            }
            else if (fontStyle.ToLower() == "b")
            {
                fuente.SetStyle(Font.BOLD);
            }
            else if (fontStyle.ToLower() == "i")
            {
                fuente.SetStyle(Font.ITALIC);
            }

            PdfPCell cell = new PdfPCell(new Phrase(text, fuente));

            cell.BorderWidth         = 0;
            cell.Rowspan             = rowspan;
            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(cell);
        }
Пример #2
0
        private static IT.Font GetFormattedFont(Font font)
        {
            IT.Font iTextFont = new IT.Font();

            //Return default font if font style is not available.
            if (font == null)
            {
                return new IT.Font();
            }

            foreach (var format in font.Formats)
            {
                switch (format)
                {
                    case FontFormats.Bold:
                        iTextFont.SetStyle(IT.Font.BOLD);
                        break;
                    case FontFormats.Italic:
                        iTextFont.SetStyle(IT.Font.ITALIC);
                        break;
                    case FontFormats.Underlined:
                        iTextFont.SetStyle(IT.Font.UNDERLINE);
                        break;
                    default:
                        break;
                }
            }
            return iTextFont;
        }
Пример #3
0
        /// <summary>
        /// Converts a report style to a new font definition.
        /// </summary>
        /// <param name="reportStyle">The report style.</param>
        /// <param name="fontFamily">Name of the font.</param>
        /// <returns>The font.</returns>
        public static Font ConvertStyleToFont(ReportStyle reportStyle, string fontFamily)
        {
            var font = new Font();

            font.SetFamily(fontFamily);

            if (reportStyle.Underline)
            {
                font.SetStyle(Font.UNDERLINE);
            }
            else if (reportStyle.Bold || reportStyle.Italic)
            {
                if (reportStyle.Bold && reportStyle.Italic)
                {
                    font.SetStyle(Font.BOLDITALIC);
                }
                else if (reportStyle.Bold)
                {
                    font.SetStyle(Font.BOLD);
                }
                else
                {
                    font.SetStyle(Font.ITALIC);
                }
            }

            font.Size = reportStyle.FontSize;
            font.SetColor(reportStyle.ForeColor.R, reportStyle.ForeColor.G, reportStyle.ForeColor.B);
            return(font);
        }
Пример #4
0
        public void AddFile(string fileName, int chapterNum)
        {
            var onlyFileName = Utils.GetFileNameFromPath(fileName);
            var reader       = new PdfReader(fileName);

            iTextSharp.text.Font f1 = new iTextSharp.text.Font();
            f1.SetStyle(iTextSharp.text.Font.BOLD);
            Paragraph cTitle  = new Paragraph(onlyFileName, f1);
            Chapter   chapter = new Chapter(cTitle, chapterNum);

            //Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", f1);
            //Section section = chapter.AddSection(sTitle, 1);
            _document.Add(chapter);
            _document.NewPage();

            for (var i = 1; i <= reader.NumberOfPages; i++)
            {
                var size = reader.GetPageSizeWithRotation(i);
                _document.SetPageSize(size);
                _document.NewPage();

                var page = _pdfCopy.GetImportedPage(reader, i);
                _pdfCopy.AddPage(page);
            }

            //iTextSharp.text.Font f1 = new iTextSharp.text.Font();
            //f1.SetStyle(iTextSharp.text.Font.BOLD);
            //Paragraph cTitle = new Paragraph("aaaaaaaaaaaa", f1);
            //Chapter chapter = new Chapter(cTitle, 1);
            //_pdfCopy.Add(chapter);

            reader.Close();
        }
Пример #5
0
        private const float milimetro = 2.83465f; // 1 milímetro equivale a 2.83465 puntos.
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            PdfPTable tCabecera      = new PdfPTable(3);                         // Tabla para poner la información en la cabecera.
            PdfPTable tPie           = new PdfPTable(3);                         // Tabla para poner la información en el pie.
            PdfPCell  celdaLogo      = new PdfPCell();                           // Celda para poner el logo.
            PdfPCell  celdaTitulo    = new PdfPCell();                           // Celda para poner el título.
            PdfPCell  celdaFecha     = new PdfPCell();                           // Celda para poner la fecha.
            PdfPCell  celdaNumPagina = new PdfPCell();                           // Celda para poner el número de página

            iTextSharp.text.Font fontTitulo = FontFactory.GetFont("Arial", 18f); // Fuente para utilizar en el título.
            iTextSharp.text.Font fontPie    = FontFactory.GetFont("Arial", 10f); // Fuente para utilizar en el pie.
            fontTitulo.Color = new BaseColor(0, 71, 185);                        // Color y
            fontTitulo.SetStyle(iTextSharp.text.Font.BOLD);                      // estilo.
            fontPie.Color = fontTitulo.Color;                                    // Color y
            fontPie.SetStyle(iTextSharp.text.Font.NORMAL);                       // estilo.
            celdaLogo.VerticalAlignment        = Element.ALIGN_MIDDLE;           // Alineación vertical de la celda.
            celdaLogo.Border                   = 0;                              // Sin borde.
            celdaTitulo.VerticalAlignment      = Element.ALIGN_MIDDLE;
            celdaTitulo.HorizontalAlignment    = Element.ALIGN_RIGHT;            // Alineación horizontal de la celda.
            celdaTitulo.Border                 = 0;
            celdaFecha.HorizontalAlignment     = Element.ALIGN_LEFT;
            celdaFecha.Border                  = 0;
            celdaNumPagina.HorizontalAlignment = Element.ALIGN_RIGHT;
            celdaNumPagina.Border              = 0;
            tCabecera.TotalWidth               = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            // El tamaño dela tabla para poner la cabecera es del 100 %
            tCabecera.DefaultCell.Border = 0;
            string url = "https://www.igformacion.com/wp-content/uploads/2019/04/logo-igformacion.png";

            // Dirección del logo.
            celdaLogo.Image = iTextSharp.text.Image.GetInstance(new Uri(url));
            // Cargamos la imagen desde la dirección indicada en la celda.

            celdaTitulo.Phrase = new Phrase("Listado de productos", fontTitulo); // Ponemos el título del listado.
            tCabecera.AddCell(celdaLogo);                                        // Añadimos el logo a la tabla cabecera.
            tCabecera.AddCell("");
            tCabecera.AddCell(celdaTitulo);                                      // Añadimos el título a la tabla cabecera.

            // Escribimos la tabla cabecera
            tCabecera.WriteSelectedRows(0,                                                              // Desde la posición 0.
                                        -1,                                                             // Toda la tabla (Sólo hay una fila)
                                        document.LeftMargin,                                            // Left -> Margen izquierda.
                                        writer.PageSize.GetTop(document.TopMargin) + (25f * milimetro), // Top -> Margen superior más 25 mm.
                                        writer.DirectContent);                                          // Dirección.

            tPie.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            tPie.DefaultCell.Border = 0;
            celdaFecha.Phrase       = new Phrase(DateTime.Now.ToString("dd/MM/yyyy"), fontPie); // Fecha de impresión.

            celdaNumPagina.Phrase = new Phrase("Página " + writer.PageNumber, fontPie);         // Número de página.

            tPie.AddCell(celdaFecha);
            tPie.AddCell("");
            tPie.AddCell(celdaNumPagina);
            tPie.WriteSelectedRows(0, -1, document.LeftMargin,

                                   writer.PageSize.GetBottom(document.BottomMargin), writer.DirectContent);
        }
Пример #6
0
        private static Font PdfFontStyle(iTextSharp.text.Font font, IEnumerable <TextStyleType> textStyle)
        {
            if (textStyle != null)
            {
                foreach (var item in textStyle)
                {
                    switch (item)
                    {
                    case TextStyleType.Bold: font.SetStyle(iTextSharp.text.Font.BOLD); return(font);

                    case TextStyleType.Italic: font.SetStyle(iTextSharp.text.Font.ITALIC); return(font);

                    case TextStyleType.Underline: font.SetStyle(iTextSharp.text.Font.UNDERLINE); return(font);

                    default: font.SetStyle(iTextSharp.text.Font.NORMAL); return(font);
                    }
                }
            }
            return(font);
        }
Пример #7
0
        private static Font GetFont(FontStyle style)
        {
            var font = new Font(PdfFonts.Normal);

            font.SetStyle(Font.NORMAL
                          | (style.Bold ? Font.BOLD : 0)
                          | (style.Italic ? Font.ITALIC : 0)
                          | (style.Underlined ? Font.UNDERLINE : 0)
                          );

            return(font);
        }
Пример #8
0
        public HeaderFooterExample(string number, string name)
        {
            header = new PdfPTable(2);
            header.WidthPercentage = 100;

            iText.Font font = new iText.Font(iText.Font.FontFamily.HELVETICA);
            font.SetStyle((int)FontStyle.Bold);

            Phrase   phrase = new Phrase(number, font);
            PdfPCell cell   = new PdfPCell(phrase);

            cell.Border              = PdfPCell.BOTTOM_BORDER;
            cell.BorderWidth         = 1.5f;
            cell.BorderColor         = BaseColor.RED;
            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            header.AddCell(cell);

            cell.Phrase = new Phrase(name, font);
            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
            header.AddCell(cell);

            cell             = new PdfPCell(new Phrase(" "));
            cell.BorderWidth = 0;
            header.AddCell(cell);
            header.AddCell(cell);

            float[] widths = { 6f, 1, 6f };
            footer           = new PdfPTable(widths);
            cell             = new PdfPCell(new Phrase("Generated by Landscape Sprinkler Designer"));
            cell.Border      = PdfPCell.TOP_BORDER;
            cell.BorderWidth = 1.5f;
            cell.BorderColor = BaseColor.BLUE;

            footer.AddCell(cell);

            cell.Phrase = new Phrase("");
            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            footer.AddCell(cell);

            cell.Phrase = new Phrase("Copywrite 2007 Tripp'n Technology");
            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
            footer.AddCell(cell);
        }
Пример #9
0
        public ExportReport()
        {
            xdoc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "\\AppTemplate\\report.xml");
            pdfDoc = new Document(PageSize.A4, 0, 0, 0, 0);
            Rectangle rect = new Rectangle(794, 1123);
            pdfDoc.SetPageSize(rect);
            pdfDoc.SetMargins(0, 0, 20, 0);

            BaseFont.AddToResourceSearch("iTextAsian.dll");
            BaseFont.AddToResourceSearch("iTextAsianCmaps.dll");
            BaseFont bsFont = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            fontTitle = new Font(bsFont, 20);
            fontContent = new Font(bsFont, 12);
            fontLabel = new Font(bsFont, 12);
            fontTableRemark = new Font(bsFont, 14);
            fontLabel.SetStyle(Font.BOLD);
            fontTitle.SetStyle(Font.BOLD);
            fontTableRemark.SetStyle(Font.BOLD);
        }
Пример #10
0
        /// <summary>
        /// 用report.xml的xdocument实例化
        /// </summary>
        /// <param name="doc">report内容</param>
        public AbsExportPDF(XDocument doc)
        {
            xdoc = doc;

            pdfDoc = new Document(PageSize.A4, 0, 0, 0, 0);
            Rectangle rect = new Rectangle(794, 1123);
            pdfDoc.SetPageSize(rect);
            pdfDoc.SetMargins(0, 0, 20, 0);

            BaseFont.AddToResourceSearch("iTextAsian.dll");
            BaseFont.AddToResourceSearch("iTextAsianCmaps.dll");
            BaseFont bsFont;
            bsFont = BaseFont.CreateFont(@"c:\WINDOWS\fonts\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            fontTitle = new Font(bsFont, 20);
            fontContent = new Font(bsFont, 12);
            fontLabel = new Font(bsFont, 12);
            fontTableRemark = new Font(bsFont, 14);
            fontLabel.SetStyle(Font.BOLD);
            fontTitle.SetStyle(Font.BOLD);
            fontTableRemark.SetStyle(Font.BOLD);
        }
        private void cabecalho(Document doc, int num)
        {
            // gera uma nova página
            doc.NewPage();

            // define a fonte a ser utilizada
            iTextSharp.text.Font fonteCab = FontFactory.GetFont("Courier");
            fonteCab.Size = 12;
            fonteCab.SetStyle(2);
            fonteCab.SetColor(5, 0, 125);

            Paragraph cab = new Paragraph("Academia SportFitness", fonteCab);
            cab.Alignment = Element.ALIGN_CENTER;
            doc.Add(cab);

            if (num == 0)
            {
                cab = new Paragraph("Relatório de Alunos Cadastrados", fonteCab);
            }
            else if (num == 1)
            {
                cab = new Paragraph("Relatório de Funcionários Cadastrados", fonteCab);
            }
            else if (num == 2)
            {
                cab = new Paragraph("Relatório do Financeiro (Renda Mensal)", fonteCab);
            }
            cab.Alignment = Element.ALIGN_CENTER;
            doc.Add(cab);

            // muda o tamanho da fonte
            fonteCab.Size = 10;
            fonteCab.SetColor(0, 0, 0);

            cab = new Paragraph(geraTracos(87), fonteCab);
            cab.Alignment = Element.ALIGN_CENTER;
            doc.Add(cab);
        }
Пример #12
0
        private List<Paragraph> Signatures()
        {
            Paragraph signature1 = new Paragraph(20f);
            Paragraph signature2 = new Paragraph(20f);
            Paragraph signature3 = new Paragraph(20f);

            Font underline = new Font(signature1.Font);
            underline.SetStyle(Font.UNDERLINE);

            string spaces = " ";
            spaces = spaces.PadLeft(70);
            Phrase line = new Phrase(spaces, underline);
            signature1.Add(line);
            signature1.Add(new Phrase("(1)", this.ContentFont));
            signature2.Add(line);
            signature2.Add(new Phrase("(2)", this.ContentFont));
            signature3.Add(line);
            signature3.Add(new Phrase("(3)", this.ContentFont));

            List<Paragraph> signatures = new List<Paragraph>() { signature1, signature2, signature3 };            
            return signatures;
        }
    protected void Prepare_Print()
    {
        String[] weekDays = new String[] { " ","Sun", "Mon", "Tue", "Wed", "Thu" };
        int[] sessions = new int[] {0,1,2,3,4,5,6,7,8,9};
        PdfPTable tblSchedule = new PdfPTable(10);
        PdfPRow[] tempRow = new PdfPRow[6];
        PdfPCell[][] tempCell = new PdfPCell[6][];
        int rowIndex = 0;
        int cellIndex = 0;
        Paragraph subject = new Paragraph();
        Paragraph teacher = new Paragraph();
        Paragraph lunch = new Paragraph();
        Paragraph dayPara = new Paragraph();
        Paragraph sessionPara = new Paragraph();
        Paragraph teacherPara = new Paragraph();

        Font lunch_font = new Font();
        Font day_session_para = new Font();
        Font session_font = new Font();
        Font teacher_font = new Font();

        session_font.Size = 10;
        teacher_font.SetStyle("Italics");
        teacher_font.Size = 7;

        lunch_font.SetColor(153, 153, 255);
        lunch_font.SetStyle("italics");
        lunch = new Paragraph("Lunch", lunch_font);

        day_session_para.SetColor(0, 0, 153);

        foreach (String weekDay in weekDays)
        {
            tempCell[rowIndex] = new PdfPCell[10];
            tempRow[rowIndex] = new PdfPRow(tempCell[rowIndex]);
            foreach (int session in sessions)
            {
                if (session == 0 || session == 6)
                {
                    if (session == 0)
                    {
                        dayPara = new Paragraph(weekDays[rowIndex],day_session_para);
                        tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                    }
                    else
                        if (weekDay != " ")
                        {
                            tempCell[rowIndex][cellIndex] = new PdfPCell(lunch);
                        }
                        else
                        {
                            //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex])));
                            dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para);
                            tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                        }
                }
                else
                {
                    if (weekDay == " ")
                    {
                        dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para);
                        tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                        //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex])));
                    }
                    else
                    {
                        string query = "select B.CourseTitle,A.TeacherID from tblStudentCourseMap as A,tblCourses as B where A.ComCod = B.ComCod and A.DaySession = '" + weekDay + session + "' and A.StudentID = '" + Current_User_ID + "'";
                        myCon.ConOpen();
                        SqlDataReader sessionDet = myCon.ExecuteReader(query);

                        if (sessionDet.Read())
                            if (!sessionDet.IsDBNull(0))
                            {
                                sessionPara = new Paragraph(sessionDet.GetString(0), session_font);
                                //tempCell[rowIndex][cellIndex] = new PdfPCell(sessionPara);
                                teacherPara = new Paragraph(sessionDet.GetString(1), teacher_font);
                                tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionPara));
                                tempCell[rowIndex][cellIndex].Phrase.Add(new Phrase("\n"));
                                tempCell[rowIndex][cellIndex].Phrase.Add(teacherPara);
                                //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionDet.GetString(0) + "\n" + sessionDet.GetString(1)));
                            }
                            else
                            {
                                tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(""));
                                //tempCell[rowIndex][cellIndex
                            }
                        else
                            tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(""));
                        myCon.ConClose();
                        tempCell[rowIndex][cellIndex].FixedHeight = 75;
                    }

                }

                //tempCell[rowIndex][cellIndex].Width = 50;
                cellIndex++;
                //tempRow[rowIndex].Cells.Add(tempCell[cellIndex++, rowIndex]);
            }
            cellIndex = 0;
            //rowIndex++;
            tblSchedule.Rows.Add(tempRow[rowIndex++]);
        }

        Font HeaderFont = new Font();
        Font HeadingFont = new Font();
        HeaderFont.Size = 20;
        HeaderFont.SetStyle(Font.UNDERLINE);
        HeadingFont.Size = 15;
        HeadingFont.SetStyle(Font.UNDERLINE);
        Paragraph HeaderPara = new Paragraph("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE", HeaderFont);
        Paragraph HeadingPara = new Paragraph("Time Table allotment for " + Current_User_ID + ".",HeadingFont);
        HeaderPara.Alignment = HeadingPara.Alignment = 1;

        Document rptTimetable = new Document(PageSize.A4_LANDSCAPE.Rotate());
        PdfWriter.GetInstance(rptTimetable, new FileStream(Request.PhysicalApplicationPath + "\\" + Current_User_ID + "_timetable.pdf", FileMode.Create));
        rptTimetable.Open();
        rptTimetable.AddCreationDate();
        rptTimetable.AddHeader("BITS PILANI, DUBAI OFFCAMPUS", "TIMETABLE");
        rptTimetable.Add(new Paragraph("\n"));
        rptTimetable.AddTitle("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE");
        rptTimetable.Add(HeaderPara);
        rptTimetable.Add(HeadingPara);
        rptTimetable.Add(new Paragraph("\n\n"));

        if (rptTimetable != null && tblSchedule != null)
        {
            rptTimetable.Add(tblSchedule);
        }
        rptTimetable.Close();
        Response.Redirect("~\\" + Current_User_ID + "_timetable.pdf");
    }
Пример #14
0
        private Paragraph Introduction()
        {
            string space = " ";
            Paragraph introduction = new Paragraph(20f);
            introduction.Alignment = Element.ALIGN_JUSTIFIED;

            Font underline = new Font(introduction.Font);
            underline.SetStyle(Font.UNDERLINE);

            introduction.Add("Aos ");

            Phrase day = new Phrase(space.PadLeft(4), underline);
            introduction.Add(day);

            introduction.Add(" dias do mês de ");

            Phrase month = new Phrase(space.PadLeft(20), underline);
            introduction.Add(month);

            introduction.Add(" de ");

            Phrase year = new Phrase(space.PadLeft(8), underline);
            introduction.Add(year);

            introduction.Add(" no(a) ");

            Phrase space6 = new Phrase(space.PadLeft(50), underline);
            introduction.Add(space6);
            introduction.Add(new Phrase("  "));
            Phrase space7 = new Phrase(space.PadLeft(130), underline);
            introduction.Add(space7);

            introduction.Add(" na presença dos abaixo assinados, procedeu-se à inutilização por de acordo com o(s) artigo(s) ");

            Phrase space10 = new Phrase(space.PadLeft(20), underline);
            introduction.Add(space10);

            introduction.Add(" da Portaria n.º ");

            introduction.Add(year);
            introduction.Add(" / ");
            introduction.Add(year);

            introduction.Add(" e disposições da tabela de seleção, dos documentos, a seguir identificados: ");

            return introduction;
        }
Пример #15
0
        public static void Genera(string sourcePath,string content)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();

                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H, //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);

                //写入一个段落, Paragraph
                doc.Add(new Paragraph("第一段:" + content, font));
                doc.Add(new Paragraph("这是第二段 !", font));

                #region 图片
                //以下代码用来添加图片,此时图片是做为背景加入到pdf文件当中的:

                Stream inputImageStream = new FileStream(HttpContext.Current.Server.MapPath("~/images/logo.jpg"), FileMode.Open, FileAccess.Read, FileShare.Read);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                image.SetAbsolutePosition(0, 0);
                image.Alignment = iTextSharp.text.Image.UNDERLYING;    //这里可以设定图片是做为背景还是做为元素添加到文件中
                doc.Add(image);

                #endregion
                #region 其他元素
                doc.Add(new Paragraph("Hello World"));
                //另起一行。有几种办法建立一个段落,如:
                Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                //所有有些对象将被添加到段落中:
                p1.Add("you can add string here\n\t");
                p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
                doc.Add(p1); doc.Add(p2); doc.Add(p3);

                //创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
                Chunk chunk = new Chunk("创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
                doc.Add(chunk);
                //如果你希望一些块有下划线或删除线,你可以通过改变字体风格简单做到:
                Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
                Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.STRIKETHRU));
                //改变块的背景
                chunk2.SetBackground(new iTextSharp.text.Color(0xFF, 0xFF, 0x00));
                //上标/下标
                chunk1.SetTextRise(5);
                doc.Add(chunk1);
                doc.Add(chunk2);

                //外部链接示例:
                Anchor anchor = new Anchor("website", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED, new iTextSharp.text.Color(0, 0, 255)));
                anchor.Reference = "http://itextsharp.sourceforge.net";
                anchor.Name = "website";
                //内部链接示例:
                Anchor anchor1 = new Anchor("This is an internal link\n\n");
                anchor1.Name = "link1";
                Anchor anchor2 = new Anchor("Click here to jump to the internal link\n\f");
                anchor2.Reference = "#link1";
                doc.Add(anchor); doc.Add(anchor1); doc.Add(anchor2);

                //排序列表示例:
                List list = new List(true, 20);
                list.Add(new ListItem("First line"));
                list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
                list.Add(new ListItem("Third line"));
                doc.Add(list);

                //文本注释:
                Annotation a = new Annotation("authors", "Maybe its because I wanted to be an author myself that I wrote iText.");
                doc.Add(a);

                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer = footer;

                //Chapter对象和Section对象自动构建一个树:
                iTextSharp.text.Font f1 = new iTextSharp.text.Font();
                f1.SetStyle(iTextSharp.text.Font.BOLD);
                Paragraph cTitle = new Paragraph("This is chapter 1", f1);
                Chapter chapter = new Chapter(cTitle, 1);
                Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", f1);
                Section section = chapter.AddSection(sTitle, 1);
                doc.Add(chapter);

                //构建了一个简单的表:
                Table aTable = new Table(4, 4);
                aTable.AutoFillEmptyCells = true;
                aTable.AddCell("2.2", new System.Drawing.Point(2, 2));
                aTable.AddCell("3.3", new System.Drawing.Point(3, 3));
                aTable.AddCell("2.1", new System.Drawing.Point(2, 1));
                aTable.AddCell("1.3", new System.Drawing.Point(1, 3));
                doc.Add(aTable);
                //构建了一个不简单的表:
                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new iTextSharp.text.Color(0, 0, 255);
                table.Cellpadding = 5;
                table.Cellspacing = 5;
                Cell cell = new Cell("header");
                cell.Header = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan = 2;
                cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell = new Cell("big cell");
                cell.Rowspan = 2;
                cell.Colspan = 2;
                cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                // 改变了单元格“big cell”的对齐方式:
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                doc.Add(table);

                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
Пример #16
0
        /// <summary>
        /// 第一页信息
        /// </summary>
        /// <param name="document"></param>
        public void InitFirstPage()
        {
            document.Add(new Paragraph("\n\n\n\n"));
            //Title
            Font font = new Font(bfSun, 24);
            font.SetStyle("bold");
            Paragraph pg = new Paragraph(SystemTitle, font);
            pg.Alignment = Element.ALIGN_CENTER;
            document.Add(pg);

            //subTitle
            font = new Font(bfSun, 18);
            font.SetStyle("bold");
            pg = new Paragraph(SubTitle, font);
            pg.Alignment = Element.ALIGN_CENTER;
            document.Add(pg);

            //版权、时间
            document.Add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));
            font = new Font(bfSun, 18);
            font.SetStyle("bold");
            pg = new Paragraph(Company, font);
            pg.Alignment = Element.ALIGN_CENTER;
            document.Add(pg);

            font = new Font(bfSun, 14);
            font.SetStyle("bold");
            string mTime = string.Format("{0}年{1}月", DateTime.Now.Year, DateTime.Now.Month);
            pg = new Paragraph(mTime, font);
            pg.Alignment = Element.ALIGN_CENTER;
            document.Add(pg);
        }
Пример #17
0
        public string CreateLogbook(Logbook _logbook)
        {
            //DateTime Monday = DateTime.Now;
            //while (Monday.DayOfWeek != DayOfWeek.Monday) Monday = Monday.AddDays(-1);
            //string Mondays = Monday.ToString("dd-MMMM-yyyy");


            //DateTime Tuesday = DateTime.Now;
            //while (Tuesday.DayOfWeek != DayOfWeek.Tuesday) Tuesday = Tuesday.AddDays(-1);
            //string Tuesdays = Tuesday.ToString("dd-MMMM-yyyy");


            //DateTime Wednesday = DateTime.Now;
            //while (Wednesday.DayOfWeek != DayOfWeek.Wednesday) Wednesday = Wednesday.AddDays(-1);
            //string Wednesdays = Wednesday.ToString("dd-MMMM-yyyy");


            //DateTime Thursday = DateTime.Now;
            //while (Thursday.DayOfWeek != DayOfWeek.Thursday) Thursday = Thursday.AddDays(-1);
            //string Thursdays = Thursday.ToString("dd-MMMM-yyyy");


            //DateTime Friday = DateTime.Now;
            //while (Friday.DayOfWeek != DayOfWeek.Friday) Friday = Friday.AddDays(-1);
            //string Fridays = Friday.ToString("dd-MMMM-yyyy");



            string Date = DateLearnerSigned.ToString();
            string WL   = "Weekly Logbook";
            // Document document = new Document(PageSize.A4.Rotate(), 10f, 10f, 10f, 0f);
            Document document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
            //Document document = new Document(new RectangleReadOnly(842, 595), 88f, 88f, 10f, 10f);
            // Document document = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);



            DateTime dt = DateTime.Now;

            while (dt.DayOfWeek != DayOfWeek.Friday)
            {
                dt = dt.AddDays(1);
            }
            string Week = dt.ToString("dd-MMMM-yyyy");


            //M path

            string path = HttpContext.Current.Server.MapPath("~/WeeklyLogbooks/" + Week + "/");



            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }



            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + _logbook.LearnerName + " " + WL + ".pdf", FileMode.Create));



            document.Open();



            Font arial = FontFactory.GetFont("Arial", 12, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);



            Paragraph info      = new Paragraph();
            Paragraph infos     = new Paragraph();
            Paragraph small     = new Paragraph();
            Paragraph smallb    = new Paragraph();
            Paragraph inforhead = new Paragraph();
            Paragraph head      = new Paragraph();

            inforhead.SpacingBefore = 12;
            head.SpacingAfter       = 14;
            small.SpacingBefore     = 10;



            iTextSharp.text.Font contentFont = iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL);
            info.Font = contentFont;

            iTextSharp.text.Font smallfont = iTextSharp.text.FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.NORMAL);
            small.Font = smallfont;

            iTextSharp.text.Font heads = iTextSharp.text.FontFactory.GetFont("Calibri(body)", 12, iTextSharp.text.Font.BOLD);
            heads.SetStyle(Font.ITALIC);

            head.Font = heads;

            iTextSharp.text.Font smallbold = iTextSharp.text.FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.NORMAL);
            smallbold.SetStyle(Font.BOLD);
            smallb.Font = smallbold;

            iTextSharp.text.Font infohea = iTextSharp.text.FontFactory.GetFont("Calibri(body)", 12, iTextSharp.text.Font.BOLD);
            infohea.SetStyle(Font.ITALIC);
            inforhead.Font = infohea;



            //For name
            iTextSharp.text.Font contentTop = iTextSharp.text.FontFactory.GetFont("Arial", 13, iTextSharp.text.Font.ITALIC);
            contentTop.SetStyle(Font.BOLD);
            contentTop.SetStyle(Font.UNDERLINE);

            info.Font  = contentFont;
            infos.Font = contentTop;
            string line = "           ";

            //info.Add("                                                           Learner Daily Log                                       " + "\r\n");
            info.Add(line);
            info.Add(line);
            info.Add(line + line + line + line + line + line + line + line + line + line + line + line + "Learner Daily Log  " + "\r\n");
            head.Add("LEARNER DAILY ACTIVITIES LOGBOOK  " + "\r\n");
            info.Add(line + "\r\n");
            infos.Add("Learner's Name: " + _logbook.LearnerName + "\r\n");
            info.Add(line + "\r\n");
            infos.Add("Mentor's Name and Tel: " + _logbook.MentorName + ": " + _logbook.MentorTel + "\r\n");
            info.Add(line + "\r\n");
            infos.Add("Learnership Intake: " + _logbook.Learnership + "\r\n");
            info.Add(line + "\r\n");
            infos.Add("Company Name: " + _logbook.CompanyName);
            inforhead.Add("Please refer to Workplace Task Maping for a breakdown of prescribed activities." + "\r\n");
            info.Add(line + "\r\n");
            info.Add(line + "\r\n");
            small.Add("This form must be completed everyday and signed off by both the Learner and respective Mentor." + "\r\n");
            small.Add("This form is intended for generic use.");

            smallb.Add("Please return to Torque IT at the follwing Fax number every friday:086 632 9687 or [email protected] and copy.");

            infos.Add(line + "\r\n");
            document.Add(info);
            document.Add(head);
            document.Add(infos);
            document.Add(small);
            document.Add(smallb);
            document.Add(inforhead);



            PdfPTable table = new PdfPTable(8);

            table.SpacingBefore = 14;
            // table.TotalWidth = 50;
            table.WidthPercentage = 100;



            //Checking which font was selected
            Font selectedFont;

            Font arialsignature = FontFactory.GetFont("Bradley Hand ITC", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arialsignature1 = FontFactory.GetFont("Blackadder ITC", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arialsignature2 = FontFactory.GetFont("Brush Script Std", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arialsignature3 = FontFactory.GetFont("Buxton Sketch", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arialsignature4 = FontFactory.GetFont("Informal Roman", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arialsignature5 = FontFactory.GetFont("Matura MT Script Capitals", 13, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);


            PdfPCell Cell  = new PdfPCell(new Phrase("Date", new Font(arial)));
            PdfPCell Cell1 = new PdfPCell(new Phrase("Task/s Completed", new Font(arial)));
            PdfPCell Cell2 = new PdfPCell(new Phrase("Completed to satidfaction Yes/No", new Font(arial)));
            PdfPCell Cell3 = new PdfPCell(new Phrase("Time Taken in Hours", new Font(arial)));
            PdfPCell Cell4 = new PdfPCell(new Phrase("Problems Experienced(if any)", new Font(arial)));
            PdfPCell Cell5 = new PdfPCell(new Phrase("General Comments", new Font(arial)));
            PdfPCell Cell6 = new PdfPCell(new Phrase("Learner's Signature", new Font(arialsignature3)));
            PdfPCell Cell7 = new PdfPCell(new Phrase("Mentor's Signature", new Font(arial)));



            Cell.Colspan                         = 1;
            Cell.HorizontalAlignment             = 1;
            table.AddCell(Cell).BackgroundColor  = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell1).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell2).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell3).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell4).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell5).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell6).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell7).BackgroundColor = BaseColor.LIGHT_GRAY;



            //1st Row


            table.AddCell(_logbook.Day01.Value.ToShortDateString());
            //table.AddCell(Mondays);
            table.AddCell(_logbook.TaskDay01);
            table.AddCell(_logbook.CompletedSatDay01);
            table.AddCell(_logbook.TimeTakenDay01);
            table.AddCell(_logbook.ProblemsDay01);
            table.AddCell(_logbook.CommentsDay01);
            table.AddCell(_logbook.LearnerSignature);
            table.AddCell("M.Huna");

            //2nd Row


            //table.AddCell(Tuesdays);
            table.AddCell(_logbook.Day02.Value.ToShortDateString());
            table.AddCell(_logbook.TaskDay02);
            table.AddCell(_logbook.CompletedSatDay02);
            table.AddCell(_logbook.TimeTakenDay02);
            table.AddCell(_logbook.ProblemsDay02);
            table.AddCell(_logbook.CommentsDay02);
            table.AddCell(_logbook.LearnerSignature);
            table.AddCell("M.Huna");

            //3rd Row



            //table.AddCell(Wednesdays);
            table.AddCell(_logbook.Day03.Value.ToShortDateString());
            table.AddCell(_logbook.TaskDay03);
            table.AddCell(_logbook.CompletedSatDay03);
            table.AddCell(_logbook.TimeTakenDay03);
            table.AddCell(_logbook.ProblemsDay03);
            table.AddCell(_logbook.CommentsDay03);
            table.AddCell(_logbook.LearnerSignature);
            table.AddCell("M.Huna");

            //4th Row



            //table.AddCell(Thursdays);
            table.AddCell(_logbook.Day04.Value.ToShortDateString());
            table.AddCell(_logbook.TaskDay04);
            table.AddCell(_logbook.CompletedSatDay04);
            table.AddCell(_logbook.TimeTakenDay04);
            table.AddCell(_logbook.ProblemsDay04);
            table.AddCell(_logbook.CommentsDay04);
            table.AddCell(_logbook.LearnerSignature);
            table.AddCell("M.Huna");

            //5th Row


            //table.AddCell(Fridays);
            table.AddCell(_logbook.Day05.Value.ToShortDateString());
            table.AddCell(_logbook.TaskDay05);
            table.AddCell(_logbook.CompletedSatDay05);
            table.AddCell(_logbook.TimeTakenDay05);
            table.AddCell(_logbook.ProblemsDay05);
            table.AddCell(_logbook.CommentsDay05);
            table.AddCell(_logbook.LearnerSignature);
            table.AddCell("M.Huna");
            info.Add("Prepared by the Torque Career Campus");
            info.Add(line + "\r\n");

            document.Add(table);



            document.Close();

            if (_logbook.Preview == "Yes")
            {
                string pathss = HttpContext.Current.Server.MapPath("~/WeeklyLogbooks/" + Week + "/");


                System.Diagnostics.Process.Start(pathss + _logbook.LearnerName + " " + WL + ".pdf");
            }


            try
            {
                return("Successfully Submitted Logbook " + _logbook.LearnerName);
            }
            catch (Exception es)
            {
                throw es;
            }
        }
Пример #18
0
        public static void Genera(string sourcePath, string content)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();


                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H,              //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);


                //写入一个段落, Paragraph
                doc.Add(new Paragraph("第一段:" + content, font));
                doc.Add(new Paragraph("这是第二段 !", font));


                #region 图片
                //以下代码用来添加图片,此时图片是做为背景加入到pdf文件当中的:

                Stream inputImageStream     = new FileStream(HttpContext.Current.Server.MapPath("~/images/logo.jpg"), FileMode.Open, FileAccess.Read, FileShare.Read);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                image.SetAbsolutePosition(0, 0);
                image.Alignment = iTextSharp.text.Image.UNDERLYING;    //这里可以设定图片是做为背景还是做为元素添加到文件中
                doc.Add(image);

                #endregion
                #region 其他元素
                doc.Add(new Paragraph("Hello World"));
                //另起一行。有几种办法建立一个段落,如:
                Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                //所有有些对象将被添加到段落中:
                p1.Add("you can add string here\n\t");
                p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
                doc.Add(p1); doc.Add(p2); doc.Add(p3);

                //创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
                Chunk chunk = new Chunk("创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
                doc.Add(chunk);
                //如果你希望一些块有下划线或删除线,你可以通过改变字体风格简单做到:
                Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
                Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.STRIKETHRU));
                //改变块的背景
                chunk2.SetBackground(new iTextSharp.text.Color(0xFF, 0xFF, 0x00));
                //上标/下标
                chunk1.SetTextRise(5);
                doc.Add(chunk1);
                doc.Add(chunk2);

                //外部链接示例:
                Anchor anchor = new Anchor("website", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED, new iTextSharp.text.Color(0, 0, 255)));
                anchor.Reference = "http://itextsharp.sourceforge.net";
                anchor.Name      = "website";
                //内部链接示例:
                Anchor anchor1 = new Anchor("This is an internal link\n\n");
                anchor1.Name = "link1";
                Anchor anchor2 = new Anchor("Click here to jump to the internal link\n\f");
                anchor2.Reference = "#link1";
                doc.Add(anchor); doc.Add(anchor1); doc.Add(anchor2);

                //排序列表示例:
                List list = new List(true, 20);
                list.Add(new ListItem("First line"));
                list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
                list.Add(new ListItem("Third line"));
                doc.Add(list);

                //文本注释:
                Annotation a = new Annotation("authors", "Maybe its because I wanted to be an author myself that I wrote iText.");
                doc.Add(a);

                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer    = footer;


                //Chapter对象和Section对象自动构建一个树:
                iTextSharp.text.Font f1 = new iTextSharp.text.Font();
                f1.SetStyle(iTextSharp.text.Font.BOLD);
                Paragraph cTitle  = new Paragraph("This is chapter 1", f1);
                Chapter   chapter = new Chapter(cTitle, 1);
                Paragraph sTitle  = new Paragraph("This is section 1 in chapter 1", f1);
                Section   section = chapter.AddSection(sTitle, 1);
                doc.Add(chapter);

                //构建了一个简单的表:
                Table aTable = new Table(4, 4);
                aTable.AutoFillEmptyCells = true;
                aTable.AddCell("2.2", new System.Drawing.Point(2, 2));
                aTable.AddCell("3.3", new System.Drawing.Point(3, 3));
                aTable.AddCell("2.1", new System.Drawing.Point(2, 1));
                aTable.AddCell("1.3", new System.Drawing.Point(1, 3));
                doc.Add(aTable);
                //构建了一个不简单的表:
                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new iTextSharp.text.Color(0, 0, 255);
                table.Cellpadding = 5;
                table.Cellspacing = 5;
                Cell cell = new Cell("header");
                cell.Header  = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell             = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan     = 2;
                cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell                 = new Cell("big cell");
                cell.Rowspan         = 2;
                cell.Colspan         = 2;
                cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                // 改变了单元格“big cell”的对齐方式:
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                doc.Add(table);

                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
Пример #19
0
        public void CreateForm(Supply sup)
        {
            try
            {
                string FileName = "Заявка на поставку №" + sup.Id + ".pdf";
                iTextSharp.text.Document doc = new iTextSharp.text.Document();
                PdfWriter.GetInstance(doc, new FileStream(FileName, FileMode.Create));

                doc.Open();

                BaseFont             baseFont          = BaseFont.CreateFont("C:/Windows/Fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                var                  arial_italic_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ariali.ttf");
                BaseFont             ItalicBaseFont    = BaseFont.CreateFont(arial_italic_path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font       = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font ItalicFont = new iTextSharp.text.Font(ItalicBaseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);

                Paragraph par = new Paragraph("Кому: " + db.getProviders().Where(i => i.Id == sup.ProviderId).Select(i => i.CompanyName).FirstOrDefault().ToString(), font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                string Initials = db.getProviders().Where(i => i.Id == sup.ProviderId).Select(i => i.Initials).FirstOrDefault().ToString();
                string FamName  = db.getProviders().Where(i => i.Id == sup.ProviderId).Select(i => i.FamilyName).FirstOrDefault().ToString();
                if (FamName[FamName.Length - 1] == 'н' || FamName[FamName.Length - 1] == 'в')
                {
                    FamName = FamName + "у";
                }
                string FulName = FamName + " " + Initials;

                par           = new Paragraph("Директору " + FulName, font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                par           = new Paragraph("От ООО \"Sirius Smoke\"", font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                string warehousename = db.getWarehouses().Where(i => i.Id == sup.WarehouseId).Select(i => i.Address).FirstOrDefault().ToString();

                par           = new Paragraph("г. Иваново, " + warehousename, font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                par           = new Paragraph("т. 8 (567) 63-87-69", font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                par           = new Paragraph(DateTime.Parse(sup.ApplicationDate.ToString()).ToShortDateString(), font);
                par.Alignment = Element.ALIGN_RIGHT;
                doc.Add(par);

                par           = new Paragraph("ЗАЯВКА", font);
                par.Alignment = Element.ALIGN_CENTER;
                par.SetLeading(font.Size, 2);
                doc.Add(par);

                par           = new Paragraph("на поставку товара", font);
                par.Alignment = Element.ALIGN_CENTER;
                doc.Add(par);

                par = new Paragraph(" ", font);
                doc.Add(par);

                string str = "Прошу зарезервировать и поставить до " + DateTime.Parse(sup.DeliveryDate.ToString()).ToShortDateString() + " следующие наименования товаров:";
                par = new Paragraph(str, font);
                doc.Add(par);

                PdfPTable table = new PdfPTable(4);
                table.SpacingBefore = 20;
                PdfPCell HeaderCell = new PdfPCell(new Phrase("Наименование", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase("Количество", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase("Цена единицы товара, р", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase("Общая стоимость, р", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);

                decimal TotalSum      = 0;
                int     TotalQuantity = 0;

                foreach (SupplyLine item in sup.Lines)
                {
                    PdfPCell BasicCell = new PdfPCell(new Phrase(item.CommodityName.ToString(), font));
                    BasicCell.HorizontalAlignment = 1;
                    table.AddCell(BasicCell);
                    BasicCell = new PdfPCell(new Phrase(item.Quantity.ToString() + " шт.", font));
                    BasicCell.HorizontalAlignment = 1;
                    table.AddCell(BasicCell);
                    BasicCell = new PdfPCell(new Phrase((item.Cost).ToString(), font));
                    BasicCell.HorizontalAlignment = 1;
                    table.AddCell(BasicCell);
                    BasicCell = new PdfPCell(new Phrase((item.Cost * item.Quantity).ToString(), font));
                    BasicCell.HorizontalAlignment = 1;
                    table.AddCell(BasicCell);
                    TotalQuantity += item.Quantity;
                    TotalSum      += item.Cost * item.Quantity;
                }
                HeaderCell = new PdfPCell(new Phrase("Итого", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase(TotalQuantity.ToString() + " шт.", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase("", font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                HeaderCell = new PdfPCell(new Phrase(TotalSum.ToString(), font));
                HeaderCell.HorizontalAlignment = 1;
                table.AddCell(HeaderCell);
                table.WidthPercentage = 95;
                doc.Add(table);

                par = new Paragraph("Директор ООО \"Sirius Smoke\"", font);
                font.SetStyle(iTextSharp.text.Font.ITALIC);
                par.Add(new Chunk("                 Воронов", ItalicFont));
                font.SetStyle(iTextSharp.text.Font.NORMAL);
                par.Add(new Chunk("                 Воронов И.С.", font));
                par.Alignment = Element.ALIGN_CENTER;
                par.SetLeading(font.Size, 2);
                doc.Add(par);
                doc.Close();
                MessageBox.Show("Файл заявки \"" + FileName + "\" создан");
            }
            catch (IOException ex)
            {
                MessageBox.Show("Возникла ошибка при записи страниц", ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Возникла ошибка", ex.Message);
            }
        }
Пример #20
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title            = "Export to PDF";
            saveFileDialog1.Filter           = "(*.pdf)|*.pdf";
            saveFileDialog1.InitialDirectory = @"D:\";
            saveFileDialog1.FileName         = "AHP_" + mainForm.getCurrentTopic().topicName + "_" + mainForm.getCurrentUser().userName;
            saveFileDialog1.FileOk          += saveFileDialog1_FileOk;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    iTextSharp.text.Document doc = new iTextSharp.text.Document();
                    PdfWriter pdfWriter          = PdfWriter.GetInstance(doc, new FileStream(saveFileDialog1.FileName, FileMode.Create));
                    //pdfWriter.PageEvent = new ITextEvents(mainForm.getCurrentTopic().topicName.ToUpper());

                    // FONT DEFINITION
                    //iTextSharp.text.pdf.BaseFont bfTitle = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED);
                    //iTextSharp.text.Font fontTitle = new iTextSharp.text.Font(bfTitle, 15);
                    //fontTitle.SetStyle(iTextSharp.text.Font.UNDERLINE);
                    iTextSharp.text.pdf.BaseFont bfNormal       = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED);
                    iTextSharp.text.pdf.BaseFont bfBold         = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED);
                    iTextSharp.text.Font         fontSubtitle   = new iTextSharp.text.Font(bfBold, 13);
                    iTextSharp.text.Font         fontColHeader  = new iTextSharp.text.Font(bfBold, 11);
                    iTextSharp.text.Font         fontTable      = new iTextSharp.text.Font(bfNormal, 10);
                    iTextSharp.text.Font         fontConclusion = new iTextSharp.text.Font(bfNormal, 10);
                    fontConclusion.SetStyle(iTextSharp.text.Font.UNDERLINE);

                    // HEADER AND FOOTER
                    TwoColumnHeaderFooter PageEventHandler = new TwoColumnHeaderFooter(mainForm.getCurrentUser().userName);
                    pdfWriter.PageEvent          = PageEventHandler;
                    PageEventHandler.Title       = "AHP RESULT";
                    PageEventHandler.HeaderFont  = FontFactory.GetFont(BaseFont.COURIER_BOLD, 10, iTextSharp.text.Font.BOLD);
                    PageEventHandler.HeaderLeft  = "Topic";
                    PageEventHandler.HeaderRight = mainForm.getCurrentTopic().topicName.ToUpper();

                    doc.Open();

                    // TITLE
                    //Paragraph title = new Paragraph(mainForm.getCurrentTopic().topicName.ToUpper(), fontTitle);
                    //title.Alignment = Element.ALIGN_CENTER;
                    //doc.Add(title);

                    doc.Add(new Paragraph(" "));
                    // SUBTITLE: DETAIL ALTERNATIVE
                    Paragraph subtitle1 = new Paragraph("DETAIL ALTERNATIVE", fontSubtitle);
                    subtitle1.Alignment     = Element.ALIGN_CENTER;
                    subtitle1.SpacingBefore = 25;
                    subtitle1.SpacingAfter  = 20;
                    doc.Add(subtitle1);

                    // TABLE DETAIL
                    bool switchCloseAlternativeListForm     = true;
                    AlternativeListForm alternativeListForm = null;
                    if (mainForm.isFormOpened(typeof(AlternativeListForm)) != null)
                    {
                        switchCloseAlternativeListForm = false;
                        alternativeListForm            = (AlternativeListForm)mainForm.isFormOpened(typeof(AlternativeListForm));
                        alternativeListForm.MdiParent  = mainForm;
                        alternativeListForm.Show();
                    }
                    else
                    {
                        alternativeListForm = mainForm.getAlternativeListForm();
                    }

                    DataGridView dataGridView = alternativeListForm.getDGV();

                    PdfPTable pdfPTable = new PdfPTable(dataGridView.ColumnCount);
                    // Header Column
                    foreach (DataGridViewColumn column in dataGridView.Columns)
                    {
                        PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fontColHeader));
                        //cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(cell);
                    }
                    // Adding DataRow
                    foreach (DataGridViewRow row in dataGridView.Rows)
                    {
                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            PdfPCell pdfPCell = new PdfPCell(new Phrase(cell.Value.ToString(), fontTable));
                            pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER;
                            pdfPCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            pdfPTable.AddCell(pdfPCell);
                        }
                    }
                    doc.Add(pdfPTable);

                    mainForm.refreshAllChildrenForm();
                    if (switchCloseAlternativeListForm)
                    {
                        alternativeListForm.Close();
                    }

                    // SUBTITLE: COMPARISON
                    Paragraph subtitle2 = new Paragraph("COMPARISON", fontSubtitle);
                    subtitle2.Alignment     = Element.ALIGN_CENTER;
                    subtitle2.SpacingBefore = 25;
                    doc.Add(subtitle2);

                    // CHART IMAGE
                    MemoryStream ms = new MemoryStream();
                    chart1.SaveImage(ms, ChartImageFormat.Png);
                    iTextSharp.text.Image chart_img = iTextSharp.text.Image.GetInstance(ms.ToArray());
                    chart_img.SetDpi(300, 300);
                    chart_img.ScaleToFit(300f, 300f);
                    chart_img.Alignment = Element.ALIGN_CENTER;
                    doc.Add(chart_img);

                    // SUBTITLE: CONCLUSION
                    Paragraph subtitle3 = new Paragraph("CONCLUSION", fontSubtitle);
                    subtitle3.Alignment     = Element.ALIGN_CENTER;
                    subtitle3.SpacingBefore = 25;
                    doc.Add(subtitle3);

                    // CONCLUSION
                    List <List <string> > conclusion = resultController.conclusionBestWorst(currentTopicId);

                    if (conclusion == null)
                    {
                        doc.Add(new Paragraph("Cannot conclude anything, since the data is all the same.", fontTable));
                    }
                    else
                    {
                        // SUB SUBTITLE BEST ALTERNATIVE
                        Paragraph subtitleBest = new Paragraph("Best Alternative(s)", fontConclusion);
                        subtitleBest.SpacingBefore = 10;
                        subtitleBest.SpacingAfter  = 5;
                        subtitleBest.Alignment     = Element.ALIGN_CENTER;
                        doc.Add(subtitleBest);

                        int numbering = 1;
                        foreach (List <string> conc in conclusion)
                        {
                            if (conc[0] == "Best")
                            {
                                string oneLine = /*numbering + ". " +*/ conc[1] + " (Best criteria: ";
                                foreach (string crit in resultController.bestWorstCriteria(currentTopicId, conc))
                                {
                                    oneLine += crit + ", ";
                                }

                                Paragraph text = new Paragraph(oneLine.Substring(0, oneLine.Length - 2) + ")\n", fontTable);
                                text.Alignment = Element.ALIGN_CENTER;
                                doc.Add(text);
                                numbering++;
                            }
                        }

                        // SUB SUBTITLE WORST ALTERNATIVE
                        Paragraph subtitleWorst = new Paragraph("Worst Alternative(s)", fontConclusion);
                        subtitleWorst.SpacingBefore = 10;
                        subtitleWorst.SpacingAfter  = 5;
                        subtitleWorst.Alignment     = Element.ALIGN_CENTER;
                        doc.Add(subtitleWorst);

                        numbering = 1;
                        foreach (List <string> conc in conclusion)
                        {
                            if (conc[0] == "Worst")
                            {
                                string oneLine = /*numbering + ". " +*/ conc[1] + " (Worst criteria: ";
                                foreach (string crit in resultController.bestWorstCriteria(currentTopicId, conc))
                                {
                                    oneLine += crit + ", ";
                                }

                                Paragraph text = new Paragraph(oneLine.Substring(0, oneLine.Length - 2) + ")\n", fontTable);
                                text.Alignment = Element.ALIGN_CENTER;
                                doc.Add(text);
                                numbering++;
                            }
                        }
                    }

                    doc.Close();

                    // DIALOG
                    int start  = saveFileDialog1.FileName.LastIndexOf('\\') + 1;
                    int length = saveFileDialog1.FileName.Length;

                    var mboxResponse = MessageBox.Show(this, "Successfully exported \"" + saveFileDialog1.FileName.Substring(start, length - start) + "\" to\n" + saveFileDialog1.FileName.Substring(0, start) + "\nDo you want to open the file?", "Export to PDF", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    if (mboxResponse == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(saveFileDialog1.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "An error occured:\n" + ex.Message, "Export to PDF", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
        }
Пример #21
0
 /**
 * Adds extra space.
 * This method should probably be rewritten.
 */
 protected internal void AddSpacing(float extraspace, float oldleading, Font f) {
     if (extraspace == 0) return;
     if (pageEmpty) return;
     if (currentHeight + line.Height + leading > IndentTop - IndentBottom) return;
     leading = extraspace;
     CarriageReturn();
     if (f.IsUnderlined() || f.IsStrikethru()) {
         f = new Font(f);
         int style = f.Style;
         style &= ~Font.UNDERLINE;
         style &= ~Font.STRIKETHRU;
         f.SetStyle(style);
     }
     Chunk space = new Chunk(" ", f);
     space.Process(this);
     CarriageReturn();
     leading = oldleading;
 }
Пример #22
0
        protected Font GetFont(FontEnum mtype)
        {
            Font mFont = null;
            switch (mtype)
            {
                case FontEnum.TitleCenter:
                    mFont = new Font(bfSun, 18);
                    mFont.SetStyle("normal");
                    break;
                case FontEnum.TitleLeft1:
                    mFont = new Font(bfSun, 16);
                    mFont.SetStyle("bold");
                    break;
                case FontEnum.TitleLeft2:
                    mFont = new Font(bfSun, 14);
                    mFont.SetStyle("normal");
                    break;
                case FontEnum.Title12Bold:
                    mFont = new Font(bfSun, 12);
                    mFont.SetStyle("bold");
                    break;
                case FontEnum.TableHeader:
                    mFont = new Font(bfSun, 12);
                    mFont.SetStyle("bold");
                    break;

                case FontEnum.TableIndex:
                    mFont = new Font(bfSun, 11);
                    mFont.SetStyle("bold");
                    break;

                case FontEnum.TableSM:
                    mFont = new Font(bfSun, 9);
                    mFont.SetStyle("normal");
                    break;
                default:
                    mFont = new Font(bfSun, 12);
                    mFont.SetStyle("normal");
                    break;

            }
            return mFont;
        }
Пример #23
0
        public string CreateEvaluation(Evaluation _evaluation)
        {
            string   MEF      = "Monthly Evaluation Form";
            Document document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());


            DateTime Created = DateTime.Now;

            //Checking and Creating folder with name date
            string folderfilter;
            string day;
            string month;
            string months;
            string yaer;


            day    = Created.Day.ToString();
            month  = Created.ToString("MMMM");
            months = Created.ToString("MM");
            yaer   = Created.Year.ToString();

            folderfilter = months + "-" + yaer;


            string path = HttpContext.Current.Server.MapPath("~/Monthly Evaluation Forms/" + folderfilter + "/");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }



            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + _evaluation.LearnerName + " " + MEF + ".pdf", FileMode.Create));



            document.Open();
            string paths = HttpContext.Current.Server.MapPath("~/Images/TalkIT.png");

            iTextSharp.text.Image PNG = iTextSharp.text.Image.GetInstance(paths);
            //iTextSharp.text.Image PNG = iTextSharp.text.Image.GetInstance("C:\\Users\\SMarimi\\Desktop\\Learners-Logging-System\\Learners--Logging-System\\Logging System\\Images\\TalkIT.png");
            PNG.Alignment = iTextSharp.text.Image.ALIGN_RIGHT;

            PNG.ScalePercent(46f);



            Font arial = FontFactory.GetFont("Arial", 12, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);

            Font arials = FontFactory.GetFont("Arial", 14, BaseColor.BLACK);

            arial.SetStyle(Font.BOLD);



            Paragraph info      = new Paragraph();
            Paragraph infos     = new Paragraph();
            Paragraph infoss    = new Paragraph();
            Paragraph infosss   = new Paragraph();
            Paragraph small     = new Paragraph();
            Paragraph smallb    = new Paragraph();
            Paragraph inforhead = new Paragraph();
            Paragraph head      = new Paragraph();
            Paragraph link      = new Paragraph();
            Paragraph sig1      = new Paragraph();
            Paragraph Datesig1  = new Paragraph();

            Paragraph sig2     = new Paragraph();
            Paragraph Datesig2 = new Paragraph();


            inforhead.SpacingBefore = 12;
            head.SpacingAfter       = 14;
            // small.SpacingBefore = 10;

            iTextSharp.text.Font heads = iTextSharp.text.FontFactory.GetFont("Calibri(body)", 12, iTextSharp.text.Font.BOLD);
            heads.SetStyle(Font.UNDERLINE);



            //Sig2
            iTextSharp.text.Font sig12 = iTextSharp.text.FontFactory.GetFont("Brush Script Std", 14, iTextSharp.text.Font.UNDERLINE);
            sig2.Font = sig12;



            head.Font = heads;

            iTextSharp.text.Font contentFont = iTextSharp.text.FontFactory.GetFont("Arial", 13, iTextSharp.text.Font.NORMAL);
            info.Font = contentFont;



            iTextSharp.text.Font SignatureDate = iTextSharp.text.FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.UNDERLINE);
            Datesig1.Font = SignatureDate;



            iTextSharp.text.Font smallfont = iTextSharp.text.FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.ITALIC);
            small.Font = smallfont;

            iTextSharp.text.Font links = iTextSharp.text.FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.ITALIC, iTextSharp.text.BaseColor.BLUE);
            link.Font = links;



            iTextSharp.text.Font smallbold = iTextSharp.text.FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.NORMAL);
            smallbold.SetStyle(Font.BOLD);
            smallb.Font = smallbold;

            iTextSharp.text.Font infohea = iTextSharp.text.FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.NORMAL);
            inforhead.Font = infohea;



            //For name
            iTextSharp.text.Font contentTop = iTextSharp.text.FontFactory.GetFont("Arial", 15, iTextSharp.text.Font.BOLD);
            // contentTop.SetStyle(Font.UNDERLINE);

            info.Font  = contentFont;
            infos.Font = contentTop;

            string line = "           ";

            infos.SetLeading(0.0f, 2.0f);
            //string email1 = "*****@*****.**";
            //string email2 = "*****@*****.**";
            info.Add(line + line + line + line + line + line + line + line + "MONTHLY EVALUATIONS  " + "\r\n");



            head.Add("WORKPLACE MONTHLY EVALAUTION FORM - LEARNER                                                                                                                                     " + "\r\n");

            small.Add("(Learners to complete this evaluation feedback form on a monthly basis; this will be put forward as part of your Portfolio of Evidence)Please fax it monthly to: 086 632 9687/ [email protected]  copy to Project Manager ");

            inforhead.Add("Using the ratings below, please indicate how the workplace provider/mentor performed in relation to all the criteria, and then give an overall rating." + "\r\n");
            info.Add(line + "\r\n");
            infoss.Add(line + line + line + line + line + line + "\r\n");
            infos.Add("Mentor's Name: " + _evaluation.MentorName + line + line + line + line + line + "\r\n");
            info.Add(line + "\r\n");
            infoss.Add(line + line + line + line + line + line + line + line + line + "\r\n");

            infos.Add("Company Name: " + _evaluation.CompanyName + line + line + line + line + line + line + line + line + "\r\n");
            infos.Add("Learner's Name: " + _evaluation.LearnerName + line + line + line + line + line + line + line + "\r\n");
            infos.Add("Month of Evaluation: " + _evaluation.Months + line + line + line + line + line + line + line + line + line + "\r\n");
            infosss.Add(line + line + line + line + line + line + "\r\n");

            PdfPTable tabless = new PdfPTable(1);

            PdfPCell Cellss = new PdfPCell(new Phrase("Ratings:     " + "\r\n" + "                    Excellent - exceptional perfomance" + "\r\n" + "                    Average - good perfomance; proficient" + "\r\n" + "                    Below Average - inadequate perfomance" + "\r\n" + "                    Not Application - perfomance was not observed  ", new Font(arial)));

            tabless.WidthPercentage     = 50;
            Cellss.HorizontalAlignment  = 0;
            tabless.HorizontalAlignment = Element.ALIGN_LEFT;
            tabless.SpacingAfter        = 40;
            tabless.SpacingBefore       = 13;
            // tabless.WidthPercentage = 100;

            tabless.AddCell(Cellss);



            document.Add(info);
            document.Add(PNG);
            document.Add(head);
            document.Add(small);
            document.Add(link);
            document.Add(inforhead);
            document.Add(infoss);
            document.Add(infos);
            document.Add(infosss);
            document.Add(tabless);
            document.Add(smallb);



            PdfPTable table = new PdfPTable(5);

            table.SpacingBefore   = 14;
            table.SpacingAfter    = 13;
            table.WidthPercentage = 100;


            //String
            string rateAS1 = "";
            string rateAS2 = "";
            string rateAS3 = "";
            string rateAS4 = "";
            string rateAS5 = "";

            string rateMS1 = "";
            string rateMS2 = "";
            string rateMS3 = "";
            string rateMS4 = "";
            string rateMS5 = "";

            string rateBS1 = "";
            string rateBS2 = "";
            string rateBS3 = "";
            string rateBS4 = "";
            string rateBS5 = "";

            string rateNA1 = "";
            string rateNA2 = "";
            string rateNA3 = "";
            string rateNA4 = "";
            string rateNA5 = "";

            string finalAS = "";
            string finalMS = "";
            string finalBS = "";
            string finalNA = "";
            string text    = "                                                                                                     FINAL JUDGEMENT";

            if (_evaluation.Rating1 == "Above standard")
            {
                rateAS1 = "Excellent";
            }
            else if (_evaluation.Rating1 == "Meets standard")
            {
                rateMS1 = "Average";
            }
            else if (_evaluation.Rating1 == "Below standard")
            {
                rateBS1 = "Below Average";
            }
            else if (_evaluation.Rating1 == "N/A")
            {
                rateNA1 = "Not Applicable";
            }


            if (_evaluation.Rating2 == "Above standard")
            {
                rateAS2 = "Excellent";
            }
            else if (_evaluation.Rating2 == "Meets standard")
            {
                rateMS2 = "Average";
            }
            else if (_evaluation.Rating2 == "Below standard")
            {
                rateBS2 = "Below Average";
            }
            else if (_evaluation.Rating2 == "N/A")
            {
                rateNA2 = "Not Applicable";
            }


            if (_evaluation.Rating3 == "Above standard")
            {
                rateAS3 = "Excellent";
            }
            else if (_evaluation.Rating3 == "Meets standard")
            {
                rateMS3 = "Average";
            }
            else if (_evaluation.Rating3 == "Below standard")
            {
                rateBS3 = "Below Average";
            }
            else if (_evaluation.Rating3 == "N/A")
            {
                rateNA3 = "Not Applicable";
            }

            if (_evaluation.Rating4 == "Above standard")
            {
                rateAS4 = "Excellent";
            }
            else if (_evaluation.Rating4 == "Meets standard")
            {
                rateMS4 = "Average";
            }
            else if (_evaluation.Rating4 == "Below standard")
            {
                rateBS4 = "Below Average";
            }
            else if (_evaluation.Rating4 == "N/A")
            {
                rateNA4 = "Not Applicable";
            }


            if (_evaluation.Rating5 == "Above standard")
            {
                rateAS5 = "Excellent";
            }
            else if (_evaluation.Rating5 == "Meets standard")
            {
                rateMS5 = "Average";
            }
            else if (_evaluation.Rating5 == "Below standard")
            {
                rateBS5 = "Below Average";
            }
            else if (_evaluation.Rating5 == "N/A")
            {
                rateNA5 = "Not Applicable";
            }

            if (_evaluation.final == "Above standard")
            {
                finalAS = "Excellent";
            }
            else if (_evaluation.final == "Meets standard")
            {
                finalMS = "Average";
            }
            else if (_evaluation.final == "Below standard")
            {
                finalBS = "Below Average";
            }
            else if (_evaluation.final == "N/A")
            {
                finalNA = "Not Applicable";
            }


            float[] widths = new float[] { 65f, 11f, 11f, 11f, 11f };
            table.SetWidths(widths);


            PdfPCell Cell  = new PdfPCell(new Phrase("1. Extended Application Traits", new Font(arial)));
            PdfPCell Cell1 = new PdfPCell(new Phrase("Above standard", new Font(arial)));
            PdfPCell Cell2 = new PdfPCell(new Phrase("Meets standard", new Font(arial)));
            PdfPCell Cell3 = new PdfPCell(new Phrase("Below standard", new Font(arial)));
            PdfPCell Cell4 = new PdfPCell(new Phrase("N/A", new Font(arial)));

            Cell.SetLeading(1.0f, 2.0f);
            Cell1.SetLeading(1.0f, 2.0f);
            Cell2.SetLeading(1.0f, 2.0f);
            Cell3.SetLeading(1.0f, 2.0f);
            Cell4.SetLeading(1.0f, 2.0f);



            Cell.HorizontalAlignment = 1;

            //Does not really have an effect
            Cell1.Rowspan = 1;
            Cell2.Rowspan = 1;
            Cell3.Rowspan = 1;
            Cell4.Rowspan = 1;

            table.AddCell(Cell).BackgroundColor  = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell1).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell2).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell3).BackgroundColor = BaseColor.LIGHT_GRAY;
            table.AddCell(Cell4).BackgroundColor = BaseColor.LIGHT_GRAY;



            //1st Row
            table.AddCell(_evaluation.Trait01);
            table.AddCell(rateAS1);
            table.AddCell(rateMS1);
            table.AddCell(rateBS1);
            table.AddCell(rateNA1);



            //2nd Row

            table.AddCell(_evaluation.Trait02);
            table.AddCell(rateAS2);
            table.AddCell(rateMS2);
            table.AddCell(rateBS2);
            table.AddCell(rateNA2);



            //3rd Row
            table.AddCell(_evaluation.Trait03);
            table.AddCell(rateAS3);
            table.AddCell(rateMS3);
            table.AddCell(rateBS3);
            table.AddCell(rateNA3);



            //4th Row

            table.AddCell(_evaluation.Trait04);
            table.AddCell(rateAS4);
            table.AddCell(rateMS4);
            table.AddCell(rateBS4);
            table.AddCell(rateNA4);



            //5th Row

            table.AddCell(_evaluation.Trait05);
            table.AddCell(rateAS5);
            table.AddCell(rateMS5);
            table.AddCell(rateBS5);
            table.AddCell(rateNA5);


            //6th Row

            table.AddCell(text);
            table.AddCell(finalAS);
            table.AddCell(finalMS);
            table.AddCell(finalBS);
            table.AddCell(finalNA);


            document.Add(table);


            Paragraph content = new Paragraph();

            content.Add("2. Please supply us with comments that further describe the environment at your workplace provider.");
            document.Add(content);

            PdfPTable tables = new PdfPTable(1);

            float[] widthss = new float[] { 200f };
            tables.SetWidths(widthss);

            PdfPCell Cells = new PdfPCell(new Phrase("", new Font(arial)));

            // Cells.Colspan = 2;
            Cells.Rowspan = 2;

            Cells.HorizontalAlignment = 1;
            tables.SpacingAfter       = 9;
            tables.SpacingBefore      = 13;
            tables.WidthPercentage    = 100;

            tables.AddCell(Cells);
            if (String.IsNullOrEmpty(_evaluation.Comments))
            {
                _evaluation.Comments = "\r\n" + "\r\n" + "__________________________________________________________________________________________________________________" + "\r\n" + "\r\n" + "\r\n" + "__________________________________________________________________________________________________________________" + "\r\n" + "\r\n" + "\r\n" + "__________________________________________________________________________________________________________________" + "\r\n" + "\r\n" + "\r\n" + "__________________________________________________________________________________________________________________" + "\r\n" + "\r\n" + "\r\n" + "\r\n";
            }

            // string mentorName = "M.Huna";
            string   date;
            DateTime Current = DateTime.Now;

            date = Current.DayOfYear.ToString();



            Chunk     glue = new Chunk(new VerticalPositionMark());
            Paragraph p    = new Paragraph();


            p.SetLeading(0.0f, 3.0f);
            p.SetLeading(0.0f, 3.0f);



            if (_evaluation.fontStyle == "Informal Roman")
            {
                Phrase f1 = new Phrase();


                //string font1 = Path.Combine("Fonts", "INFROMAN.TTF");
                //   string fontas = Path.GetDirectoryName("~/Fonts/INFROMAN.TTF");
                string fontas = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/INFROMAN.TTF");

                BaseFont baseFont1 = BaseFont.CreateFont(fontas, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                //  BaseFont baseFont1 = BaseFont.CreateFont("Fonts/INFROMAN.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(fontas, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Bradley Hand ITC")
            {
                Phrase f12 = new Phrase();

                string font1 = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/BRADHITC.TTF");
                //    string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "BRADHITC.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f12.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f12);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string font = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                //    string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Blackadder ITC")
            {
                Phrase f13 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string font1 = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ITCBLKAD.TTF");
                //   string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ITCBLKAD.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f13.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f13);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Brush Script MT Italic")
            {
                Phrase f14 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //  string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "BRUSHSCI.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/BRUSHSCI.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f14.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f14);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Edwardian Script ITC")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ITCEDSCR.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ITCEDSCR.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Mistral")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "MISTRAL.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/MISTRAL.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Place Script MT")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //   string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "PALSCRI.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/PALSCRI.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Chiller")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "CHILLER.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/CHILLER.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Curlz MT")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "CURLZ___.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/CURLZ___.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "French Script MT")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "FRSCRIPT.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/FRSCRIPT.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //  string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Rage Italic")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //      string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "RAGE.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/RAGE.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else if (_evaluation.fontStyle == "Arial")
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                //  string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ARIAL.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }
            else
            {
                Phrase f1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");
                string   font1     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/ARIAL.TTF");
                BaseFont baseFont1 = BaseFont.CreateFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                f1.Add(new Chunk(_evaluation.LearnerSignature, new Font(FontFactory.GetFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));

                p.Add("Leaner's Signature: ");
                p.Add(f1);
                p.Add("  Date: " + _evaluation.DateLearnerSigned.Value.ToShortDateString());


                //Date Mentor Signed

                DateTime dt    = DateTime.Now;
                string   dates = dt.ToString("yyyy/mm/dd");
                //For Sig Monday - Mentor
                Phrase s1 = new Phrase();
                //string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                // string font = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "VLADIMIR.ttf");
                string   font     = System.Web.HttpContext.Current.Server.MapPath("~/Fonts/VLADIMIR.TTF");
                BaseFont baseFont = BaseFont.CreateFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                s1.Add(new Chunk("M.Huna", new Font(FontFactory.GetFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 16))));
                //table.AddCell(s1);

                p.Add(new Chunk(glue));
                p.Add("Mentor's Signature: ");
                p.Add(s1);
                //    p.Add(s1);
                p.Add("  Date: " + dates);
                tables.AddCell(_evaluation.Comments);

                document.Add(tables);
                document.Add(p);
            }

            document.Close();

            if (_evaluation.Preview == "Yes")
            {
                string pathss = HttpContext.Current.Server.MapPath("~/Monthly Evaluation Forms/" + folderfilter + "/");
                System.Diagnostics.Process.Start(pathss + _evaluation.LearnerName + " " + MEF + ".pdf");
            }


            try
            {
                return("Successfully Submitted Monthly Evaluation Form " + _evaluation.LearnerName);
            }
            catch (Exception es)
            {
                throw es;
            }
        }
        public ActionResult Vendas(FormCollection form)
        {
            if (form.HasKeys())
            {
                int cliente = int.Parse(form["txtCliente"]);
                int produto = int.Parse(form["txtProduto"]);

                List<Venda> vendas = Venda.Listar();

                if (cliente > 0)
                {
                    vendas = vendas.Where(v => v.CodCliente == cliente).ToList();
                }

                if (produto > 0)
                {
                    vendas = vendas.Where(v => v.VendaProduto.FirstOrDefault(vp => vp.CodProduto == produto) != null).ToList();
                }

                if (!String.IsNullOrWhiteSpace(form["txtDataInicio"]))
                {
                    DateTime data = DateTime.Parse(form["txtDataInicio"], new CultureInfo("pt-BR"));
                    vendas = vendas.Where(v => v.DtVenda >= data).ToList();
                }

                if (!String.IsNullOrWhiteSpace(form["txtDataTermino"]))
                {
                    DateTime data = DateTime.Parse(form["txtDataTermino"] + " 23:59:59", new CultureInfo("pt-BR"));
                    vendas = vendas.Where(v => v.DtVenda <= data).ToList();
                }

                if (vendas.Count == 0)
                {
                    TempData["Erro"] = "Não há vendas no filtro especificado";
                    return RedirectToAction("Vendas");
                }

                vendas = vendas.OrderBy(v => v.DtVenda).ToList();

                // PDF

                MemoryStream memStream = new MemoryStream();
                Document document = new Document(PageSize.A4.Rotate(), 36, 36, 54, 36);
                PdfWriter writer = PdfWriter.GetInstance(document, memStream);
                writer.CloseStream = false;
                writer.PageEvent = new PaginacaoPdfPageEventHelper();

                document.Open();

                Paragraph titulo = new Paragraph("Relatório de Vendas");
                titulo.Font.Size = 18;
                titulo.Font.SetStyle(Font.BOLD);
                document.Add(titulo);

                document.Add(Chunk.NEWLINE);

                if (!String.IsNullOrWhiteSpace(form["txtDataInicio"]) || !String.IsNullOrWhiteSpace(form["txtDataTermino"]))
                {
                    string periodo = "";
                    if (!String.IsNullOrWhiteSpace(form["txtDataInicio"]) && !String.IsNullOrWhiteSpace(form["txtDataTermino"]))
                    {
                        periodo = $"de {form["txtDataInicio"]} até {form["txtDataTermino"]}";
                    }
                    else if (!String.IsNullOrWhiteSpace(form["txtDataInicio"]))
                    {
                        periodo = $"de {form["txtDataInicio"]} até {DateTime.Today.ToString("dd/MM/yyyy")}";
                    }
                    else if (!String.IsNullOrWhiteSpace(form["txtDataTermino"]))
                    {
                        periodo = $"até {form["txtDataTermino"]}";
                    }
                    Paragraph filtroPeriodo = new Paragraph($"Período: {periodo}");
                    filtroPeriodo.Font.SetStyle(Font.BOLD);
                    document.Add(filtroPeriodo);
                }

                string descricao = "Todos";
                if (produto > 0)
                {
                    descricao = Produto.ObterPorCodigo(produto).Descricao;
                }
                Paragraph filtroProduto = new Paragraph($"Produto: {descricao}");
                filtroProduto.Font.SetStyle(Font.BOLD);
                document.Add(filtroProduto);

                string nome = "Todos";
                if (cliente > 0)
                {
                    nome = Cliente.ObterPorCodigo(cliente).Pessoa.Nome;
                }
                Paragraph filtroCliente = new Paragraph($"Cliente: {nome}");
                filtroCliente.Font.SetStyle(Font.BOLD);
                document.Add(filtroCliente);

                document.Add(Chunk.NEWLINE);

                PdfPTable tabela = new PdfPTable(6);
                tabela.SetWidths(new float[] { 1, 1, 1, 1, 1, 1 });
                tabela.TotalWidth = document.PageSize.Width - document.RightMargin - document.LeftMargin;
                tabela.LockedWidth = true;
                tabela.DefaultCell.MinimumHeight = 20;
                tabela.DefaultCell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;
                tabela.DefaultCell.BorderWidthBottom = 2;
                Font fontBold = new Font();
                fontBold.SetStyle(Font.BOLD);
                tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                tabela.AddCell(new Phrase("Data", fontBold));
                tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                tabela.AddCell(new Phrase("Cliente", fontBold));
                tabela.AddCell(new Phrase("Produto", fontBold));
                tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                tabela.AddCell(new Phrase("Quantidade", fontBold));
                tabela.AddCell(new Phrase("Preço Unitário", fontBold));
                tabela.AddCell(new Phrase("Valor Total", fontBold));
                tabela.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                tabela.DefaultCell.BorderWidthBottom = 1;

                foreach (Venda venda in vendas)
                {
                    foreach (VendaProduto vendaProduto in venda.VendaProduto)
                    {
                        if (produto > 0 && vendaProduto.CodProduto != produto)
                        {
                            continue;
                        }
                        tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                        tabela.AddCell(venda.DtVenda.ToString("dd/MM/yyyy"));
                        tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        tabela.AddCell(venda.Cliente.Pessoa.Nome);
                        tabela.AddCell(vendaProduto.Produto.Descricao);
                        tabela.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        tabela.AddCell(vendaProduto.QuantidadeUnidade);
                        tabela.AddCell(vendaProduto.PrecoUnitario.ToString("C", new System.Globalization.CultureInfo("pt-BR")));
                        tabela.AddCell(vendaProduto.Valor.ToString("C", new System.Globalization.CultureInfo("pt-BR")));
                    }
                }

                document.Add(tabela);

                document.Add(Chunk.NEWLINE);

                PdfPTable tabelaTotais = new PdfPTable(2);
                tabelaTotais.SetWidths(new float[] { 1, 1 });
                tabelaTotais.TotalWidth = document.PageSize.Width - document.RightMargin - document.LeftMargin;
                tabelaTotais.LockedWidth = true;
                tabelaTotais.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                tabelaTotais.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                PdfPCell totais = new PdfPCell(new Phrase("TOTAIS", fontBold));
                totais.Colspan = 2;
                totais.Border = Rectangle.BOTTOM_BORDER;
                totais.HorizontalAlignment = Element.ALIGN_CENTER;
                tabelaTotais.AddCell(totais);
                tabelaTotais.AddCell(new Phrase("Quantidades", fontBold));
                tabelaTotais.AddCell(new Phrase("Valores", fontBold));

                PdfPTable tabelaQuantidades = new PdfPTable(1);
                tabelaQuantidades.SetWidths(new float[] { 1 });
                tabelaQuantidades.TotalWidth = (document.PageSize.Width - document.RightMargin - document.LeftMargin) / 2;
                tabelaQuantidades.LockedWidth = true;
                tabelaQuantidades.DefaultCell.Border = Rectangle.NO_BORDER;
                tabelaQuantidades.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                Dictionary<string, double> totaisQuantidadePorUnidade = new Dictionary<string, double>();
                foreach (Venda venda in vendas)
                {
                    foreach (string unidade in venda.QuantidadePorUnidade.Keys)
                    {
                        if (totaisQuantidadePorUnidade.ContainsKey(unidade))
                        {
                            totaisQuantidadePorUnidade[unidade] += venda.QuantidadePorUnidade[unidade];
                        }
                        else
                        {
                            totaisQuantidadePorUnidade[unidade] = venda.QuantidadePorUnidade[unidade];
                        }
                    }
                }
                foreach (string unidade in totaisQuantidadePorUnidade.Keys)
                {
                    tabelaQuantidades.AddCell($"{totaisQuantidadePorUnidade[unidade]} {unidade}\n");
                }
                tabelaTotais.AddCell(tabelaQuantidades);

                PdfPTable tabelaValores = new PdfPTable(2);
                tabelaValores.SetWidths(new float[] { 3, 1 });
                tabelaValores.TotalWidth = (document.PageSize.Width - document.RightMargin - document.LeftMargin) / 2;
                tabelaValores.LockedWidth = true;
                tabelaValores.DefaultCell.Border = Rectangle.NO_BORDER;
                tabelaValores.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                tabelaValores.AddCell(new Phrase("Desconto Total:", fontBold));
                tabelaValores.AddCell(new Phrase(vendas.Sum(v => v.Desconto)?.ToString("C", new System.Globalization.CultureInfo("pt-BR")) ?? "R$ 0,00"));

                tabelaValores.AddCell(new Phrase("Valor Total (com desconto):", fontBold));
                tabelaValores.AddCell(new Phrase(vendas.Sum(v => v.ValorTotal).ToString("C", new System.Globalization.CultureInfo("pt-BR"))));

                tabelaValores.AddCell(new Phrase("Valor Total (sem desconto):", fontBold));
                tabelaValores.AddCell(new Phrase(vendas.Sum(v => v.ValorTotalSemDesconto).ToString("C", new System.Globalization.CultureInfo("pt-BR"))));

                tabelaTotais.AddCell(tabelaValores);

                document.Add(tabelaTotais);

                document.Close();

                Response.AddHeader("Content-Disposition", "attachment; filename=\"relatorio-vendas-" + DateTime.Today.ToString("dd-MM-yyyy") + ".pdf\"");

                byte[] buf = new byte[memStream.Position];
                memStream.Position = 0;
                memStream.Read(buf, 0, buf.Length);

                return new BinaryContentResult(buf, "application/pdf");
            }

            return RedirectToAction("Vendas");
        }
Пример #25
0
        public void CreatePdfForStoreRecomendations()
        {
            List <string> storeNames = getAllStoreNames();
            List <Tuple <string, string> > tuples = getAllProductsTupleNameKey();
            string text = "";

            PdfPTable table = new PdfPTable(2);

            PdfPCell cell = new PdfPCell(new Phrase("Item Name"));

            cell.Colspan = 1;

            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

            table.AddCell(cell);
            PdfPCell cell2 = new PdfPCell(new Phrase("Store Name"));

            cell2.Colspan = 1;

            cell2.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

            table.AddCell(cell2);
            foreach (var tuple in tuples)
            {
                float  bestScore = 0;
                string storeName = "";
                foreach (var store in storeNames)
                {
                    ModelInput sampleData = new ModelInput()
                    {
                        Store_name = store,
                        SerialKey  = tuple.Item1,
                    };
                    var predictionResult = ConsumeModel.Predict(sampleData);
                    if (predictionResult.Score >= bestScore || bestScore == 0)
                    {
                        bestScore = predictionResult.Score;
                        storeName = store;
                    }
                }
                table.AddCell(tuple.Item2);
                table.AddCell(storeName);
            }
            Document doc = new Document(PageSize.A4, 7f, 5f, 5f, 0f);

            doc.AddTitle("Machine Learning results");
            PdfWriter.GetInstance(doc, new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Recommended Stores.pdf", FileMode.Create));
            doc.Open();
            //     Paragraph p1 = new Paragraph(text);
            //   doc.Add(p1);

            doc.Add(table);
            Font x = FontFactory.GetFont("nina fett");

            x.Size = 19;

            x.SetStyle("Italic");

            x.SetColor(0, 42, 255);


            Paragraph c2 = new Paragraph(@"Based on our recommendations for which products to buy in which store", x);

            c2.IndentationLeft = 30;
            doc.Add(c2);


            doc.Close();
        }
Пример #26
0
        private void creerPDFlisteactives(bool estprotect)
        {
            int i = 0;

            lesActivites = activitechoisie.InitActivite();
            listeType    = type.InitType();
            recupDates();

            try
            {
                string   nompdf = Properties.Settings.Default["savePDFCommun"].ToString(); // Récupère le chemin
                Document doc    = new Document();
                if (estprotect == true)
                {
                    nompdf += "listeactivitee.pdf";
                }
                else
                {
                    nompdf += "listeactivitep.pdf";
                }
                PdfWriter listeActPDF = PdfWriter.GetInstance(doc, new FileStream(nompdf, FileMode.Create, FileAccess.Write));
                if (estprotect == true)
                {
                    System.Text.UTF8Encoding enconding = new System.Text.UTF8Encoding();                                                       // Création du norme d'encodage
                    listeActPDF.SetEncryption(null, enconding.GetBytes("123456789"), PdfWriter.AllowScreenReaders, PdfWriter.STRENGTH128BITS); // Encryptage du fichier PDF qui autorise seulement la lecture de celui-ci
                }
                doc.Open();
                Paragraph paragraph = new Paragraph();
                Phrase    titre     = new Phrase("Listes des activités de Joach Autrement", FontFactory.GetFont(FontFactory.COURIER, 20));
                paragraph.Alignment    = Element.ALIGN_CENTER;
                paragraph.SpacingAfter = 15;
                paragraph.Add(titre);
                doc.Add(paragraph);

                lesDates = lesDates.OrderBy(x => x.Date).ToList();
                foreach (DatePDF d in lesDates)
                {
                    d.LesActivites = d.LesActivites.OrderBy(x => x.IdType).ThenBy(x => x.Heuredebut).ToList();

                    foreach (Type untype in listeType)
                    {
                        Paragraph p = new Paragraph();
                        Phrase    t = new Phrase(d.Date.ToLongDateString().ToUpper() + " " + d.Libelle + "\n" + untype.Libelle, FontFactory.GetFont(FontFactory.COURIER, 20));
                        p.Add(t);
                        p.Alignment    = Element.ALIGN_CENTER;
                        p.SpacingAfter = 15;
                        doc.NewPage();
                        doc.Add(p);

                        foreach (Activite act in d.LesActivites)
                        {
                            if (act.IdType == untype.Id)
                            {
                                i++;
                                iTextSharp.text.Font gras = new iTextSharp.text.Font();
                                string typeecriture       = "bold";
                                gras.SetStyle(typeecriture);
                                iTextSharp.text.Font italique = new iTextSharp.text.Font();
                                typeecriture = "italic";
                                italique.SetStyle(typeecriture);
                                PdfPTable tableactivite = new PdfPTable(2); //Table regroupant toutes les autres tables pour les infos de cette activité
                                float[]   taillecolonnetableactivite = { 30, 70 };
                                tableactivite.SetWidths(taillecolonnetableactivite);
                                tableactivite.DefaultCell.Border            = iTextSharp.text.Rectangle.NO_BORDER;
                                tableactivite.DefaultCell.BorderWidthTop    = 2;
                                tableactivite.DefaultCell.BorderWidthBottom = 2;
                                PdfPTable tablecodeheure = new PdfPTable(1);
                                PdfPTable Colonnedroite  = new PdfPTable(1);
                                Colonnedroite.DefaultCell.BorderWidthTop    = iTextSharp.text.Rectangle.NO_BORDER;
                                Colonnedroite.DefaultCell.BorderWidthRight  = iTextSharp.text.Rectangle.NO_BORDER;
                                Colonnedroite.DefaultCell.BorderWidthBottom = iTextSharp.text.Rectangle.NO_BORDER;
                                PdfPTable tablelibelledescription = new PdfPTable(1);
                                PdfPTable tableinfodivers         = new PdfPTable(3);
                                PdfPCell  infoCode = new PdfPCell();
                                Phrase    infocode = new Phrase(act.Code, gras);
                                infoCode.BorderWidth = PdfPCell.NO_BORDER;
                                infoCode.AddElement(infocode);
                                Phrase infoheures = new Phrase(act.Heuredebut.ToShortTimeString() + " - " + act.Heurefin.ToShortTimeString());
                                infoCode.AddElement(infoheures);
                                tablecodeheure.AddCell(infoCode);
                                tableactivite.AddCell(tablecodeheure);
                                PdfPCell infolibelledescri = new PdfPCell();
                                Phrase   infolibelle       = new Phrase(act.Libelle, gras);
                                infolibelledescri.BorderWidth = PdfPCell.NO_BORDER;
                                infolibelledescri.AddElement(infolibelle);
                                Phrase infoentetelibelledescri = new Phrase(act.EnteteDescription, FontFactory.GetFont(BaseFont.TIMES_ITALIC));
                                infolibelledescri.AddElement(infoentetelibelledescri);
                                Phrase infodescription = new Phrase(act.Description);
                                infolibelledescri.AddElement(infodescription);
                                tablelibelledescription.AddCell(infolibelledescri);
                                Colonnedroite.AddCell(tablelibelledescription);
                                PdfPCell prerequisclasse = new PdfPCell(new Phrase(act.Restriction));
                                prerequisclasse.BorderWidth = PdfPCell.NO_BORDER;
                                tableinfodivers.AddCell(prerequisclasse);
                                PdfPCell  infoNombreeleve  = new PdfPCell();
                                Paragraph infonombreelevep = new Paragraph(new Phrase(act.Nombreplaces + " élèves"));
                                infoNombreeleve.BorderWidth = PdfPCell.NO_BORDER;
                                infonombreelevep.Alignment  = Element.ALIGN_CENTER;
                                infoNombreeleve.AddElement(infonombreelevep);
                                tableinfodivers.AddCell(infoNombreeleve);
                                PdfPCell  infoSalle  = new PdfPCell();
                                Paragraph infosallep = new Paragraph(new Phrase(act.Salle));
                                infoSalle.BorderWidth = PdfPCell.NO_BORDER;
                                infosallep.Alignment  = Element.ALIGN_CENTER;
                                infoSalle.AddElement(infosallep);
                                tableinfodivers.AddCell(infoSalle);
                                Colonnedroite.AddCell(tableinfodivers);
                                tableactivite.AddCell(Colonnedroite);
                                doc.Add(tableactivite);
                            }
                        }
                    }
                }
                doc.Close();
            }
            catch (System.IO.IOException err)// gestion des erreurs
            {
                MessageBox.Show("Erreur pdf: " + err, "Problème connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #27
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            // 来自:https://blog.csdn.net/jsjpanxiaoyu/article/details/52922119
            //Document:(文档)生成pdf必备的一个对象,生成一个Document示例
            Document document = new Document(PageSize.A4, 30, 30, 5, 5);
            //为该Document创建一个Writer实例:
            PdfWriter.GetInstance(document, new FileStream("e://" + "Chap0101.pdf", FileMode.Create));
            //打开当前Document
            document.Open();
            //为当前Document添加内容:
            document.Add(new Paragraph("Hello World"));
            //另起一行。有几种办法建立一个段落,如:
            Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
            Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
            //所有有些对象将被添加到段落中:
            p1.Add("you can add string here\n\t");
            p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
            document.Add(p1); document.Add(p2); document.Add(p3);

            //创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
            Chunk chunk = new Chunk("Hello world", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
            document.Add(chunk);
            //如果你希望一些块有下划线或删除线,你可以通过改变字体风格简单做到:
            Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
            Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.STRIKETHRU));
            //改变块的背景
            chunk2.SetBackground(new iTextSharp.text.Color(0xFF, 0xFF, 0x00));
            //上标/下标
            chunk1.SetTextRise(5);
            document.Add(chunk1);
            document.Add(chunk2);

            //外部链接示例:
            Anchor anchor = new Anchor("website", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED, new iTextSharp.text.Color(0, 0, 255)));

            anchor.Reference = "http://itextsharp.sourceforge.net/";
            anchor.Name = "website";
            //内部链接示例:
            Anchor anchor1 = new Anchor("This is an internal link\n\n");
            anchor1.Name = "link1";
            Anchor anchor2 = new Anchor("Click here to jump to the internal link\n\f");
            anchor2.Reference = "#link1";
            document.Add(anchor); document.Add(anchor1); document.Add(anchor2);

            //排序列表示例:
            List list = new List(true, 20);
            list.Add(new iTextSharp.text.ListItem("First line"));
            list.Add(new iTextSharp.text.ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
            list.Add(new iTextSharp.text.ListItem("Third line"));
            document.Add(list);

            //文本注释:
            Annotation a = new Annotation("authors", "Maybe its because I wanted to be an author myself that I wrote iText.");
            document.Add(a);

            //包含页码没有任何边框的页脚。
            HeaderFooter footer = new HeaderFooter(new Phrase("This is page: "), true);
            footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
            document.Footer = footer;

            //Chapter对象和Section对象自动构建一个树:
            iTextSharp.text.Font f1 = new iTextSharp.text.Font();
            f1.SetStyle(iTextSharp.text.Font.BOLD);
            Paragraph cTitle = new Paragraph("This is chapter 1", f1);
            Chapter chapter = new Chapter(cTitle, 1);
            Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", f1);
            Section section = chapter.AddSection(sTitle, 1);
            document.Add(chapter);

            ////构建了一个简单的表:

            //iTextSharp.text.Table aTable = new iTextSharp.text.Table(4, 4);

            //aTable.AutoFillEmptyCells = true;

            //aTable.AddCell("2.2", new Point(2, 2));

            //aTable.AddCell("3.3", new Point(3, 3));

            //aTable.AddCell("2.1", new Point(2, 1));

            //aTable.AddCell("1.3", new Point(1, 3));

            //document.Add(aTable);

            ////构建了一个不简单的表:

            //iTextSharp.text.Table table = new iTextSharp.text.Table(3);

            //table.BorderWidth = 1;

            //table.BorderColor = new iTextSharp.text.Color(0, 0, 255);

            //table.Cellpadding = 5;

            //table.Cellspacing = 5;

            //Cell cell = new Cell("header");

            //cell.Header = true;

            //cell.Colspan = 3;

            //table.AddCell(cell);

            //cell = new Cell("example cell with colspan 1 and rowspan 2");

            //cell.Rowspan = 2;

            //cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);

            //table.AddCell(cell);

            //table.AddCell("1.1");

            //table.AddCell("2.1");

            //table.AddCell("1.2");

            //table.AddCell("2.2");

            //table.AddCell("cell test1");

            //cell = new Cell("big cell");

            //cell.Rowspan = 2;

            //cell.Colspan = 2;

            //cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
            //table.AddCell(cell);
            //table.AddCell("cell test2");
            //// 改变了单元格“big cell”的对齐方式:
            //cell.HorizontalAlignment = Element.ALIGN_CENTER;
            //cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            //document.Add(table);

            //关闭Document

            document.Close();
        }
Пример #28
0
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            // create the fonts that are to be used
            // first the hightlight or Bold font
            fontTxtBold = FontFactory.GetFont(_boldFont.fontFamily, _boldFont.fontSize, _boldFont.foreColor);
            if (_boldFont.isBold)
            {
                fontTxtBold.SetStyle(Font.BOLD);
            }
            if (_boldFont.isItalic)
            {
                fontTxtBold.SetStyle(Font.ITALIC);
            }
            if (_boldFont.isUnderlined)
            {
                fontTxtBold.SetStyle(Font.UNDERLINE);
            }

            // next the normal font
            fontTxtRegular = FontFactory.GetFont(_normalFont.fontFamily, _normalFont.fontSize, _normalFont.foreColor);
            if (_normalFont.isBold)
            {
                fontTxtRegular.SetStyle(Font.BOLD);
            }
            if (_normalFont.isItalic)
            {
                fontTxtRegular.SetStyle(Font.ITALIC);
            }
            if (_normalFont.isUnderlined)
            {
                fontTxtRegular.SetStyle(Font.UNDERLINE);
            }

            // now build the header and footer templates
            try
            {
                float pageHeight = document.PageSize.Height;
                float pageWidth  = document.PageSize.Width;

                _headerWidth = (int)pageWidth - ((int)_rightMargin + (int)_leftMargin);
                _footerWidth = _headerWidth;

                if (hasHeader)
                {
                    // i basically dummy build the headers so i can trial fit them and see how much space they take.
                    float[] widths = new float[1] {
                        90f
                    };

                    PdfPTable hdrTable = new PdfPTable(1);
                    hdrTable.TotalWidth      = document.PageSize.Width - (_leftMargin + _rightMargin);
                    hdrTable.WidthPercentage = 95;
                    hdrTable.SetWidths(widths);
                    hdrTable.LockedWidth = true;

                    _headerHeight = 0;

                    for (int hdrIdx = 0; hdrIdx < (_headerLines.Length < 2 ? 2 : _headerLines.Length); hdrIdx++)
                    {
                        Paragraph hdrPara = new Paragraph(5, hdrIdx > _headerLines.Length - 1 ? string.Empty : _headerLines[hdrIdx], (hdrIdx > 0 ? fontTxtRegular : fontTxtBold));
                        PdfPCell  hdrCell = new PdfPCell(hdrPara);
                        hdrCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        hdrCell.Border = 0;
                        hdrTable.AddCell(hdrCell);
                        _headerHeight = _headerHeight + (int)hdrTable.GetRowHeight(hdrIdx);
                    }

                    // iTextSharp underestimates the size of each line so fudge it a little
                    // this gives me 3 extra lines to play with on the spacing
                    _headerHeight = _headerHeight + (_fontPointSize * 3);
                }
                else
                {
                    _headerHeight = _fontPointSize * 3;
                }

                if (hasFooter)
                {
                    _footerHeight = (_fontPointSize * 2);
                }
                else
                {
                    _footerHeight = (_fontPointSize);
                }

                document.SetMargins(_leftMargin, _rightMargin, (_topMargin + _headerHeight), _footerHeight);

                cb = writer.DirectContent;

                if (hasHeader)
                {
                    headerTemplate = cb.CreateTemplate(_headerWidth, _headerHeight);
                }

                if (hasFooter)
                {
                    footerTemplate = cb.CreateTemplate(_footerWidth, _footerHeight);
                }
            }
            catch (DocumentException de)
            {
            }
            catch (System.IO.IOException ioe)
            {
            }
        }
Пример #29
0
        public void CreatePdfForDayRecomendations()
        {
            List <Tuple <string, string> > tuples = getAllProductsTupleNameKey();
            List <DayOfWeek> days = new List <DayOfWeek>();

            days.Add(DayOfWeek.Sunday);
            days.Add(DayOfWeek.Monday);
            days.Add(DayOfWeek.Tuesday);
            days.Add(DayOfWeek.Wednesday);
            days.Add(DayOfWeek.Thursday);
            days.Add(DayOfWeek.Friday);
            days.Add(DayOfWeek.Saturday);

            PdfPTable table = new PdfPTable(2);

            PdfPCell cell = new PdfPCell(new Phrase("Item Name"));

            cell.Colspan = 1;

            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

            table.AddCell(cell);
            PdfPCell cell2 = new PdfPCell(new Phrase("Best Day"));

            cell2.Colspan = 1;

            cell2.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

            table.AddCell(cell2);
            foreach (var tuple in tuples)
            {
                int       quantity    = 0;
                int       maxQuantity = 0;
                DayOfWeek dayOfWeek   = new DayOfWeek();
                foreach (DayOfWeek day in days)
                {
                    List <Item> items = idal.getAllItems(y => y.Date_of_purchase.DayOfWeek == day && y.SerialKey == tuple.Item1);
                    foreach (var item in items)
                    {
                        quantity += item.Quantity;
                    }
                    if (quantity > maxQuantity)
                    {
                        maxQuantity = quantity;
                        dayOfWeek   = day;
                    }
                }
                table.AddCell(tuple.Item2);
                table.AddCell(dayOfWeek.ToString());
            }
            Document doc = new Document(PageSize.A4, 7f, 5f, 5f, 0f);

            doc.AddTitle("Machine Learning results");
            PdfWriter.GetInstance(doc, new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Recommended Days.pdf", FileMode.Create));
            doc.Open();
            //     Paragraph p1 = new Paragraph(text);
            //   doc.Add(p1);

            doc.Add(table);
            Font x = FontFactory.GetFont("nina fett");

            x.Size = 19;

            x.SetStyle("Italic");

            x.SetColor(0, 42, 255);


            Paragraph c2 = new Paragraph(@"Based on our recommendations for which products to buy on which  day", x);

            c2.IndentationLeft = 30;
            doc.Add(c2);


            doc.Close();
        }
Пример #30
0
        public void addbody()
        {
            DateTime date = DateTime.Now;
            string   Date = Convert.ToString(date);

            foreach (Student s in SelectedStudents)
            {
                iTextSharp.text.Font f     = FontFactory.GetFont("Tahoma", 7f, 1);
                PdfPCell             pdfcl = new PdfPCell(new Phrase(s.ARN, f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                PdfPCell pdfcl1 = new PdfPCell(new Phrase(s.Name, f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                PdfPCell pdfcl2 = new PdfPCell(new Phrase(s.aggregate.ToString(), f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                PdfPCell pdfcl3 = new PdfPCell(new Phrase(s.department, f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                PdfPCell pdfcl4 = new PdfPCell(new Phrase(s.Email, f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                PdfPCell pdfcl5 = new PdfPCell(new Phrase(s.Category, f));
                pdfcl.BorderColor         = BaseColor.DARK_GRAY;
                pdfcl.ExtraParagraphSpace = 0;

                pdfcl.BorderWidth  = 1f;
                pdfcl1.BorderWidth = 1f;
                pdfcl2.BorderWidth = 1f;
                pdfcl3.BorderWidth = 1f;
                pdfcl4.BorderWidth = 1f;
                pdfcl5.BorderWidth = 1f;

                pdfcl.BorderColor  = BaseColor.GRAY;
                pdfcl2.BorderColor = BaseColor.GRAY;
                pdfcl1.BorderColor = BaseColor.GRAY;
                pdfcl3.BorderColor = BaseColor.GRAY;
                pdfcl4.BorderColor = BaseColor.GRAY;
                pdfcl5.BorderColor = BaseColor.GRAY;



                pdft.AddCell(pdfcl);
                pdft.AddCell(pdfcl1);
                pdft.AddCell(pdfcl2);
                pdft.AddCell(pdfcl3);
                pdft.AddCell(pdfcl4);
                pdft.AddCell(pdfcl5);
            }

            iTextSharp.text.Font ff = FontFactory.GetFont("Arial", 7f);
            ff.IsBold();
            iTextSharp.text.Font fff = FontFactory.GetFont("Arial", 7f);
            fff.SetStyle(4);
            PdfPCell pdfcl11 = new PdfPCell(new Phrase("@ all copy Rights reserved, www.uet.edu.pk"));

            pdfcl11.Colspan = 3;
            pdfcl11.Border  = 0;
            PdfPCell pdfcl12 = new PdfPCell(new Phrase(Date));

            pdfcl12.Colspan    = 3;
            pdfcl12.Border     = 0;
            pdfcl11.PaddingTop = 50f;
            pdfcl12.PaddingTop = 50f;


            pdft.AddCell(pdfcl11);
            pdft.AddCell(pdfcl12);
        }
        public static void AddDataToPdf(SupermarketContext db)
        {
            Document doc = new Document();
            PdfAWriter.GetInstance(doc, new FileStream(@"../../.." + "/Aggregated-Sales-Report.pdf", FileMode.Create));
            doc.Open();

            PdfPTable table = new PdfPTable(5);
            Font fontBold = new Font(Font.FontFamily.HELVETICA, 14f);
            fontBold.SetStyle("bold");
            Font fontNormal = new Font(Font.FontFamily.HELVETICA, 12f);

            PdfPCell header = new PdfPCell(new Phrase("Aggregated Sales Report", fontBold));
            header.Colspan = 5;
            header.HorizontalAlignment = 1;
            table.AddCell(header);

            using (db)
            {
                var dates =
                    (from d in db.SalesReports
                     select d.ReportDate).Distinct();

                decimal grandTotal = 0;

                foreach (var date in dates)
                {
                    PdfPCell cellDate = new PdfPCell(new Phrase("Date : " + date.ToShortDateString()));
                    cellDate.Colspan = 5;
                    table.AddCell(cellDate);

                    PdfPCell cellProduct = new PdfPCell(new Phrase("Products", fontBold));
                    table.AddCell(cellProduct);

                    PdfPCell cellQuantity = new PdfPCell(new Phrase("Quantity", fontBold));
                    table.AddCell(cellQuantity);

                    PdfPCell cellUnitPrice = new PdfPCell(new Phrase("Unit Price", fontBold));
                    table.AddCell(cellUnitPrice);

                    PdfPCell cellLocation = new PdfPCell(new Phrase("Location", fontBold));
                    table.AddCell(cellLocation);

                    PdfPCell cellSum = new PdfPCell(new Phrase("Sum", fontBold));
                    table.AddCell(cellSum);

                    var sales =
                        (from s in db.SalesReports
                         where s.ReportDate == date
                         select s);

                    decimal totalSum = 0;

                    foreach (var sale in sales)
                    {
                        if (sale.Product.ProductName != null)
                        {
                            table.AddCell(sale.Product.ProductName);
                            table.AddCell(sale.Quantity.ToString() + " " + db.Measures
                                                                                .Where(x => x.MeasureID == sale.Product.MeasureID)
                                                                                .Select(x => x.MeasureName).First().ToString());
                            table.AddCell(sale.UnitPrice.ToString());
                            table.AddCell(sale.SupermarketName);
                            table.AddCell(sale.Sum.ToString());

                            totalSum += sale.Sum;
                        }
                    }

                    string text = string.Format("Total sum for {0} :", date.ToShortDateString());
                    PdfPCell cellTotal = new PdfPCell(new Phrase(text, fontNormal));
                    cellTotal.Colspan = 4;
                    cellTotal.HorizontalAlignment = 2;
                    table.AddCell(cellTotal);
                    table.AddCell(totalSum.ToString());

                    grandTotal += totalSum;
                }

                string grand = string.Format("Grand Total: ");
                PdfPCell cellGrand = new PdfPCell(new Phrase(grand));
                cellGrand.Colspan = 4;
                cellGrand.HorizontalAlignment = 2;
                table.AddCell(cellGrand);
                table.AddCell(grandTotal.ToString());

                doc.Add(table);
            }

            doc.Close();
        }
Пример #32
0
            public override void OnEndPage(PdfWriter writer, Document document)
            {
                Font Calibri = FontFactory.GetFont("Calibri", 9, iTextSharp.text.Font.NORMAL);
                Font CalibriBold = FontFactory.GetFont("Calibri", 10, iTextSharp.text.Font.BOLD);
                Font CalibriHeader = FontFactory.GetFont("Calibri", 60, iTextSharp.text.Font.BOLD);
                Font CalibriStrikeThrough = FontFactory.GetFont("Calibri", 10, iTextSharp.text.Font.STRIKETHRU);
                Font cbh = new Font(CalibriHeader);
                cbh.Size = 12;
                cbh.SetStyle(1);

                String _clientaddress = String.Empty;
                if (ClientAddress2 != null)
                {
                    _clientaddress = ClientAddress + ", " + ClientAddress2;
                }
                else
                {
                    _clientaddress = ClientAddress;
                }

                String footerstr2 = Client + ", " + _clientaddress + ", " + ClientCity + ", " + ClientCounty + ", " + ClientZipCode + ".";

                Chunk f = new Chunk(footerstr2, new Font(Calibri));
                // Paragraph footer1 = new Paragraph(footerstr2, FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
                Paragraph footer1 = new Paragraph(f);
                footer1.Alignment = Element.ALIGN_CENTER;

                String footerstr = "       " + Client + " is Registered in England and Wales. Company Number " + CompRegistrationNo;

                Chunk f1 = new Chunk(footerstr, new Font(Calibri));
                //Paragraph footer = new Paragraph(footerstr, FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
                Paragraph footer = new Paragraph(f1);
                Int32 footerlength = footerstr.Length;
                Int32 footerlength2 = footerstr2.Length;

                //    footer.Alignment = Element.ALIGN_RIGHT;

                PdfPTable tabFot = new PdfPTable(new float[] { 1F });
                tabFot.HorizontalAlignment = 1;
                tabFot.HorizontalAlignment = Element.ALIGN_CENTER;
                PdfPCell cell1;
                cell1 = new PdfPCell(footer1);
                cell1.Border = 0;

                PdfPCell cell;
                tabFot.TotalWidth = 580F;
                cell = new PdfPCell(footer);
                cell.Border = 0;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.HorizontalAlignment = 0;
                tabFot.AddCell(cell1);
                tabFot.AddCell(cell);

                tabFot.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
                // tabFot.WriteSelectedRows(0, -1, 140, document.Bottom+30, writer.DirectContent);

                tabFot.WriteSelectedRows(0, -1, document.LeftMargin + 110, document.Bottom + 30, writer.DirectContent);
            }
Пример #33
0
        public static string NyomtatOklevelVersenyVersenyzo(Oklevel _Oklevel, OKLEVELVERSENYZO _Versenyzo, string _Path)
        {
            string filename = _Path + "/" + _Versenyzo.Indulo + ".pdf";

            Document document = new Document(PageSize.A4);

            document.SetMargins(0, 0, 0, 0);

            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));

            // 0.353 mm = 1 unit
            // w = 595 . h = 842

            document.Open( );

            PdfContentByte pdfContentByte = pdfWriter.DirectContent;
            ColumnText     columnText     = new ColumnText(pdfContentByte);

            float MmToUnit = 1.0f / 0.353f;
            float UnitToMm = 0.353f;

            float xOffset = 0;
            float yOffset = 4;

            //NOTE(mate): a (0,0) a lap bal also sarkaban van

            List <seged> Seged = new List <seged>( );

            if (_Oklevel.VersenyX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.VersenyX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.VersenyY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.VersenyH * MmToUnit,
                    M     = _Oklevel.VersenyM,
                    I     = _Oklevel.VersenyI,
                    F     = _Oklevel.VersenyF,
                    B     = _Oklevel.VersenyB,
                    Value = _Versenyzo.Verseny,
                });
            }
            if (_Oklevel.VersenySorozatX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.VersenySorozatX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.VersenySorozatY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.VersenySorozatH * MmToUnit,
                    M     = _Oklevel.VersenySorozatM,
                    I     = _Oklevel.VersenySorozatI,
                    F     = _Oklevel.VersenySorozatF,
                    B     = _Oklevel.VersenySorozatB,
                    Value = _Versenyzo.VersenySorozat,
                });
            }
            if (_Oklevel.HelyezesX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.HelyezesX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.HelyezesY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.HelyezesH * MmToUnit,
                    M     = _Oklevel.HelyezesM,
                    I     = _Oklevel.HelyezesI,
                    F     = _Oklevel.HelyezesF,
                    B     = _Oklevel.HelyezesB,
                    Value = _Versenyzo.Helyezes.ToString( ),
                });
            }
            if (_Oklevel.InduloX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.InduloX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.InduloY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.InduloH * MmToUnit,
                    M     = _Oklevel.InduloM,
                    I     = _Oklevel.InduloI,
                    F     = _Oklevel.InduloF,
                    B     = _Oklevel.InduloB,
                    Value = _Versenyzo.Indulo,
                });
            }
            if (_Oklevel.EgyesuletX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.EgyesuletX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.EgyesuletY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.EgyesuletH * MmToUnit,
                    M     = _Oklevel.EgyesuletM,
                    I     = _Oklevel.EgyesuletI,
                    F     = _Oklevel.EgyesuletF,
                    B     = _Oklevel.EgyesuletB,
                    Value = _Versenyzo.Egyesulet,
                });
            }
            if (_Oklevel.IjtipusX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.IjtipusX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.IjtipusY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.IjtipusH * MmToUnit,
                    M     = _Oklevel.IjtipusM,
                    I     = _Oklevel.IjtipusI,
                    F     = _Oklevel.IjtipusF,
                    B     = _Oklevel.IjtipusB,
                    Value = _Versenyzo.Ijtipus,
                });
            }
            if (_Oklevel.KorosztalyX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.KorosztalyX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.KorosztalyY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.KorosztalyH * MmToUnit,
                    M     = _Oklevel.KorosztalyM,
                    I     = _Oklevel.KorosztalyI,
                    F     = _Oklevel.KorosztalyF,
                    B     = _Oklevel.KorosztalyB,
                    Value = _Versenyzo.Korosztaly,
                });
            }
            if (_Oklevel.InduloNemeX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.InduloNemeX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.InduloNemeY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.InduloNemeH * MmToUnit,
                    M     = _Oklevel.InduloNemeM,
                    I     = _Oklevel.InduloNemeI,
                    F     = _Oklevel.InduloNemeF,
                    B     = _Oklevel.InduloNemeB,
                    Value = _Versenyzo.InduloNeme,
                });
            }
            if (_Oklevel.DatumX != 0)
            {
                Seged.Add(new seged {
                    X     = (_Oklevel.DatumX * MmToUnit) + (xOffset * MmToUnit),
                    Y     = 842.0f - (_Oklevel.DatumY * MmToUnit) + (yOffset * MmToUnit),
                    H     = _Oklevel.DatumH * MmToUnit,
                    M     = _Oklevel.DatumM,
                    I     = _Oklevel.DatumI,
                    F     = _Oklevel.DatumF,
                    B     = _Oklevel.DatumB,
                    Value = _Versenyzo.Datum,
                });
            }

            foreach (var item in Seged)
            {
                Font font = Program.database.getFont(item.B);
                if (font == null)
                {
                    MessageBox.Show("Hiba a betűtípus betöltésekor", "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                font.Size = item.M;

                switch (item.F)
                {
                case "B":
                    //font = FontFactory.GetFont( FontFactory.COURIER, item.M, Font.BOLD );
                    font.SetStyle(Font.BOLD);
                    break;

                case "I":
                    //font = FontFactory.GetFont( FontFactory.COURIER, item.M, Font.ITALIC );
                    font.SetStyle(Font.ITALIC);
                    break;

                case "2":
                    //font = FontFactory.GetFont( FontFactory.COURIER, item.M, Font.BOLDITALIC );
                    //font.SetStyle(Font.BOLDITALIC);
                    break;

                case "0":
                    //font = FontFactory.GetFont( FontFactory.COURIER, item.M, Font.NORMAL );
                    //font = Program.database.getCoronet( );
                    break;

                default:
                    //font = FontFactory.GetFont( FontFactory.COURIER, item.M, Font.NORMAL );
                    //font = Program.database.getCoronet( );
                    break;
                }
                DrawText(columnText,
                         item.Value,
                         font,
                         item.X, item.Y, item.H,
                         40,
                         item.I);
            }
            document.Close( );
            return(filename);
        }
 private void setDefaults(IPdfFont baseFont, Font toFont)
 {
     toFont.Color = baseFont.Color;
     toFont.Size = baseFont.Size;
     toFont.SetStyle((int)baseFont.Style);
 }
Пример #35
0
        public static void CreatePdf(string path)
        {
            Document myDoc = new Document(PageSize.A4.Rotate());
            iTextSharp.text.pdf.PdfWriter.GetInstance(myDoc, new FileStream(path, FileMode.Create));
            myDoc.Open();
            PdfPTable table = new PdfPTable(5);

            table.TotalWidth = 800f;
            table.LockedWidth = true;
            Font font = new Font(Font.FontFamily.COURIER, 20f, 1);
            font.SetStyle("bold");

            PdfPCell cell = new PdfPCell(new Phrase("Aggregated Sales Report", font));
            cell.Colspan = 5;
            cell.Indent = 50;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.Padding = 5;
            cell.BackgroundColor = new BaseColor(229, 228, 226);
            table.AddCell(cell);

            using (SupermarketDBContext sqlContext = new SupermarketDBContext())
            {
                //MAGIC QUERRY
                //var salesRep = ( from sr in sqlContext.SalesReports
                //                 join p in sqlContext.Products
                //                 on	sr.ProductId equals p.ProductId
                //                 select new { sr, p.ProductName }).Distinct().GroupBy(x => x.sr.ReportDate);

                var salesReports = sqlContext.SalesReports.GroupBy(x => x.ReportDate).ToList();
                decimal grandTotal = 0m;

                foreach (var reports in salesReports)
                {
                    string format = "dd-MMM-yyyy";
                    var date = reports.First().ReportDate.ToString(format);
                    PdfPCell dateCell = new PdfPCell(
                        new Phrase(date, font));

                    dateCell.Colspan = 5;
                    dateCell.Indent = 50;
                    dateCell.HorizontalAlignment = Element.ALIGN_CENTER;
                    dateCell.Padding = 5;
                    dateCell.BackgroundColor = new BaseColor(229, 228, 226);
                    table.AddCell(dateCell);

                    foreach (var report in reports)
                    {
                        string productId = report.Product.ProductName.ToString();
                        string quantity = report.Quantity.ToString();
                        string unitPrice = report.UnitPrice.ToString();
                        string location = report.Location.ToString();
                        string sum = report.Sum.ToString();

                        table.AddCell(productId);
                        table.AddCell(quantity);
                        table.AddCell(unitPrice);
                        table.AddCell(location);
                        table.AddCell(sum);

                    }
                    PdfPCell footrCell = new PdfPCell(new Phrase("Total sum for " + date));
                    footrCell.Colspan = 4;
                    footrCell.Indent = 50;
                    footrCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    footrCell.Padding = 5;
                    table.AddCell(footrCell);
                    //PdfPCell totalCell = new PdfPCell();
                    decimal reportSum = reports.Sum(x => x.Sum);
                    grandTotal += reportSum;
                    table.AddCell(reportSum.ToString());
                }

                PdfPCell grandFootrCell = new PdfPCell(new Phrase("Grand total:"));
                grandFootrCell.Colspan = 4;
                grandFootrCell.Indent = 50;
                grandFootrCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                grandFootrCell.Padding = 5;
                table.AddCell(grandFootrCell);

                table.AddCell(new PdfPCell(new Phrase(grandTotal.ToString(),font)));
                myDoc.Add(table);
            }

            myDoc.Close();
        }