public static Phrase Parse(IFuzzyState state, Phrase phrase) {
            Match regexMatch = TimeVariableTemporalPrimitiveToken.RegexMatch.Match(phrase.Text);

            if (regexMatch.Success == true) {
                int? hours = regexMatch.Groups["hours"].Value.Length > 0 ? int.Parse(regexMatch.Groups["hours"].Value) : 0;
                int? minutes = regexMatch.Groups["minutes"].Value.Length > 0 ? int.Parse(regexMatch.Groups["minutes"].Value) : 0;
                int? seconds = regexMatch.Groups["seconds"].Value.Length > 0 ? int.Parse(regexMatch.Groups["seconds"].Value) : 0;

                if (String.Compare(regexMatch.Groups["meridiem"].Value, "pm", StringComparison.OrdinalIgnoreCase) == 0 && hours < 12) {
                    hours += 12;
                }
                else if (String.Compare(regexMatch.Groups["meridiem"].Value, "am", StringComparison.OrdinalIgnoreCase) == 0) {
                    if (hours == 12) {
                        hours = 0;
                    }
                }

                hours %= 24;

                phrase.Add(new TimeVariableTemporalPrimitiveToken() {
                    Pattern = new FuzzyDateTimePattern() {
                        Rule = TimeType.Definitive,
                        Hour = (regexMatch.Groups["hours"].Value.Length > 0 ? hours : null),
                        Minute = (regexMatch.Groups["minutes"].Value.Length > 0 ? minutes : null),
                        Second = (regexMatch.Groups["seconds"].Value.Length > 0 ? seconds : null)
                    },
                    Text = phrase.Text,
                    Similarity = 100.0F
                });
            }

            return phrase;
        }
Ejemplo n.º 2
0
        public static Phrase Parse(IFuzzyState state, Phrase phrase) {
            if (phrase.Text.Length > 0 && phrase.Text.First() == '"' && phrase.Text.Last() == '"' && phrase.Refactoring == false) {
                phrase.Add(new StringPrimitiveToken() {
                    Text = phrase.Text.Trim('"'),
                    Similarity = 80,
                    Value = phrase.Text.Trim('"')
                });
            }

            return phrase;
        }
        public static Phrase Parse(IFuzzyState state, Phrase phrase) {
            Match regexMatch = DateVariableTemporalPrimitiveToken.RegexMatch.Match(phrase.Text);

            if (regexMatch.Success == true) {
                DateTime dt;
                if (DateTime.TryParse(phrase.Text, out dt) == true) {
                    phrase.Add(new DateVariableTemporalPrimitiveToken() {
                        Pattern = new FuzzyDateTimePattern() {
                            Rule = TimeType.Definitive,
                            Year = dt.Year,
                            Month = dt.Month,
                            Day = dt.Day
                        },
                        Text = phrase.Text,
                        Similarity = 100.0F
                    });
                }
            }

            return phrase;
        }
Ejemplo n.º 4
0
        private void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                #region Common Part
                PdfPTable pdfTable3 = new PdfPTable(DataGridView1.ColumnCount - 2);
                pdfTable3.DefaultCell.Padding = 3;
                pdfTable3.WidthPercentage     = 80;
                pdfTable3.HorizontalAlignment = Element.ALIGN_CENTER;
                // pdfTable3.DefaultCell.VerticalAlignment = Element.ALIGN_LEFT;
                pdfTable3.DefaultCell.BorderWidth = 1;
                //Footer Sectionaa
                PdfPTable pdfTableFooter = new PdfPTable(1);
                pdfTableFooter.DefaultCell.BorderWidth         = 0;
                pdfTableFooter.WidthPercentage                 = 100;
                pdfTableFooter.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;


                Chunk cnkFooter = new Chunk("                                                                                                                                          SIGNATURE", FontFactory.GetFont("Times New Roman"));
                cnkFooter.Font.SetStyle(1);
                cnkFooter.Font.Size = 10;
                pdfTableFooter.AddCell(new Phrase(cnkFooter));

                Chunk e1 = new Chunk("                                                                                                                                                  '" + user + "'", FontFactory.GetFont("Times New Roman"));
                e1.Font.SetStyle(0);
                e1.Font.Size = 10;
                pdfTableFooter.AddCell(new Phrase(e1));
                //End Of Footer Section



                #endregion

                #region Page
                #region Section-1

                PdfPTable pdfTable1 = new PdfPTable(1);//Here 1 is Used For Count of Column
                PdfPTable pdfTable2 = new PdfPTable(1);
                PdfPTable pdfTable4 = new PdfPTable(1);
                PdfPTable pdfTable5 = new PdfPTable(1);

                //Font Style
                System.Drawing.Font fontH1 = new System.Drawing.Font("Bookman Old Style Bold", 16);

                pdfTable1.DefaultCell.Padding             = 5;
                pdfTable1.WidthPercentage                 = 80;
                pdfTable1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable1.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                //// pdfTable1.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(64, 134, 170);
                pdfTable1.DefaultCell.BorderWidth = 0;


                pdfTable1.DefaultCell.Padding             = 5;
                pdfTable2.WidthPercentage                 = 80;
                pdfTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable2.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                // pdfTable1.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(64, 134, 170);
                pdfTable2.DefaultCell.BorderWidth = 0;

                pdfTable4.DefaultCell.Padding             = 0;
                pdfTable4.WidthPercentage                 = 80;
                pdfTable4.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                pdfTable4.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
                pdfTable4.DefaultCell.BorderWidth         = 0;

                pdfTable5.DefaultCell.Padding             = 0;
                pdfTable5.WidthPercentage                 = 80;
                pdfTable5.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable5.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                pdfTable5.DefaultCell.BorderWidth         = 0;

                Chunk  c14 = new Chunk(" ");
                Phrase p14 = new Phrase();
                p14.Add(c14);
                pdfTable5.AddCell(p14);


                // Chunk c1 = new Chunk("" + TextBox6.Text +"");//("Jyothis Central School", FontFactory.GetFont("Bookman Old Style Bold"));
                Chunk c1 = new Chunk("Jyothis Central School");//, FontFactory.GetFont("Bookman Old Style Bold"));
                c1.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
                c1.Font.SetStyle(0);
                c1.Font.Size = 14;
                Phrase p1 = new Phrase();
                p1.Add(c1);
                pdfTable1.AddCell(p1);
                Chunk c2 = new Chunk("KAZHAKUTTOM P.O, Tvpm - 695582", FontFactory.GetFont("Times New Roman"));
                c2.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
                c2.Font.SetStyle(0);
                c2.Font.Size = 11;
                Phrase p2 = new Phrase();
                p2.Add(c2);
                pdfTable2.AddCell(p2);
                Chunk c3 = new Chunk("Ph: 0471 - 2705857, 6548751, 2925751, 2415751", FontFactory.GetFont("Times New Roman"));
                c3.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
                c3.Font.SetStyle(0);
                c3.Font.Size = 11;
                Phrase p3 = new Phrase();
                p3.Add(c3);
                pdfTable2.AddCell(p3);
                Chunk  c4 = new Chunk(" ");
                Phrase p4 = new Phrase();
                p4.Add(c4);
                pdfTable2.AddCell(p4);

                Chunk  c9 = new Chunk(" BOOK RECEIPT ");
                Phrase p9 = new Phrase();
                p9.Add(c9);
                pdfTable2.AddCell(p9);

                Chunk  c11 = new Chunk("----------------------- ");
                Phrase p11 = new Phrase();
                p11.Add(c11);
                pdfTable2.AddCell(p11);

                Chunk  c10 = new Chunk(" ");
                Phrase p10 = new Phrase();
                p10.Add(c10);
                pdfTable4.AddCell(p10);

                Chunk c5 = new Chunk("Student Name = '" + TextBox3.Text + "'                                                            Invoice Number = '" + TextBox1.Text + "'", FontFactory.GetFont("Times New Roman"));
                c5.Font.Size = 10;
                Phrase p5 = new Phrase();
                p5.Add(c5);
                pdfTable4.AddCell(p5);

                Chunk  c6 = new Chunk(" ");
                Phrase p6 = new Phrase();
                p6.Add(c6);
                pdfTable4.AddCell(p6);

                Chunk c7 = new Chunk("Class = '" + TextBox2.Text + "'                                                                                           Date Of Invoice = '" + TextBox4.Text + "'", FontFactory.GetFont("Times New Roman"));
                c7.Font.Size = 10;
                Phrase p7 = new Phrase();
                p7.Add(c7);
                pdfTable4.AddCell(p7);

                Chunk  c8 = new Chunk(" ");
                Phrase p8 = new Phrase();
                p8.Add(c8);
                pdfTable4.AddCell(p8);

                Chunk c12 = new Chunk("Date Of Issue = '" + TextBox5.Text + "'", FontFactory.GetFont("Times New Roman"));
                c12.Font.Size = 10;
                Phrase p12 = new Phrase();
                p12.Add(c12);
                pdfTable4.AddCell(p12);

                Chunk  c13 = new Chunk(" ");
                Phrase p13 = new Phrase();
                p13.Add(c13);
                pdfTable4.AddCell(p13);
                pdfTable4.AddCell(p13);

                #endregion
                #region Section-1

                #endregion
                #region Section-Image

                iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("JCS Logo.jpg");

                //Resize image depend upon your need
                jpg.ScaleToFit(100f, 80f);
                //Give space before image
                jpg.SpacingBefore = 10f;
                //Give some space after the image
                jpg.SpacingAfter = 100f;

                jpg.Alignment = Element.ALIGN_CENTER;
                #endregion

                #region section Table
                int i = 0;
                foreach (DataGridViewColumn column in DataGridView1.Columns)
                {
                    i++;
                    if (i > 2)
                    {
                        PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
                        pdfTable3.AddCell(cell);
                    }
                }
                //Adding DataRow
                foreach (DataGridViewRow row in DataGridView1.Rows)
                {
                    i = 0;
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        i++;
                        if (i > 2)
                        {
                            pdfTable3.AddCell(cell.Value.ToString());
                        }
                    }
                }


                #endregion

                #endregion


                #region Pdf Generation
                string folderPath = "C:\\StockManagement Data\\";
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                //File Name
                //int fileCount = Directory.GetFiles("C:\\StockManagement Data\\").Length;
                string strFileName = "Invoice of '" + TextBox1.Text + "'.pdf"; //" + (fileCount + 1) + ".pdf";

                using (FileStream stream = new FileStream(folderPath + strFileName, FileMode.Create))
                {
                    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                    PdfWriter.GetInstance(pdfDoc, stream);
                    pdfDoc.Open();
                    #region PAGE-1
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(jpg);
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(pdfTable1);
                    pdfDoc.Add(pdfTable2);
                    pdfDoc.Add(pdfTable4);
                    pdfDoc.Add(pdfTable3);
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(pdfTable5);
                    pdfDoc.Add(pdfTableFooter);

                    pdfDoc.NewPage();
                    #endregion


                    pdfDoc.Close();
                    stream.Close();
                }
                #endregion

                #region Display PDF
                System.Diagnostics.Process.Start(folderPath + "\\" + strFileName);
                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }

            TextBox1.Text = "0";
            Button2_Click(sender, e);
            TextBox1.Clear();
        }
Ejemplo n.º 5
0
        public static void CreatePDF()
        {
            FileStream fs = new FileStream("dokument.pdf", FileMode.Create, FileAccess.Write, FileShare.None);

            Document doc = new Document(PageSize.A4);

            doc.SetMargins(24.65f, 23.8f, doc.TopMargin, doc.BottomMargin);

            string path = Environment.CurrentDirectory;

            string    nazwa1 = "Bestellungsformular" + MainClass.Oferta[1].Replace("/", "") + "_" + MainClass.Halledaten[1] + "x" + MainClass.Halledaten[2] + "m_" + MainClass.Halledaten[0] + "_" + MainClass.Personaldaten[7] + " " + MainClass.Personaldaten[0] + " " + MainClass.Personaldaten[1];
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", nazwa1 + ".pdf")), FileMode.Create));

            doc.Open();


            PdfPTable table;
            PdfPCell  cell;
            Paragraph par;
            Phrase    phrase;

            BaseFont impact  = BaseFont.CreateFont(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", "Fonts/impact.ttf")), BaseFont.CP1252, BaseFont.EMBEDDED);
            BaseFont arial   = BaseFont.CreateFont(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", "Fonts/Arial.ttf")), BaseFont.CP1252, BaseFont.EMBEDDED);
            BaseFont arialbd = BaseFont.CreateFont(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", "Fonts/ARIALBD.TTF")), BaseFont.CP1252, BaseFont.EMBEDDED);
            BaseFont verdana = BaseFont.CreateFont(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", "Fonts/verdana.TTF")), BaseFont.CP1252, BaseFont.EMBEDDED);
            BaseFont simsun  = BaseFont.CreateFont(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Replace("Oferta+.app/Contents/MonoBundle", "Fonts/SIMSUN.ttf")), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            Font logo1       = new Font(impact, 27f, Font.NORMAL, new BaseColor(102, 102, 102));
            Font logo2       = new Font(impact, 27f, Font.NORMAL, new BaseColor(0, 204, 204));
            Font logo1_small = new Font(impact, 10f, Font.NORMAL, new BaseColor(102, 102, 102));
            Font logo2_small = new Font(impact, 10f, Font.NORMAL, new BaseColor(0, 204, 204));

            Font standard           = new Font(arial, 9f, Font.NORMAL, BaseColor.BLACK);
            Font standard_bold      = new Font(arialbd, 9f, Font.NORMAL, BaseColor.BLACK);
            Font standard_blue      = new Font(arialbd, 9f, Font.NORMAL, new BaseColor(0, 69, 134));
            Font standard_lightblue = new Font(arial, 9f, Font.NORMAL, new BaseColor(0, 69, 134));

            Font chinese = new Font(simsun, 9f, Font.NORMAL, BaseColor.BLACK);

            Font small = new Font(verdana, 7f, Font.NORMAL, BaseColor.BLACK);

            Font medium      = new Font(arial, 8f, Font.NORMAL, BaseColor.BLACK);
            Font medium_bold = new Font(arialbd, 8f, Font.NORMAL, BaseColor.BLACK);

            Font small_blue = new Font(arial, 7f, Font.NORMAL, new BaseColor(0, 69, 134));

            //itcmetalcon.
            phrase = new Phrase();
            phrase.Add(new Chunk("itc", logo2));
            phrase.Add(new Chunk("metalcon", logo1));
            phrase.Add(new Chunk(".", logo2));
            par = new Paragraph();
            par.Add(phrase);
            par.Alignment = 2;
            doc.Add(par);

            //1tabela dane klienta
            table       = new PdfPTable(3);
            cell        = new PdfPCell(new Phrase(MainClass.Personaldaten[7] + " " + MainClass.Personaldaten[0] + " " + MainClass.Personaldaten[1], standard_bold));
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);

            cell         = new PdfPCell(new Phrase(" "));
            cell.Border  = Rectangle.NO_BORDER;
            cell.Rowspan = 6;
            table.AddCell(cell);

            //cell = new PdfPCell(new Phrase("Hallensysteme\n Herstellung", small_blue));
            //cell.AddElement(new Phrase("Ferligung nach maB", small_blue));
            //cell.AddElement(new Phrase("Verkauf und Vermietung", small_blue));
            cell                   = new PdfPCell();
            cell.Border            = Rectangle.NO_BORDER;
            cell.UseAscender       = true;
            cell.VerticalAlignment = Element.ALIGN_TOP;
            par = new Paragraph(new Phrase(" \n", small_blue));
            par.SpacingAfter = -4f;
            par.Alignment    = 2;
            cell.AddElement(par);
            par = new Paragraph(new Phrase("Hallensysteme\n", small_blue));
            par.SpacingAfter = -4f;
            par.Alignment    = 2;
            cell.AddElement(par);
            par = new Paragraph(new Phrase("Herstellung\n", small_blue));
            par.SpacingAfter = -4f;
            par.Alignment    = 2;
            cell.AddElement(par);
            par = new Paragraph(new Phrase("Ferligung nach maß\n", small_blue));
            par.SpacingAfter = -4f;
            par.Alignment    = 2;
            cell.AddElement(par);
            par           = new Paragraph(new Phrase("Verkauf und Vermietung\n ", small_blue));
            par.Alignment = 2;
            cell.AddElement(par);

            cell.Rowspan = 4;
            table.AddCell(cell);

            if (MainClass.Personaldaten[6].Length > 0)
            {
                cell        = new PdfPCell(new Phrase(MainClass.Personaldaten[6], standard_bold));
                cell.Border = Rectangle.NO_BORDER;
                table.AddCell(cell);
            }

            if (MainClass.Personaldaten[2].Length > 0)
            {
                cell        = new PdfPCell(new Phrase(MainClass.Personaldaten[2], standard));
                cell.Border = Rectangle.NO_BORDER;
                table.AddCell(cell);
            }

            if (MainClass.Personaldaten[4].Length > 0)
            {
                cell = new PdfPCell(new Phrase(MainClass.Personaldaten[4] + " " + MainClass.Personaldaten[3], standard));
            }
            else
            {
                cell = new PdfPCell(new Phrase(MainClass.Personaldaten[3], standard));
            }
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);

            phrase = new Phrase();
            //Console.WriteLine(Personaldaten[6].Length);
            if (MainClass.Personaldaten[5].Length > 6)
            {
                phrase = new Phrase(MainClass.Personaldaten[5], standard);
            }
            else
            {
                phrase = new Phrase(" ");
            }
            cell        = new PdfPCell(phrase);
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);

            if (MainClass.Personaldaten[6].Length == 0)
            {
                cell        = new PdfPCell(new Phrase(" "));
                cell.Border = Rectangle.NO_BORDER;
                table.AddCell(cell);
            }

            if (MainClass.Personaldaten[2].Length == 0)
            {
                cell        = new PdfPCell(new Phrase(" "));
                cell.Border = Rectangle.NO_BORDER;
                table.AddCell(cell);
            }



            phrase = new Phrase(new Chunk("Angebot Nr: ", medium_bold));
            phrase.Add(new Chunk(MainClass.Oferta[1] + " von " + MainClass.dataoferty.ToString("dd.MM.yyyy"), medium));
            par                      = new Paragraph(phrase);
            par.Alignment            = 2;
            cell                     = new PdfPCell(par);
            cell.UseAscender         = true;
            cell.HorizontalAlignment = 2;
            cell.Border              = Rectangle.NO_BORDER;
            table.AddCell(cell);

            cell        = new PdfPCell(new Phrase(" "));
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);
            table.AddCell(cell);

            table.TotalWidth = doc.Right - doc.Left;
            //Console.WriteLine(doc.Right - doc.Left); //default 534
            //Console.WriteLine(doc.LeftMargin + " " + doc.RightMargin); //default 36/36
            table.LockedWidth = true;

            table.SetWidths(new float[] { 1.572f, 0.908f, 1.240f });

            doc.Add(table);



            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Lieferadresse / Aufbauort: ", standard_bold));
            phrase.Add(new Chunk("..............................................................", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Hallengröße (B x L x H): ", standard_bold));
            phrase.Add(new Chunk(
                           String.Format("{0:0.00}", Convert.ToDouble(MainClass.Halledaten[1].Replace(",", "."))).Replace(".", ",") + " x " +
                           String.Format("{0:0.00}", Convert.ToDouble(MainClass.Halledaten[2].Replace(",", "."))).Replace(".", ",") + " x " +
                           String.Format("{0:0.00}", Convert.ToDouble(MainClass.Halledaten[3].Replace(",", "."))).Replace(".", ",") + " m", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Schneelast: ", standard_bold));
            string windzone = MainClass.Halledaten[10];

            if (MainClass.Halledaten2[8].Length > 0)
            {
                windzone = MainClass.Halledaten2[8] + "- " + windzone;
            }
            string schneelast = MainClass.Halledaten[9];

            if (MainClass.Halledaten2[7].Length > 0)
            {
                schneelast = MainClass.Halledaten2[7] + "- " + schneelast;
            }
            phrase.Add(new Chunk(schneelast + " kN/m², Windzone " + windzone + " kN/m²", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Boden: ", standard_bold));
            phrase.Add(new Chunk("..............................................................................................", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);



            string[] typ_pom = MainClass.Halledaten[0].Split(" ");
            string[] typ     = new string[2];
            if (typ_pom[1].Substring(0, 2) == "TT" || typ_pom[1].Substring(0, 2) == "PT" || typ_pom[1].Substring(0, 2) == "PP")
            {
                typ[1] = typ_pom[1];
            }
            else if (typ_pom[1].Substring(0, 3) == "ISO" || typ_pom[1].Substring(0, 3) == "DPS")
            {
                typ[1] = typ_pom[1];
            }
            else if (typ_pom.Length > 2)
            {
                if (typ_pom[2].Substring(0, 2) == "TT" || typ_pom[2].Substring(0, 2) == "PT" || typ_pom[2].Substring(0, 2) == "PP")
                {
                    typ[1] = typ_pom[2];
                }
                else if (typ_pom[2].Substring(0, 3) == "ISO" || typ_pom[2].Substring(0, 3) == "DPS")
                {
                    typ[1] = typ_pom[2];
                }
            }

            string opis1 = "";
            string opis2 = "";
            string opis3 = "";

            if (typ[1].Substring(0, 2) == "TT")
            {
                //opis1 = "Konstruktion aus Aluminiumkastenprofil mit Zugbändern, mit First- und Eckverbindungen aus feuerverzinktem Stahl. Die feuerverzinkten Fußplatten sind entsprechend den statischen Erfordernissen mittels Erdnägeln (1,00 m lang) auf nicht bindigen, dicht gelagerten Boden evtl. Schwerlastdübeln auf Fundamenten verankert.";
                opis1 = MainClass.TechnischeDaten;
                opis2 = "Dacheindeckung und Giebeldreieck: PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m², schwerentflammbar gemäß DIN4102/B1. Es ist in den 4-Kedernut Alu-Profil eingezogen. Das PVC- Material in Standardfarbe Weiß - es kann nach Absprache und evtl. gegen Aufpreis in anderen Farben geliefert werden.";
                opis3 = "Zur Isolierung und Kondenswasservermeidung kann im Dachbereich (von Traufe bis Traufe) gegen Aufpreis eine lichtdurchlässige Innenplane montiert werden.";
            }
            else if (typ[1].Substring(0, 2) == "PT")
            {
                //opis1 = "Konstruktion aus Aluminiumkastenprofil mit Zugbändern, mit First- und Eckverbindungen aus feuerverzinktem Stahl. Die feuerverzinkten Fußplatten sind entsprechend den statischen Erfordernissen mittels Erdnägeln (1,00 m lang) auf nicht bindigen, dicht gelagerten Boden (DIN-EN 13782) evtl. Schwerlastdübeln auf Fundamenten (DIN-EN 1991) verankert.";
                opis1 = MainClass.TechnischeDaten;
                opis2 = "Dacheindeckung und Giebeldreieck: PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m², schwerentflammbar gemäß DIN4102/B1. Es ist in den 4-Kedernut Alu-Profil eingezogen. Das PVC- Material in Standardfarbe Weiß - es kann nach Absprache und evtl. gegen Aufpreis in anderen Farben geliefert werden.";
                opis3 = "Zur Isolierung und Kondenswasservermeidung kann im Dachbereich (von Traufe bis Traufe) gegen Aufpreis eine lichtdurchlässige Innenplane montiert werden.";
            }
            else if (typ[1].Substring(0, 2) == "PP")
            {
                opis1 = MainClass.TechnischeDaten;
                opis2 = "Dacheindeckung und Giebeldreieck: PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m², schwerentflammbar gemäß DIN4102/B1. Es ist in den 4-Kedernut Alu-Profil eingezogen. Das PVC- Material in Standardfarbe Weiß - es kann nach Absprache und evtl. gegen Aufpreis in anderen Farben geliefert werden.";
                opis3 = "Zur Isolierung und Kondenswasservermeidung kann im Dachbereich (von Traufe bis Traufe) gegen Aufpreis eine lichtdurchlässige Innenplane montiert werden.";
            }
            else if (typ[1].Substring(0, 3) == "ISO")
            {
                //opis1 = "Konstruktion aus Doppel-T-Träger IPE240 (Riegel) und HEA 180 (Ständer), ohne Zugbändern (Flacheisen). Baustahl 235, feuerverzinkt nach DIN-EN ISO 1461. Die Fußplattern sind entsprechend den statischen Erfordernissen mittles Schwerlastdübeln auf Fundementen verankert.";
                opis1 = MainClass.TechnischeDaten;
                opis2 = "Sandwichpaneelen, Stärke 40mm, chwerentflammbar nach DIN 4102 Baustoffklasse 1, U-Wert";
                opis3 = "";
            }
            else if (typ[1].Substring(0, 3) == "DPS")
            {
                //opis1 = "Konstruktion aus Aluminiumkastenprofil mit Zugbändern, mit First- und Eckverbindungen aus feuerverzinktem Stahl. Die feuerverzinkten Fußplatten sind entsprechend den statischen Erfordernissen mittels Erdnägeln (1,00 m lang) auf nicht bindigen, dicht gelagerten Boden (DIN-EN 13782) evtl. Schwerlastdübeln auf Fundamenten (DIN-EN 1991) verankert.";
                opis1 = MainClass.TechnischeDaten;
            }

            phrase = new Phrase(new Chunk("Konstruktion: ", standard_bold));
            phrase.Add(new Chunk(MainClass.TechnischeDaten, standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);
            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);


            if (typ[1].Substring(0, 2) == "PT")
            {
                phrase = new Phrase(new Chunk("Dacheindeckung und Giebeldreieck: ", standard_bold));
                phrase.Add(new Chunk("PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m², schwerentflammbar gemäß DIN4102/B1. Es ist in den " + MainClass.Kedernut + "-Kedernut Alu-Profil eingezogen. Das PVC- Material in Standardfarbe Weiß - es kann nach Absprache und evtl. gegen Aufpreis in anderen Farben geliefert werden.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 2) == "TT")
            {
                phrase = new Phrase(new Chunk("Dacheindeckung: ", standard_bold));
                phrase.Add(new Chunk("bestehend aus verzinkten und kunststoffbeschichteten Stahl-Trapezblechen T35 / T18, Stärke " + MainClass.Technische[0] + " mm.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 2) == "PP")
            {
                phrase = new Phrase(new Chunk("Dacheindeckung und Wandverkleidung: ", standard_bold));
                phrase.Add(new Chunk("PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m2, schwerentflammbar gemäß DIN4102/B1. Es ist in den 4-Kedernut Alu-Profil eingezogen. Das PVC- Material in Standardfarbe Weiß oder Grün - es kann nach Absprache in anderen Farben geliefert werden.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 3) == "DPS")
            {
                phrase = new Phrase(new Chunk("Dacheindeckung und Giebeldreieck: ", standard_bold));
                phrase.Add(new Chunk("doppelschalige PVC- beschichtete Gewebe hoch-glanz-lackiert, Gewicht " + MainClass.Technische[4] + " g/m², schwerentflammbar gemäß DIN4102/B1, K-Wert " + MainClass.Technische[5] + " W/m²K, Druckregler mit Kompressor (1 Stk.).", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (MainClass.Select3 == 1)
            {
                phrase = new Phrase(new Chunk("Dacheindeckung: ", standard_bold));
                phrase.Add(new Chunk("Sandwichpaneelen (profiliert), ", standard));
                phrase.Add(new Chunk("Stärke " + MainClass.Technische[0] + " mm, ", standard_bold));
                phrase.Add(new Chunk("schwerentflammbar nach DIN 4102 Baustoffklasse 1, ", standard));
                phrase.Add(new Chunk("U-Wert (W/m²K) = " + MainClass.Technische[1] + ". ", standard_bold));
                phrase.Add(new Chunk("Die Panellen bestehen aus einem Kern aus Hartschaum zwischen verzinkten und kunststoffbeschichtetem Stahlblech- Deckschalen.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }



            if (typ[1].Substring(0, 2) == "PT")
            {
                phrase = new Phrase(new Chunk("Wandverkleidung ", standard_bold));
                phrase.Add(new Chunk("bestehend aus waagerecht (evtl. senkrecht) verlegten, verzinkten und kunststoffbeschichteten Stahl-Trapezblechen T35 / T18, Stärke " + MainClass.Technische[2] + " mm.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 2) == "PP")
            {
                phrase = new Phrase(new Chunk("Wandverkleidung ", standard_bold));
                phrase.Add(new Chunk("bestehend aus waagerecht (evtl. senkrecht) verlegten, verzinkten und kunststoffbeschichteten Stahl-Trapezblechen T35 / T18, Stärke " + MainClass.Technische[2] + " mm.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 2) == "TT")
            {
                phrase = new Phrase(new Chunk("Wandverkleidung ", standard_bold));
                phrase.Add(new Chunk("bestehend aus waagerecht verlegten, verzinkten und kunststoffbeschichteten Stahl-Trapezblechen T35 / T18, Stärke " + MainClass.Technische[2] + " mm.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (typ[1].Substring(0, 3) == "DPS")
            {
                phrase = new Phrase(new Chunk("Wandverkleidung: ", standard_bold));
                phrase.Add(new Chunk("Sandwichpaneelen (profiliert), ", standard));
                phrase.Add(new Chunk("Stärke " + MainClass.Technische[2] + " mm, ", standard_bold));
                phrase.Add(new Chunk("schwerentflammbar nach DIN 4102 Baustoffklasse 1, ", standard));
                phrase.Add(new Chunk("U-Wert (W/m²K) = " + MainClass.Technische[3] + ". ", standard_bold));
                phrase.Add(new Chunk("Die Panellen bestehen aus einem Kern aus Hartschaum zwischen verzinkten und kunststoffbeschichtetem Stahlblech- Deckschalen. Die Verkleidung schließt mit einem Abschluss aus Kantblechen + Dichtband am Boden ab.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }
            else if (MainClass.Select3 == 1)
            {
                phrase = new Phrase(new Chunk("Wandverkleidung: ", standard_bold));
                phrase.Add(new Chunk("Sandwichpaneelen (profiliert), ", standard));
                phrase.Add(new Chunk("Stärke " + MainClass.Technische[2] + " mm, ", standard_bold));
                phrase.Add(new Chunk("schwerentflammbar nach DIN 4102 Baustoffklasse 1, ", standard));
                phrase.Add(new Chunk("U-Wert (W/m²K) = " + MainClass.Technische[3] + ". ", standard_bold));
                phrase.Add(new Chunk("Die Panellen bestehen aus einem Kern aus Hartschaum zwischen verzinkten und kunststoffbeschichtetem Stahlblech- Deckschalen. Die Verkleidung schließt mit einem Abschluss aus Kantblechen + Dichtband am Boden ab.", standard));
                phrase.Add(new Chunk("\nFarbton: ............................................................................................", standard));
                par = new Paragraph(phrase);

                par.SpacingAfter = -4f;
                par.SetLeading(10f, 0f);
                par.Alignment = 0;
                doc.Add(par);

                par = new Paragraph(new Phrase(" ", standard));
                par.SpacingAfter = 0f;
                par.Alignment    = 0;
                doc.Add(par);
            }

            phrase = new Phrase(new Chunk("Tore und Türen:\n", standard_bold));
            phrase.Add(new Chunk(MainClass.ToreUndTuren, standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Zusätliche Ausstattung:", standard_bold));

            string ausstattung = "";

            string[] elm = AllManager.CreateReadyElement(MainClass.bazaTabela1, MainClass.bazaTabela1_x, MainClass.bazaTabela1_y);
            for (int i = (MainClass.AusstattungOd - 1); i <= (MainClass.AusstattungDo - 1); i++)
            {
                ausstattung = ausstattung + "\n-" + Convert.ToString(MainClass.bazaTabela1_ilosc[i]) + " " + MainClass.bazaTabela1_jedn[i] + " " + elm[i];
                if (i < MainClass.AusstattungDo - 1)
                {
                    ausstattung = ausstattung + ",";
                }
            }

            phrase.Add(new Chunk(ausstattung, standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            string leichtbauhalle = "";

            if (MainClass.Halledaten[0].Split(" ")[MainClass.Halledaten[0].Split(" ").Length - 1].Length > 2)
            {
                leichtbauhalle = MainClass.Halledaten[0].Substring(0, MainClass.Halledaten[0].Length - 4);
            }
            else
            {
                leichtbauhalle = MainClass.Halledaten[0].Substring(0, MainClass.Halledaten[0].Length - 3);
            }
            phrase           = new Phrase(new Chunk("Ich bestelle die " + leichtbauhalle + " mit Lieferung und mit / ohne Montage.", standard_bold));
            par              = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Gesamtpreis: ", standard_bold));

            string gesamtpreis = String.Format("{0:0.00}", Convert.ToDouble(MainClass.Gesamtpreis)).Replace(".", ",");

            phrase.Add(new Chunk(gesamtpreis + " € inkl. Liefer- und Montagekosten, zzgl. 19% MwSt.", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase = new Phrase(new Chunk("Zahlung bei Kauf:\n", standard_bold));
            phrase.Add(new Chunk("Mit Montage: 30% vom Auftragswert bei Bestellung, 60% bei Anlieferung, vor Abladung. Restzahlung - 10% bei Abnahme / Fertigstellung (siehe AGB).\nOhne Montage: 40% vom Auftragswert bei Bestellung, Restzahlung 60% bei Anlieferung, vor Abladung.", standard));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase           = new Phrase(new Chunk("Ich habe die AGB von itcmetalcon. gelesen und akzeptiere diese.", standard_bold));
            par              = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            par = new Paragraph(new Phrase(" ", standard));
            par.SpacingAfter = 0f;
            par.Alignment    = 0;
            doc.Add(par);

            phrase           = new Phrase(new Chunk("Datum, Unterschrift", standard));
            par              = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.SetLeading(10f, 0f);
            par.Alignment = 0;
            doc.Add(par);



            //stopka
            table                  = new PdfPTable(3);
            cell                   = new PdfPCell();
            cell.Rowspan           = 4;
            cell.UseAscender       = true;
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;

            phrase = new Phrase();
            phrase.Add(new Chunk("itc", logo2_small));
            phrase.Add(new Chunk("metalcon", logo1_small));
            phrase.Add(new Chunk(".\n", logo2_small));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Normannenstrasse 2", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("71263 Weil der Stadt", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Tel.: (+49) 162 4230214", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Fax.: (+49) 7033 467017 \n ", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase(" ", small));
            par.SpacingAfter = -0.5f;
            par.Alignment    = 0;
            cell.AddElement(par);

            cell.BackgroundColor = new BaseColor(238, 238, 238);
            cell.Border          = Rectangle.NO_BORDER;

            table.AddCell(cell);


            cell                   = new PdfPCell();
            cell.Rowspan           = 4;
            cell.UseAscender       = true;
            cell.VerticalAlignment = Element.ALIGN_TOP;

            phrase = new Phrase();
            phrase.Add(new Chunk(" \n", logo2_small));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Konto: 4530164301", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("BLZ: 85591000", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("IBAN: DE55855910004530164301", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("BIC: GENODEF1GR1", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            cell.BackgroundColor = new BaseColor(238, 238, 238);
            cell.Border          = Rectangle.NO_BORDER;

            table.AddCell(cell);


            cell                   = new PdfPCell();
            cell.Rowspan           = 5;
            cell.UseAscender       = true;
            cell.VerticalAlignment = Element.ALIGN_TOP;

            phrase = new Phrase();
            phrase.Add(new Chunk(" \n", logo2_small));
            par = new Paragraph(phrase);
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("*****@*****.**", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("www.itcmetalcon.de", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Geshäftsführer / Inhaber: Pawel Swiderski", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase(" ", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("USt. ID - Nummer: DE 275947975", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            par = new Paragraph(new Phrase("Steuernummer: 70418/72302", small));
            par.SpacingAfter = -4f;
            par.Alignment    = 0;
            cell.AddElement(par);

            cell.BackgroundColor = new BaseColor(238, 238, 238);
            cell.Border          = Rectangle.NO_BORDER;

            table.AddCell(cell);

            table.TotalWidth  = doc.Right - doc.Left;
            table.LockedWidth = true;
            PdfContentByte pcb = writer.DirectContent;

            table.WriteSelectedRows(0, -1, doc.Left, doc.Bottom + 50, pcb);



            doc.Close();

            writer.Close();

            fs.Close();
        }
Ejemplo n.º 6
0
        public override void Design(Person person, Education sch, Education col, Education uni, WorkHistory work, AdditionalCourse adc)
        {
            // creating the pdf
            Document doc1 = new Document(PageSize.A3);

            PdfWriter.GetInstance(doc1, new FileStream(path + ".pdf", FileMode.Append));
            //working on the pdf
            doc1.Open();
            PdfPTable table1  = new PdfPTable(1);
            PdfPTable table2  = new PdfPTable(1);
            PdfPTable table3  = new PdfPTable(1);
            PdfPTable table4  = new PdfPTable(1);
            PdfPTable table5  = new PdfPTable(1);
            PdfPTable table6  = new PdfPTable(1);
            PdfPTable table7  = new PdfPTable(1);
            PdfPTable table8  = new PdfPTable(1);
            PdfPTable table9  = new PdfPTable(1);
            PdfPTable table10 = new PdfPTable(1);
            PdfPTable table11 = new PdfPTable(1);
            PdfPTable table12 = new PdfPTable(1);
            PdfPTable table13 = new PdfPTable(1);
            PdfPTable table14 = new PdfPTable(1);
            PdfPTable table15 = new PdfPTable(1);
            PdfPTable table16 = new PdfPTable(1);
            PdfPTable table17 = new PdfPTable(1);
            PdfPTable table18 = new PdfPTable(1);
            PdfPTable table19 = new PdfPTable(1);
            PdfPTable table20 = new PdfPTable(1);
            PdfPTable table21 = new PdfPTable(1);

            table1.WidthPercentage = 80;
            table1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            table1.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
            table1.DefaultCell.BorderWidth         = 0;
            table2.WidthPercentage = 80;
            table2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            table2.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
            table2.DefaultCell.BorderWidth         = 0;
            table2.DefaultCell.PaddingTop          = 10;
            table3.WidthPercentage = 80;
            table3.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table3.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table3.DefaultCell.BorderWidth         = 0;
            table3.DefaultCell.PaddingTop          = 40;
            table4.WidthPercentage = 80;
            table4.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table4.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table4.DefaultCell.BorderWidth         = 0;
            table4.DefaultCell.PaddingTop          = 10;
            table4.WidthPercentage = 80;
            table5.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table5.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table5.DefaultCell.BorderWidth         = 0;
            table5.DefaultCell.PaddingTop          = 20;
            table6.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table6.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table6.DefaultCell.BorderWidth         = 0;
            table6.DefaultCell.PaddingTop          = -20;
            table7.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table7.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table7.DefaultCell.BorderWidth         = 0;
            table8.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table8.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table8.DefaultCell.BorderWidth         = 0;
            table8.DefaultCell.PaddingTop          = 5;
            table9.DefaultCell.BorderWidth         = 0;
            table9.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table9.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table9.WidthPercentage                  = 80;
            table10.DefaultCell.BorderWidth         = 0;
            table10.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table10.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table10.DefaultCell.PaddingTop          = -15;
            table10.DefaultCell.PaddingLeft         = 30;
            table11.DefaultCell.BorderWidth         = 0;
            table11.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table11.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table11.DefaultCell.PaddingTop          = 20;
            table12.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table12.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table12.DefaultCell.BorderWidth         = 0;
            table12.DefaultCell.PaddingTop          = 20;
            table13.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table13.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table13.DefaultCell.BorderWidth         = 0;
            table13.DefaultCell.PaddingTop          = 10;
            table14.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table14.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table14.DefaultCell.BorderWidth         = 0;
            table14.DefaultCell.PaddingTop          = 20;
            table15.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table15.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table15.DefaultCell.BorderWidth         = 0;
            table15.DefaultCell.PaddingTop          = 10;
            table16.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table16.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table16.DefaultCell.BorderWidth         = 0;
            table16.DefaultCell.PaddingTop          = 20;
            table17.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table17.DefaultCell.VerticalAlignment   = Element.ALIGN_LEFT;
            table17.DefaultCell.BorderWidth         = 0;
            table17.DefaultCell.PaddingTop          = 10;
            table18.DefaultCell.BorderWidth         = 0;
            table18.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table18.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table18.DefaultCell.PaddingTop          = -250;
            table19.DefaultCell.BorderWidth         = 0;
            table19.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table19.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table19.DefaultCell.PaddingTop          = -230;
            table21.DefaultCell.BorderWidth         = 0;
            table21.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table21.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table20.DefaultCell.PaddingTop          = 6;
            table20.DefaultCell.BorderWidth         = 0;
            table20.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table20.DefaultCell.VerticalAlignment   = Element.ALIGN_RIGHT;
            table20.DefaultCell.PaddingTop          = -17;
            Chunk c1 = new Chunk(person.name, FontFactory.GetFont("Sitka Small"));

            c1.Font.Color = new BaseColor(0, 0, 0);
            c1.Font.SetStyle(0);
            c1.Font.Size = 25;
            Phrase p1 = new Phrase();

            p1.Add(c1);
            table1.AddCell(p1);
            Chunk c2 = new Chunk(person.address, FontFactory.GetFont("Sitka Display"));

            c2.Font.Color = new BaseColor(0, 0, 0);
            c2.Font.SetStyle(0);
            c2.Font.Size = 14;
            Phrase p2 = new Phrase();

            p2.Add(c2);
            table2.AddCell(p2);
            Chunk c3 = new Chunk(person.contactNum, FontFactory.GetFont("Sitka Display"));

            //Console.WriteLine();
            c3.Font.Color = new BaseColor(0, 0, 0);
            c3.Font.SetStyle(1);
            c3.Font.Size = 13;
            Phrase p3 = new Phrase();

            p3.Add(c3);
            table2.AddCell(p3);

            Chunk c4 = new Chunk(person.email, FontFactory.GetFont("Sitka Display"));

            c4.Font.Color = new BaseColor(0, 0, 0);
            c4.Font.SetStyle(2);
            c4.Font.Size = 13;
            //Console.WriteLine();
            Phrase p4 = new Phrase();

            p4.Add(c4);
            table2.AddCell(p4);

            Chunk c5 = new Chunk("Objective", FontFactory.GetFont("Stika Text"));

            c5.Font.Color = new BaseColor(0, 0, 0);
            c5.Font.SetStyle(1);
            c5.Font.Size = 18;
            Phrase p5 = new Phrase();

            p5.Add(c5);
            table3.AddCell(p5);
            Chunk c6 = new Chunk(person.objective, FontFactory.GetFont("Stika Text"));

            c6.Font.Color = new BaseColor(0, 0, 0);
            c6.Font.SetStyle(0);
            c6.Font.Size = 14;
            Phrase p6 = new Phrase();

            p6.Add(c6);
            table4.AddCell(p6);

            Chunk c7 = new Chunk("Education", FontFactory.GetFont("Stika Text"));

            c7.Font.Color = new BaseColor(0, 0, 0);
            c7.Font.SetStyle(1);
            c7.Font.Size = 18;
            Phrase p7 = new Phrase();

            p7.Add(c7);
            table5.AddCell(p7);
            Chunk c8 = new Chunk(person.city, FontFactory.GetFont("Stika Display"));

            c8.Font.Color = new BaseColor(0, 0, 0);
            c8.Font.SetStyle(0);
            c8.Font.Size = 14;
            Phrase p8 = new Phrase();

            p8.Add(c8);
            table6.AddCell(p8);
            Chunk c9 = new Chunk(uni.startedFrom + " " + uni.endedOn, FontFactory.GetFont("Stika Display"));

            c9.Font.Color = new BaseColor(0, 0, 0);
            c9.Font.SetStyle(0);
            c9.Font.Size = 14;
            Phrase p9 = new Phrase();

            p9.Add(c9);
            table7.AddCell(p9);
            Chunk c10 = new Chunk(uni.instituteName, FontFactory.GetFont("Stika Text"));

            c10.Font.SetStyle(1);
            c10.Font.Size = 16;
            Phrase p10 = new Phrase();

            p10.Add(c10);
            table8.AddCell(p10);
            Chunk c11 = new Chunk(uni.qualification, FontFactory.GetFont("Stika Text"));

            c11.Font.SetStyle(4);
            c11.Font.Size = 13;
            Phrase p11 = new Phrase();

            p11.Add(c11);
            table9.AddCell(p11);
            Chunk c12 = new Chunk("");

            c12.Font.SetStyle(0);
            c12.Font.Size = 13;
            Phrase p12 = new Phrase();

            p12.Add(c12);
            table10.AddCell(p12);
            Chunk c13 = new Chunk(col.instituteName, FontFactory.GetFont("Stika Small"));

            c13.Font.Color = new BaseColor(0, 0, 0);
            c13.Font.SetStyle(1);
            c13.Font.Size = 16;
            Phrase p13 = new Phrase();

            p13.Add(c13);
            table11.AddCell(p13);
            Chunk c14 = new Chunk(col.qualification, FontFactory.GetFont("Stika Small"));

            c14.Font.Color = new BaseColor(0, 0, 0);
            c14.Font.SetStyle(0);
            c14.Font.Size = 13;
            Phrase p14 = new Phrase();

            p14.Add(c14);
            table11.AddCell(p14);
            Chunk c15 = new Chunk(sch.instituteName, FontFactory.GetFont("Stika Text"));

            c15.Font.Color = new BaseColor(0, 0, 0);
            c15.Font.SetStyle(1);
            c15.Font.Size = 18;
            Phrase p15 = new Phrase();

            p15.Add(c15);
            table12.AddCell(p15);
            Chunk c16 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c16.Font.Color = new BaseColor(0, 0, 0);
            c16.Font.SetStyle(0);
            c16.Font.Size = 13;
            Phrase p16 = new Phrase();

            p16.Add(c16);
            table13.AddCell(p16);
            Chunk c17 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c17.Font.Color = new BaseColor(0, 0, 0);
            c17.Font.SetStyle(0);
            c17.Font.Size = 13;
            Phrase p17 = new Phrase();

            p17.Add(c17);
            table13.AddCell(p17);
            Chunk c18 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c18.Font.Color = new BaseColor(0, 0, 0);
            c18.Font.SetStyle(0);
            c18.Font.Size = 13;
            Phrase p18 = new Phrase();

            p18.Add(c18);
            table13.AddCell(p18);
            Chunk c19 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c19.Font.Color = new BaseColor(0, 0, 0);
            c19.Font.SetStyle(0);
            c19.Font.Size = 13;
            Phrase p19 = new Phrase();

            p19.Add(c19);
            table13.AddCell(p19);
            Chunk c20 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c20.Font.Color = new BaseColor(0, 0, 0);
            c20.Font.SetStyle(0);
            c20.Font.Size = 13;
            Phrase p20 = new Phrase();

            p20.Add(c20);
            table13.AddCell(p20);
            Chunk c21 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c21.Font.Color = new BaseColor(0, 0, 0);
            c21.Font.SetStyle(0);
            c21.Font.Size = 13;
            Phrase p21 = new Phrase();

            p21.Add(c21);
            table13.AddCell(p21);
            Chunk c22 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c22.Font.Color = new BaseColor(0, 0, 0);
            c22.Font.SetStyle(0);
            c22.Font.Size = 13;
            Phrase p22 = new Phrase();

            p22.Add(c22);
            table13.AddCell(p22);
            Chunk c23 = new Chunk("Work Experience:", FontFactory.GetFont("Stika Text"));

            c23.Font.Color = new BaseColor(0, 0, 0);
            c23.Font.SetStyle(1);
            c23.Font.Size = 18;
            Phrase p23 = new Phrase();

            p23.Add(c23);
            table14.AddCell(p23);
            Chunk c24 = new Chunk(work.employer, FontFactory.GetFont("Stika Small"));

            c24.Font.Color = new BaseColor(0, 0, 0);
            c24.Font.SetStyle(0);
            c24.Font.Size = 13;
            Phrase p24 = new Phrase();

            p24.Add(c24);
            table15.AddCell(p24);
            Chunk c25 = new Chunk(work.position, FontFactory.GetFont("Stika Small"));

            c25.Font.Color = new BaseColor(0, 0, 0);
            c25.Font.SetStyle(0);
            c25.Font.Size = 13;
            Phrase p25 = new Phrase();

            p25.Add(c25);
            table15.AddCell(p25);
            Chunk c26 = new Chunk(work.startedFrom + " " + work.endedOn, FontFactory.GetFont("Stika Small"));

            c26.Font.Color = new BaseColor(0, 0, 0);
            c26.Font.SetStyle(0);
            c26.Font.Size = 13;
            Phrase p26 = new Phrase();

            p26.Add(c26);
            table15.AddCell(p26);
            Chunk c27 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c27.Font.Color = new BaseColor(0, 0, 0);
            c27.Font.SetStyle(0);
            c27.Font.Size = 13;
            Phrase p27 = new Phrase();

            p27.Add(c27);
            table15.AddCell(p27);
            Chunk c28 = new Chunk("Skills:", FontFactory.GetFont("Stika Text"));

            c28.Font.Color = new BaseColor(0, 0, 0);
            c28.Font.SetStyle(1);
            c28.Font.Size = 18;
            Phrase p28 = new Phrase();

            p28.Add(c28);
            table16.AddCell(p28);
            Chunk c29 = new Chunk(adc.courseName, FontFactory.GetFont("Stika Small"));

            c29.Font.Color = new BaseColor(0, 0, 0);
            c29.Font.SetStyle(0);
            c29.Font.Size = 13;
            Phrase p29 = new Phrase();

            p29.Add(c29);
            table17.AddCell(p29);
            Chunk c30 = new Chunk(adc.courseFrom, FontFactory.GetFont("Stika Small"));

            c30.Font.Color = new BaseColor(0, 0, 0);
            c30.Font.SetStyle(0);
            c30.Font.Size = 13;
            Phrase p30 = new Phrase();

            p30.Add(c30);
            table17.AddCell(p30);
            Chunk c31 = new Chunk(" ", FontFactory.GetFont("Stika Small"));

            c31.Font.Color = new BaseColor(0, 0, 0);
            c31.Font.SetStyle(0);
            c31.Font.Size = 13;
            Phrase p31 = new Phrase();

            p31.Add(c31);
            table17.AddCell(p31);
            Chunk c32 = new Chunk(person.city, FontFactory.GetFont("Stika Small"));

            c32.Font.Color = new BaseColor(2, 2, 2);
            c32.Font.SetStyle(1);
            c32.Font.Size = 14;
            Phrase p32 = new Phrase();

            p32.Add(c32);
            table18.AddCell(p32);

            Chunk c33 = new Chunk(col.startedFrom + " " + col.endedOn, FontFactory.GetFont("Stika Small"));

            c33.Font.Color = new BaseColor(2, 2, 2);
            c33.Font.SetStyle(0);
            c33.Font.Size = 14;
            Phrase p33 = new Phrase();

            p33.Add(c33);
            table19.AddCell(p33);
            Chunk c34 = new Chunk(person.city, FontFactory.GetFont("Stika Small"));

            c34.Font.Color = new BaseColor(2, 2, 2);
            c34.Font.SetStyle(1);
            c34.Font.Size = 14;
            Phrase p34 = new Phrase();

            p34.Add(c34);
            table20.AddCell(p34);
            Chunk c35 = new Chunk(sch.startedFrom + " " + sch.endedOn, FontFactory.GetFont("Stika Small"));

            c35.Font.Color = new BaseColor(2, 2, 2);
            c35.Font.SetStyle(0);
            c35.Font.Size = 14;
            Phrase p35 = new Phrase();

            p35.Add(c35);
            table21.AddCell(p35);

            doc1.Add(table1);
            doc1.Add(table2);
            doc1.Add(table3);
            doc1.Add(table4);
            doc1.Add(table5);
            doc1.Add(table6);
            doc1.Add(table7);
            doc1.Add(table8);
            doc1.Add(table9);
            doc1.Add(table10);
            doc1.Add(table11);
            doc1.Add(table12);
            doc1.Add(table13);

            doc1.Add(table18);
            doc1.Add(table19);
            doc1.Add(table20);
            doc1.Add(table21);

            if (person.isExperienced == true)
            {
                doc1.Add(table14);
                doc1.Add(table15);
            }
            if (person.hasSkill == true)
            {
                doc1.Add(table16);
                doc1.Add(table17);
            }

            doc1.Close();
            MessageBox.Show("Created");
        }
    public MemoryStream GeneratePDF()
    {
        //  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cnstring"].ConnectionString);
        dt = new DataSet();

        cmd             = new SqlCommand();
        cmd.CommandText = "creditnotes_invoice1";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@id", orderid);
        cmd.Connection = con;
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        da = new SqlDataAdapter(cmd);
        da.Fill(dt);

        Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
        MemoryStream PDFData = new MemoryStream();
        PdfWriter    writer  = PdfWriter.GetInstance(pdfDoc, PDFData);

        var titleFont     = FontFactory.GetFont("Arial", 6, Font.NORMAL);
        var titleFontBlue = FontFactory.GetFont("Arial", 18, Font.NORMAL, Color.BLACK);
        //var boldTableFont = FontFactory.GetFont("Arial", 6, Font.BOLD);//8
        var   boldTableFont              = FontFactory.GetFont("Arial", 6, Font.BOLD);                //8
        var   boldTableFont1             = FontFactory.GetFont("Arial", 8, Font.BOLD);                //8
        var   bodyFont                   = FontFactory.GetFont("Arial", 7, Font.NORMAL);              //8
        var   EmailFont                  = FontFactory.GetFont("Arial", 7, Font.BOLD, Color.BLACK);   //8
        var   footerfont                 = FontFactory.GetFont("Arial", 6, Font.NORMAL, Color.BLACK); //8
        var   newfontt                   = FontFactory.GetFont("Arial", 6, Font.NORMAL, Color.BLACK); //8
        Color TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");

        Rectangle pageSize = writer.PageSize;

        // Open the Document for writing
        pdfDoc.Open();
        //Add elements to the document here



        #region Top table
        // Create the header table
        PdfPTable headertable = new PdfPTable(1);
        headertable.HorizontalAlignment = 0;
        headertable.WidthPercentage     = 100;
        headertable.SetWidths(new float[] { 440f });    // then set the column's __relative__ widths
        headertable.DefaultCell.Border = Rectangle.NO_BORDER;
        headertable.DefaultCell.Border = Rectangle.BOX; //for testing

        //iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Images/500.png"));
        //// //logo.ScaleToFit(100,80);
        ////logo.ScaleToFit(70, 120);
        //logo.ScaleToFit(70, 120);
        //{

        //    PdfPCell pdfCelllogo = new PdfPCell(logo);
        //    pdfCelllogo.Border = Rectangle.NO_BORDER;
        //    pdfCelllogo.BorderColorBottom = new Color(System.Drawing.Color.Black);
        //    pdfCelllogo.BorderWidthBottom = 1f;
        //    pdfCelllogo.Top = 0;


        //    headertable.AddCell(pdfCelllogo);
        //}

        {
            PdfPTable nested = new PdfPTable(1);

            nested.DefaultCell.Border = Rectangle.NO_BORDER;



            PdfPCell nextPostCell1 = new PdfPCell(new Phrase(dt.Tables[2].Rows[0]["shopName"].ToString(), titleFontBlue));
            nextPostCell1.Border = Rectangle.NO_BORDER;
            nextPostCell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            nested.AddCell(nextPostCell1);
            string   ddd           = dt.Tables[2].Rows[0]["address"].ToString() + "\n" + dt.Tables[2].Rows[0]["phone"].ToString();
            PdfPCell nextPostCell2 = new PdfPCell(new Phrase(ddd, boldTableFont1));
            nextPostCell2.Border = Rectangle.NO_BORDER;
            nextPostCell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            nested.AddCell(nextPostCell2);
            PdfPCell nextPostCell3 = new PdfPCell(new Phrase(dt.Tables[2].Rows[0]["GSTIN"].ToString(), boldTableFont1));
            nextPostCell3.Border = Rectangle.NO_BORDER;
            nextPostCell3.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            nested.AddCell(nextPostCell3);
            //PdfPCell nextPostCell4 = new PdfPCell(new Phrase("The Leading Manufacturing Company For exercise Notebook & All kind of stationary products", titleFont));
            //nextPostCell4.Border = Rectangle.NO_BORDER;
            //nested.AddCell(nextPostCell4);


            nested.AddCell("");


            PdfPCell nesthousing = new PdfPCell(nested);


            nesthousing.Border            = Rectangle.NO_BORDER;
            nesthousing.BorderColorBottom = new Color(System.Drawing.Color.Black);
            nesthousing.BorderWidthBottom = 1f;
            headertable.AddCell(nesthousing);
        }



        // invoice rperte

        PdfPTable Invoicetable2 = new PdfPTable(1);
        Invoicetable2.HorizontalAlignment = 0;
        Invoicetable2.WidthPercentage     = 100;
        Invoicetable2.SetWidths(new float[] { 500f });  // then set the column's __relative__ widths
        Invoicetable2.DefaultCell.Border = Rectangle.NO_BORDER;
        //**********
        {
            PdfPTable tablenew = new PdfPTable(3);


            PdfPCell cellnew2 = new PdfPCell(new Phrase(" Name : " + dt.Tables[1].Rows[0]["NAME"].ToString() + "\n Address :" + dt.Tables[1].Rows[0]["address"].ToString() + "\n Mobile No. : " + "" + dt.Tables[1].Rows[0]["phone"].ToString() + "" + "\n" + "GST No." + dt.Tables[1].Rows[0]["gstno"].ToString() + "                                                     ", EmailFont));

            PdfPCell cellnew3 = new PdfPCell(new Phrase("Credit Note No.:" + dt.Tables[0].Rows[0]["id"].ToString() + "\n" + "Date :" + dt.Tables[0].Rows[0]["createddate"].ToString() + "\n" + "Reason :" + dt.Tables[0].Rows[0]["reason"].ToString(), EmailFont));


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



            cellnew2.Colspan = 2;
            tablenew.AddCell(cellnew2);

            //cellnew3.Colspan = 2;
            tablenew.AddCell(cellnew3);


            PdfPCell nesthousingn = new PdfPCell(tablenew);
            nesthousingn.Border = Rectangle.NO_BORDER;

            nesthousingn.PaddingBottom = 10f;
            Invoicetable2.AddCell(nesthousingn);
        }
        //******
        //invoice repeat
        pdfDoc.Add(headertable);
        Invoicetable2.SpacingBefore = 3f;
        //  Invoicetable. = 10f;

        // pdfDoc.Add(Invoicetable);

        pdfDoc.Add(Invoicetable2);


        #endregion

        #region Items Table
        //Create body table
        PdfPTable itemTable = new PdfPTable(3);

        itemTable.HorizontalAlignment = 0;
        itemTable.WidthPercentage     = 100;
        // itemTable.SetWidths(new float[] {2,30,6,6,6,6,6,6,6,6,6,4,4,7 }); 4, 30, 6, 6, 6, 6, 6, 6, 6 // then set the column's __relative__ widths
        itemTable.SetWidths(new float[] { 4, 30, 6 });
        itemTable.SpacingAfter = 10;

        itemTable.DefaultCell.Border = Rectangle.BOX;

        PdfPCell cell1 = new PdfPCell(new Phrase("Sr No", boldTableFont));
        cell1.BackgroundColor     = TabelHeaderBackGroundColor;
        cell1.HorizontalAlignment = Element.ALIGN_CENTER;
        itemTable.AddCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase("Description", boldTableFont));
        cell2.BackgroundColor     = TabelHeaderBackGroundColor;
        cell2.HorizontalAlignment = 1;
        itemTable.AddCell(cell2);



        PdfPCell cell3 = new PdfPCell(new Phrase("Amount", boldTableFont));
        cell3.BackgroundColor     = TabelHeaderBackGroundColor;
        cell3.HorizontalAlignment = 1;
        itemTable.AddCell(cell3);


        foreach (DataRow row in dt.Tables[0].Rows)
        {
            //name of product
            var _phrase1 = new Phrase();
            _phrase1.Add(new Chunk(row["sr"].ToString(), EmailFont));
            PdfPCell descCells = new PdfPCell(_phrase1);
            descCells.HorizontalAlignment = 0;
            descCells.PaddingLeft         = 10f;
            descCells.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
            itemTable.AddCell(descCells);

            //name of product
            var _phrase = new Phrase();
            _phrase.Add(new Chunk(row["description"].ToString(), EmailFont));
            PdfPCell descCell = new PdfPCell(_phrase);
            descCell.HorizontalAlignment = 0;
            descCell.PaddingLeft         = 10f;
            descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
            itemTable.AddCell(descCell);

            //totalqty
            PdfPCell amountCell = new PdfPCell(new Phrase(new Chunk(row["famt"].ToString(), EmailFont)));
            amountCell.HorizontalAlignment = 1;
            amountCell.PaddingLeft         = 10f;
            amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
            itemTable.AddCell(amountCell);
        }
        // Table footer
        //sr number
        PdfPCell totalAmtCell1 = new PdfPCell(new Phrase("", bodyFont));
        totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
        totalAmtCell1.HorizontalAlignment = 1;
        itemTable.AddCell(totalAmtCell1);

        PdfPCell totalAmtCell2 = new PdfPCell(new Phrase("Total Amount : ", FontFactory.GetFont("arial", 7, Font.BOLD)));
        totalAmtCell2.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;
        totalAmtCell2.HorizontalAlignment = 2;
        itemTable.AddCell(totalAmtCell2);

        //PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(Total_TotalQty.ToString(), bodyFont));
        PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(dt.Tables[0].Rows[0]["ftotal"].ToString(), bodyFont));
        totalAmtCell3.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;
        totalAmtCell3.HorizontalAlignment = 1;
        itemTable.AddCell(totalAmtCell3);



        pdfDoc.Add(itemTable);


        PdfPTable Invoicetable3 = new PdfPTable(1);
        Invoicetable3.HorizontalAlignment = 0;
        Invoicetable3.WidthPercentage     = 100;
        Invoicetable3.SetWidths(new float[] { 500f });  // then set the column's __relative__ widths
        Invoicetable3.DefaultCell.Border = Rectangle.NO_BORDER;
        Invoicetable3.SpacingBefore      = 10f;
        // Invoicetable3.SpacingBefore = 270f;
        PdfPTable tablenewt = new PdfPTable(5);

        PdfPCell cellnewt = new PdfPCell(new Phrase("In Words :" + dt.Tables[0].Rows[0]["inwords"].ToString(), FontFactory.GetFont("Mangal", 8, Font.BOLD)));
        cellnewt.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
        cellnewt.Colspan             = 100;
        cellnewt.HorizontalAlignment = 1;

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

        tablenewt.AddCell(cellnewt);

        PdfPCell cellnew1t;
        PdfPCell cellnew2t;

        cellnew1t = new PdfPCell(new Phrase("Total Amount:", EmailFont));
        cellnew1t.BackgroundColor     = new Color(System.Drawing.Color.Khaki);
        cellnew1t.HorizontalAlignment = 2;


        cellnew2t = new PdfPCell(new Phrase(dt.Tables[0].Rows[0]["ftotal"].ToString(), EmailFont));
        cellnew2t.BackgroundColor = new Color(System.Drawing.Color.Khaki);
        cellnew2t.Colspan         = 2;
        //tablenewt.AddCell(cellnew1t);

        //tablenewt.AddCell(cellnew2t);


        PdfPCell cellnew3t = new PdfPCell(new Phrase("Declaration : We declare that this invoice shows the actual price of the goods described and that all particulars are true and coorect.", EmailFont));



        cellnew3t.Colspan = 7;
        tablenewt.AddCell(cellnew3t);



        PdfPCell nesthousingnt = new PdfPCell(tablenewt);
        nesthousingnt.Border = Rectangle.NO_BORDER;

        nesthousingnt.PaddingBottom = 10f;
        Invoicetable3.AddCell(nesthousingnt);


        //pdfDoc.Add(itemTable);
        pdfDoc.Add(Invoicetable3);

        #endregion



        //////////////////////////////////////

        pdfDoc.Close();


        return(PDFData);
    }
Ejemplo n.º 8
0
        public ActionResult Disbursement(Int32 DisbursementId)
        {
            // ==============================
            // PDF Settings and Customization
            // ==============================
            MemoryStream workStream = new MemoryStream();
            Rectangle    rectangle  = new Rectangle(PageSize.A3);
            Document     document   = new Document(rectangle, 72, 72, 72, 72);

            document.SetMargins(30f, 30f, 30f, 30f);
            PdfWriter.GetInstance(document, workStream).CloseStream = false;

            document.Open();

            // =====
            // Fonts
            // =====
            Font fontArial17Bold = FontFactory.GetFont("Arial", 17, Font.BOLD);
            Font fontArial11     = FontFactory.GetFont("Arial", 11);
            Font fontArial9Bold  = FontFactory.GetFont("Arial", 9, Font.BOLD);
            Font fontArial9      = FontFactory.GetFont("Arial", 9);
            Font fontArial10Bold = FontFactory.GetFont("Arial", 10, Font.BOLD);
            Font fontArial10     = FontFactory.GetFont("Arial", 10);
            Font fontArial11Bold = FontFactory.GetFont("Arial", 11, Font.BOLD);
            Font fontArial12Bold = FontFactory.GetFont("Arial", 12, Font.BOLD);
            Font fontArial13Bold = FontFactory.GetFont("Arial", 13, Font.BOLD);

            Paragraph line = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 4.5F)));

            var identityUserId   = User.Identity.GetUserId();
            var currentUser      = from d in db.MstUsers where d.UserId == identityUserId select d;
            var currentCompanyId = currentUser.FirstOrDefault().CompanyId;
            var currentBranchId  = currentUser.FirstOrDefault().BranchId;

            // ==============
            // Company Detail
            // ==============
            var companyName = (from d in db.MstCompanies where d.Id == Convert.ToInt32(currentCompanyId) select d.Company).FirstOrDefault();
            var address     = (from d in db.MstCompanies where d.Id == Convert.ToInt32(currentCompanyId) select d.Address).FirstOrDefault();
            var contactNo   = (from d in db.MstCompanies where d.Id == Convert.ToInt32(currentCompanyId) select d.ContactNumber).FirstOrDefault();
            var branch      = (from d in db.MstBranches where d.Id == Convert.ToInt32(currentBranchId) select d.Branch).FirstOrDefault();

            // ===========
            // Header Page
            // ===========
            PdfPTable headerPage = new PdfPTable(2);

            float[] widthsCellsHeaderPage = new float[] { 100f, 75f };
            headerPage.SetWidths(widthsCellsHeaderPage);
            headerPage.WidthPercentage = 100;
            headerPage.AddCell(new PdfPCell(new Phrase(companyName, fontArial17Bold))
            {
                Border = 0
            });
            headerPage.AddCell(new PdfPCell(new Phrase("Check / Cash Voucher", fontArial17Bold))
            {
                Border = 0, HorizontalAlignment = 2
            });
            headerPage.AddCell(new PdfPCell(new Phrase(address, fontArial11))
            {
                Border = 0, PaddingTop = 5f
            });
            headerPage.AddCell(new PdfPCell(new Phrase(branch, fontArial11))
            {
                Border = 0, PaddingTop = 5f, HorizontalAlignment = 2
            });
            headerPage.AddCell(new PdfPCell(new Phrase(contactNo, fontArial11))
            {
                Border = 0, PaddingTop = 5f
            });
            headerPage.AddCell(new PdfPCell(new Phrase("Printed " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToString("hh:mm:ss tt"), fontArial11))
            {
                Border = 0, PaddingTop = 5f, HorizontalAlignment = 2
            });
            document.Add(headerPage);

            // =====
            // Space
            // =====
            PdfPTable spaceTable = new PdfPTable(1);

            float[] widthCellsSpaceTable = new float[] { 100f };
            spaceTable.SetWidths(widthCellsSpaceTable);
            spaceTable.WidthPercentage = 100;
            spaceTable.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
            {
                Border = 0, PaddingTop = 5f
            });

            document.Add(line);

            // ================
            // Get Disbursement
            // ================
            var disbursements = from d in db.TrnDisbursements
                                where d.Id == DisbursementId &&
                                d.IsLocked == true
                                select d;

            if (disbursements.Any())
            {
                String payee       = disbursements.FirstOrDefault().Payee;
                String bank        = disbursements.FirstOrDefault().MstArticle1.Article;
                String particulars = disbursements.FirstOrDefault().Particulars;
                String checkNo     = disbursements.FirstOrDefault().CheckNumber;
                String CVNumber    = disbursements.FirstOrDefault().CVNumber;
                String CVDate      = disbursements.FirstOrDefault().CVDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
                String checkDate   = disbursements.FirstOrDefault().CheckDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
                String preparedBy  = disbursements.FirstOrDefault().MstUser3.FullName;
                String checkedBy   = disbursements.FirstOrDefault().MstUser1.FullName;
                String approvedBy  = disbursements.FirstOrDefault().MstUser.FullName;

                PdfPTable tableDisbursement            = new PdfPTable(4);
                float[]   widthscellsTableDisbursement = new float[] { 40f, 150f, 70f, 50f };
                tableDisbursement.SetWidths(widthscellsTableDisbursement);
                tableDisbursement.WidthPercentage = 100;

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Payee", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 10f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(payee, fontArial11))
                {
                    Border = 0, PaddingTop = 10f, PaddingLeft = 5f, PaddingRight = 5f
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("No.", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 10f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(CVNumber, fontArial11))
                {
                    Border = 0, PaddingTop = 10f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Particulars", fontArial11Bold))
                {
                    Rowspan = 3, Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });

                var particularsPhrase = new Phrase();
                particularsPhrase.Add(new Chunk(particulars, fontArial11));

                Paragraph particularsParagraph = new Paragraph();
                particularsParagraph.Add(particularsPhrase);

                PdfPCell particularsCell = new PdfPCell();
                particularsCell.AddElement(particularsParagraph);

                tableDisbursement.AddCell(new PdfPCell(particularsCell)
                {
                    Rowspan = 4, Border = 0, PaddingTop = 0f, PaddingLeft = 5f, PaddingRight = 5f
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Date", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(CVDate, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Check No.", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(checkNo, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Check Date", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(checkDate, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });

                tableDisbursement.AddCell(new PdfPCell(new Phrase("Bank", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(bank, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                document.Add(tableDisbursement);

                document.Add(spaceTable);

                // ===========
                // Get Journal
                // ===========
                var journals = from d in db.TrnJournals
                               where d.CVId == DisbursementId
                               select new
                {
                    Id                = d.Id,
                    JournalDate       = d.JournalDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture),
                    BranchId          = d.BranchId,
                    Branch            = d.MstBranch.Branch,
                    AccountId         = d.AccountId,
                    Account           = d.MstAccount.Account,
                    AccountCode       = d.MstAccount.AccountCode,
                    ArticleId         = d.ArticleId,
                    Article           = d.MstArticle.Article,
                    Particulars       = d.Particulars,
                    DebitAmount       = d.DebitAmount,
                    CreditAmount      = d.CreditAmount,
                    ORId              = d.ORId,
                    CVId              = d.CVId,
                    JVId              = d.JVId,
                    RRId              = d.RRId,
                    SIId              = d.SIId,
                    INId              = d.INId,
                    OTId              = d.OTId,
                    STId              = d.STId,
                    DocumentReference = d.DocumentReference,
                    APRRId            = d.APRRId,
                    ARSIId            = d.ARSIId,
                };

                if (journals.Any())
                {
                    PdfPTable tableJournal       = new PdfPTable(6);
                    float[]   widthscellsJournal = new float[] { 120f, 90f, 130f, 150f, 100f, 100f };
                    tableJournal.SetWidths(widthscellsJournal);
                    tableJournal.WidthPercentage = 100;
                    tableJournal.AddCell(new PdfPCell(new Phrase("Branch", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Code", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Account", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Article", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Debit", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Credit", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });

                    Decimal totalDebitAmount  = 0;
                    Decimal totalCreditAmount = 0;

                    foreach (var journal in journals)
                    {
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.Branch, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.AccountCode, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.Account, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.Article, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.DebitAmount.ToString("#,##0.00"), fontArial11))
                        {
                            HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.CreditAmount.ToString("#,##0.00"), fontArial11))
                        {
                            HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });

                        totalDebitAmount  += journal.DebitAmount;
                        totalCreditAmount += journal.CreditAmount;
                    }

                    tableJournal.AddCell(new PdfPCell(new Phrase("Total", fontArial11Bold))
                    {
                        Colspan = 4, HorizontalAlignment = 2, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase(totalDebitAmount.ToString("#,##0.00"), fontArial11Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase(totalCreditAmount.ToString("#,##0.00"), fontArial11Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    document.Add(tableJournal);

                    document.Add(spaceTable);
                }

                // ======================
                // Get Disbursement Lines
                // ======================
                var disbursementLines = from d in db.TrnDisbursementLines
                                        where d.CVId == DisbursementId &&
                                        d.TrnDisbursement.IsLocked == true
                                        select new
                {
                    Id          = d.Id,
                    CVId        = d.CVId,
                    CV          = d.TrnDisbursement.CVNumber,
                    BranchId    = d.BranchId,
                    Branch      = d.MstBranch.Branch,
                    AccountId   = d.AccountId,
                    Account     = d.MstAccount.Account,
                    ArticleId   = d.ArticleId,
                    Article     = d.MstArticle.Article,
                    RRId        = d.RRId,
                    RR          = d.TrnReceivingReceipt,
                    Particulars = d.Particulars,
                    Amount      = d.Amount
                };

                if (disbursementLines.Any())
                {
                    PdfPTable tableDisbursementLines       = new PdfPTable(4);
                    float[]   widthscellsDisbursementLines = new float[] { 120f, 80f, 140f, 100f };
                    tableDisbursementLines.SetWidths(widthscellsDisbursementLines);
                    tableDisbursementLines.WidthPercentage = 100;
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("RR No.", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("RR Date", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Particulars", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Paid Amount", fontArial11Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });

                    Decimal totalPaidAmount = 0;

                    foreach (var disbursementLine in disbursementLines)
                    {
                        String RRNumber = " ", RRDate = " ";
                        if (disbursementLine.RRId != null)
                        {
                            RRNumber = disbursementLine.RR.RRNumber;
                            RRDate   = disbursementLine.RR.RRDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
                        }

                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(RRNumber, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(RRDate, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(disbursementLine.Particulars, fontArial11))
                        {
                            HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(disbursementLine.Amount.ToString("#,##0.00"), fontArial11))
                        {
                            HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                        });

                        totalPaidAmount += disbursementLine.Amount;
                    }

                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Total", fontArial11Bold))
                    {
                        Colspan = 3, HorizontalAlignment = 2, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase(totalPaidAmount.ToString("#,##0.00"), fontArial11Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    document.Add(tableDisbursementLines);

                    document.Add(spaceTable);
                }

                // ==============
                // User Signature
                // ==============
                PdfPTable tableUsers            = new PdfPTable(3);
                float[]   widthsCellsTableUsers = new float[] { 100f, 100f, 100f };
                tableUsers.WidthPercentage = 100;
                tableUsers.SetWidths(widthsCellsTableUsers);
                tableUsers.AddCell(new PdfPCell(new Phrase("Prepared by", fontArial11Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase("Checked by", fontArial11Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase("Approved by", fontArial11Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 50f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 50f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 50f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(preparedBy, fontArial11))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(checkedBy, fontArial11))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUsers.AddCell(new PdfPCell(new Phrase(approvedBy, fontArial11))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                document.Add(tableUsers);

                document.Add(spaceTable);

                // ================
                // Money Word Table
                // ================
                PdfPTable tableMoneyWord = new PdfPTable(3)
                {
                    WidthPercentage = 100
                };
                float[] widthsSignFooterCells = new float[] { 40f, 100f, 140f };
                tableMoneyWord.SetWidths(widthsSignFooterCells);
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Check No.", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(checkNo, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });


                String paidAmount        = Convert.ToString(Math.Round(disbursements.FirstOrDefault().Amount * 100) / 100);
                var    amountTablePhrase = new Phrase();
                var    amountString      = "ZERO";

                if (Convert.ToDecimal(paidAmount) != 0)
                {
                    amountString = GetMoneyWord(paidAmount).ToUpper();
                }

                amountTablePhrase.Add(new Chunk("Representing Payment from " + companyName + "the amount of ", fontArial11));
                amountTablePhrase.Add(new Chunk(amountString, fontArial11Bold));

                Paragraph paragraphAmountTable = new Paragraph();
                paragraphAmountTable.SetLeading(0, 1.4f);
                paragraphAmountTable.Add(amountTablePhrase);

                PdfPCell chunkyAmountTable = new PdfPCell();
                chunkyAmountTable.AddElement(paragraphAmountTable);
                chunkyAmountTable.BorderWidth = PdfPCell.NO_BORDER;

                tableMoneyWord.AddCell(new PdfPCell(chunkyAmountTable)
                {
                    Rowspan = 3, Border = 0, PaddingTop = 0f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 0
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Check Date", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(checkDate, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Bank", fontArial11Bold))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(bank, fontArial11))
                {
                    Border = 0, PaddingTop = 5f, PaddingLeft = 5f, PaddingRight = 5f
                });
                document.Add(tableMoneyWord);

                document.Add(Chunk.NEWLINE);
                document.Add(Chunk.NEWLINE);

                // ===============
                // Signature Table
                // ===============
                PdfPTable tableSignature = new PdfPTable(4)
                {
                    WidthPercentage = 100
                };
                float[] widthCellsSignature = new float[] { 115f, 50f, 10f, 50f };
                tableSignature.SetWidths(widthCellsSignature);
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11Bold))
                {
                    Border = 0
                });
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11Bold))
                {
                    Border = 0
                });
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11Bold))
                {
                    Border = 0
                });
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11Bold))
                {
                    Border = 0
                });
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11))
                {
                    Border = 0,
                });
                tableSignature.AddCell(new PdfPCell(new Phrase("Signature Over Printed Name", fontArial11Bold))
                {
                    Border = 1, HorizontalAlignment = 1
                });
                tableSignature.AddCell(new PdfPCell(new Phrase(" ", fontArial11Bold))
                {
                    Border = 0
                });
                tableSignature.AddCell(new PdfPCell(new Phrase("Date", fontArial11Bold))
                {
                    Border = 1, HorizontalAlignment = 1
                });
                document.Add(tableSignature);
            }

            document.Close();

            byte[] byteInfo = workStream.ToArray();
            workStream.Write(byteInfo, 0, byteInfo.Length);
            workStream.Position = 0;

            return(new FileStreamResult(workStream, "application/pdf"));
        }
Ejemplo n.º 9
0
        public static Stream generar(HeadInvoicePDF head, List <DetailInvoicePDF> details, string pathFile)
        {
            String PDFTitle          = head.company;
            String PDFClientName     = head.clientName;
            String PDFAddress        = head.clientAddress;
            String PDFClientDocument = head.clientId;
            string PDFClientPhone    = head.clientPhone;
            string PDFClientEmail    = head.clientEmail;

            List <Dictionary <string, string> > prods = new List <Dictionary <string, string> >();

            foreach (DetailInvoicePDF detail in details)
            {
                prods.Add(convertToDictonary(detail));
            }


            //double taxAmount = 0.18;
            string       subTotal     = head.subtotal;
            string       taxOfAmount  = head.taxes;
            string       total        = head.total;
            string       companyDoc   = head.companyRuc;
            string       documentType = head.document;
            string       serieNumber  = head.serie;
            string       docNumber    = head.nroext;
            string       perc         = head.perception;
            string       dateDoc      = head.documentDate;
            string       url          = head.url;
            string       path         = "D:/ResumenFactura_" + head.document + head.serie + "-" + head.nroext + ".pdf";
            MemoryStream ms           = new MemoryStream();
            Rectangle    rec2         = new Rectangle(PageSize.A4);
            Document     doc          = new Document(rec2);
            PdfWriter    writer       = PdfWriter.GetInstance(doc, ms);

            writer.CloseStream = false;
            iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(url);
            doc.Open();
            var titleFont         = FontFactory.GetFont("Arial", 18, Font.BOLD);
            var subTitleFont      = FontFactory.GetFont("Arial", 14, Font.BOLD);
            var boldTableFont     = FontFactory.GetFont("Arial", 8, Font.BOLD);
            var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC);
            var bodyFont          = FontFactory.GetFont("Arial", 8, Font.NORMAL);
            var bodyHeaderFont    = FontFactory.GetFont("Arial", 6, Font.NORMAL);

            //doc.Add(new Paragraph(PDFTitle, titleFont));
            PdfPTable headerTable = new PdfPTable(2);

            headerTable.DefaultCell.Border    = PdfPCell.NO_BORDER;
            headerTable.DefaultCell.CellEvent = new RoundRectangleForm();
            headerTable.TotalWidth            = 520f;
            headerTable.LockedWidth           = true;
            headerTable.SetWidths(new float[] { 2f, 1f });
            //Left Header Table
            PdfPTable nestedHeaderLeftTable = new PdfPTable(2);

            nestedHeaderLeftTable.DefaultCell.Border = PdfPCell.NO_BORDER;
            nestedHeaderLeftTable.SetWidths(new float[] { 1f, 3f });
            nestedHeaderLeftTable.AddCell(myImage);
            PdfPTable headerSubTitle = new PdfPTable(1);

            headerSubTitle.DefaultCell.Border = PdfPCell.NO_BORDER;
            PdfPCell headerTitle = new PdfPCell()
            {
                Border        = PdfPCell.NO_BORDER,
                PaddingBottom = 4,
                Phrase        = new Phrase(PDFTitle, titleFont)
            };

            headerSubTitle.AddCell(headerTitle);
            headerSubTitle.AddCell(new Phrase(head.headerLeftLine1, bodyHeaderFont));
            headerSubTitle.AddCell(new Phrase(head.headerLeftLine2, bodyHeaderFont));
            headerSubTitle.AddCell(new Phrase(head.headerLeftLine3, bodyHeaderFont));
            headerSubTitle.AddCell(new Phrase(head.headerLeftLine4, bodyHeaderFont));
            headerSubTitle.AddCell(new Phrase(head.headerLeftLine5, bodyHeaderFont));
            PdfPCell nestedCell = new PdfPCell(headerSubTitle);

            nestedCell.Padding = 0f;
            nestedCell.Border  = PdfPCell.NO_BORDER;
            nestedHeaderLeftTable.AddCell(nestedCell);
            PdfPCell nesthou = new PdfPCell(nestedHeaderLeftTable);

            nesthou.Border = PdfPCell.NO_BORDER;
            nesthou.HorizontalAlignment = 1;
            headerTable.AddCell(nesthou);

            //Right Header Table
            PdfPTable nestedHeaderTable = new PdfPTable(1);

            nestedHeaderTable.DefaultCell.Border = PdfPCell.NO_BORDER;
            PdfPCell headerRUC = new PdfPCell()
            {
                Border      = PdfPCell.NO_BORDER,
                PaddingLeft = 20f,
                Phrase      = new Phrase("R.U.C. " + companyDoc, subTitleFont)
            };
            float    scaleFontSize = 9.7f;
            PdfPCell headerDocType = new PdfPCell()
            {
                Border      = PdfPCell.NO_BORDER,
                PaddingLeft = (Math.Abs(170 - documentType.Length * scaleFontSize)) / 2,
                Phrase      = new Phrase(documentType, subTitleFont)
            };
            PdfPCell headerSerie = new PdfPCell()
            {
                Border      = PdfPCell.NO_BORDER,
                PaddingLeft = 25f,
                Phrase      = new Phrase(serieNumber + " - N° " + docNumber, subTitleFont)
            };

            nestedHeaderTable.AddCell(headerRUC);
            nestedHeaderTable.AddCell(headerDocType);
            nestedHeaderTable.AddCell(headerSerie);
            PdfPCell nesthousing = new PdfPCell(nestedHeaderTable);

            nesthousing.PaddingTop          = 15f;
            nesthousing.PaddingBottom       = 15f;
            nesthousing.HorizontalAlignment = 1;
            nesthousing.Border    = PdfPCell.NO_BORDER;
            nesthousing.CellEvent = new RoundRectangleForm();
            headerTable.AddCell(nesthousing);
            doc.Add(headerTable);
            var orderInfoTable = new PdfPTable(4);

            orderInfoTable.HorizontalAlignment = 0;
            orderInfoTable.SpacingBefore       = 10;
            orderInfoTable.DefaultCell.Border  = 0;
            orderInfoTable.SetWidths(new int[] { 2, 5, 2, 7 });
            orderInfoTable.SpacingBefore = 20;


            orderInfoTable.AddCell(new Phrase("NOMBRE:", boldTableFont));
            orderInfoTable.AddCell(new Phrase(PDFClientName, bodyFont));
            orderInfoTable.AddCell(new Phrase("DIRECCIÓN:", boldTableFont));
            orderInfoTable.AddCell(new Phrase(PDFAddress, bodyFont));
            orderInfoTable.AddCell(new Phrase("RUC:", boldTableFont));
            orderInfoTable.AddCell(new Phrase(PDFClientDocument, bodyFont));
            orderInfoTable.AddCell(new Phrase("TELÉFONO:", boldTableFont));
            orderInfoTable.AddCell(new Phrase(PDFClientPhone, bodyFont));
            orderInfoTable.AddCell(new Phrase("FECHA:", boldTableFont));
            orderInfoTable.AddCell(new Phrase(dateDoc, bodyFont));
            orderInfoTable.AddCell(" ");
            orderInfoTable.AddCell(" ");

            doc.Add(orderInfoTable);
            //Preparing the table header
            PdfPTable table = new PdfPTable(1);

            table.DefaultCell.Border    = PdfPCell.NO_BORDER;
            table.DefaultCell.CellEvent = new RoundRectangleForm();
            //actual width of table in points
            table.TotalWidth = 500f;
            //fix the absolute width of the table
            table.LockedWidth         = true;
            table.HorizontalAlignment = 0;
            table.SpacingAfter        = 15f;
            PdfPTable nestedTable = new PdfPTable(5);

            nestedTable.DefaultCell.Border = PdfPCell.NO_BORDER;
            //relative col widths in proportions - 1/3 and 2/3
            float[] widths = new float[] { 3f, 1f, 1f, 1f, 1f };
            nestedTable.SetWidths(widths);
            nestedTable.HorizontalAlignment = 0;
            var descPhrase = new Phrase();

            descPhrase.Add(new Chunk("DESCRIPCIÓN", boldTableFont));
            var quanPhrase = new Phrase();

            quanPhrase.Add(new Chunk("CANTIDAD", boldTableFont));
            var pricePhrase = new Phrase();

            pricePhrase.Add(new Chunk("VAL UNIT", boldTableFont));
            var taxPhrase = new Phrase();

            taxPhrase.Add(new Chunk("IMPUESTO", boldTableFont));
            var amountPhrase = new Phrase();

            amountPhrase.Add(new Chunk("IMPORTE", boldTableFont));
            //leave a gap before and after the table
            PdfPCell descCell = new PdfPCell()
            {
                Border  = PdfPCell.BOTTOM_BORDER,
                Padding = 4,
                Phrase  = new Phrase(descPhrase)
            };
            PdfPCell impCell = new PdfPCell()
            {
                Border  = PdfPCell.BOTTOM_BORDER,
                Padding = 4,
                Phrase  = new Phrase(amountPhrase)
            };
            PdfPCell quanCell = new PdfPCell()
            {
                Border  = PdfPCell.BOTTOM_BORDER,
                Padding = 4,
                Phrase  = new Phrase(quanPhrase)
            };
            PdfPCell priceCell = new PdfPCell()
            {
                Border  = PdfPCell.BOTTOM_BORDER,
                Padding = 4,
                Phrase  = new Phrase(pricePhrase)
            };
            PdfPCell headerTaxCell = new PdfPCell()
            {
                Border  = PdfPCell.BOTTOM_BORDER,
                Padding = 4,
                Phrase  = new Phrase(taxPhrase)
            };

            nestedTable.AddCell(descCell);
            nestedTable.AddCell(quanCell);
            nestedTable.AddCell(priceCell);
            nestedTable.AddCell(headerTaxCell);
            nestedTable.AddCell(impCell);
            //Adding products
            for (int i = 0; i < 25; i++)
            {
                Phrase descP, priceP, quanP, taxP, amountP;
                if (i < prods.Count)
                {
                    descP   = new Phrase(prods[i]["desc"], bodyFont);
                    priceP  = new Phrase(prods[i]["price"], bodyFont);
                    quanP   = new Phrase(prods[i]["qua"], bodyFont);
                    taxP    = new Phrase(prods[i]["tax"], bodyFont);
                    amountP = new Phrase(prods[i]["amount"], bodyFont);
                }
                else
                {
                    descP   = new Phrase(" ");
                    priceP  = new Phrase(" ");
                    quanP   = new Phrase(" ");
                    taxP    = new Phrase(" ");
                    amountP = new Phrase(" ");
                }
                PdfPCell descPro = new PdfPCell()
                {
                    Border  = PdfPCell.NO_BORDER,
                    Padding = 4,
                    Phrase  = descP
                };
                PdfPCell pricePro = new PdfPCell()
                {
                    Border  = PdfPCell.NO_BORDER,
                    Padding = 4,
                    Phrase  = priceP
                };
                PdfPCell quanPro = new PdfPCell()
                {
                    Border        = PdfPCell.NO_BORDER,
                    PaddingTop    = 4,
                    PaddingBottom = 4,
                    PaddingLeft   = 20f,
                    Phrase        = quanP
                };
                PdfPCell taxPro = new PdfPCell()
                {
                    Border        = PdfPCell.NO_BORDER,
                    PaddingTop    = 4,
                    PaddingBottom = 4,
                    PaddingLeft   = 17f,
                    Phrase        = taxP
                };
                PdfPCell amountPro = new PdfPCell()
                {
                    Border  = PdfPCell.NO_BORDER,
                    Padding = 4,
                    Phrase  = amountP
                };

                nestedTable.AddCell(descPro);
                nestedTable.AddCell(quanPro);
                nestedTable.AddCell(pricePro);
                nestedTable.AddCell(taxPro);
                nestedTable.AddCell(amountPro);
            }

            PdfPCell subTotalCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase("Sub Total", boldTableFont)
            };
            PdfPCell subTotalValueCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase(subTotal, bodyFont)
            };
            PdfPCell tributosCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase("Impuestos:", boldTableFont)
            };


            PdfPCell taxCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase(taxOfAmount, bodyFont)
            };
            PdfPCell percCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase("Percepción", boldTableFont)
            };
            PdfPCell percValueCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase(perc, bodyFont)
            };

            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(subTotalCell);
            nestedTable.AddCell(subTotalValueCell);
            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(tributosCell);
            nestedTable.AddCell(taxCell);
            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(" ");
            nestedTable.AddCell(percCell);
            nestedTable.AddCell(percValueCell);
            table.AddCell(nestedTable);
            doc.Add(table);

            //total = subTotal + taxOfAmount;
            PdfPTable totalTable = new PdfPTable(1);

            totalTable.DefaultCell.Border = PdfPCell.NO_BORDER;
            //actual width of table in points
            totalTable.TotalWidth = 500f;
            //fix the absolute width of the table
            totalTable.LockedWidth         = true;
            totalTable.HorizontalAlignment = 0;
            PdfPTable nestedTotalTable = new PdfPTable(4);

            nestedTotalTable.DefaultCell.Border = PdfPCell.NO_BORDER;
            //relative col widths in proportions - 1/3 and 2/3
            float[] totalWidths = new float[] { 4f, 1f, 1f, 1f };
            nestedTotalTable.SetWidths(totalWidths);
            nestedTotalTable.HorizontalAlignment = 0;
            PdfPCell sonCell = new PdfPCell()
            {
                Border    = PdfPCell.NO_BORDER,
                CellEvent = new RoundRectangleForm(),
                Padding   = 4,
                Phrase    = new Phrase("SON: " + head.totalDescription, boldTableFont)
            };
            PdfPCell totalCell = new PdfPCell()
            {
                Border  = PdfPCell.NO_BORDER,
                Padding = 4,
                Phrase  = new Phrase("TOTAL:", boldTableFont)
            };
            PdfPCell totalAmountCell = new PdfPCell()
            {
                Border    = PdfPCell.NO_BORDER,
                CellEvent = new RoundRectangleForm(),
                Padding   = 4,
                Phrase    = new Phrase(total, bodyFont)
            };

            nestedTotalTable.AddCell(sonCell);
            nestedTotalTable.AddCell(" ");
            nestedTotalTable.AddCell(totalCell);
            nestedTotalTable.AddCell(totalAmountCell);
            totalTable.AddCell(nestedTotalTable);
            doc.Add(totalTable);
            doc.Add(new Paragraph(head.Observacion, bodyFont));
            doc.Close();
            ms.Flush();      //Always catches me out
            ms.Position = 0; //Not sure if this is required

            return(ms);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////
        }
Ejemplo n.º 10
0
        // write on end of each page
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            //設定中文字體
            string   chFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "KAIU.TTF");
            BaseFont chBaseFont = BaseFont.CreateFont(chFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            Font     chFont     = new iTextSharp.text.Font(chBaseFont, 14);

            // header設定
            Rectangle page = document.PageSize;
            PdfPTable head = new PdfPTable(1);

            head.TotalWidth = page.Width;
            Phrase complicatedPhrase = new Phrase();

            complicatedPhrase.Add(new Chunk("test \n", new iTextSharp.text.Font(chBaseFont, 18, 1)));
            complicatedPhrase.Add(new Chunk("TCI Co., Ltd.  ", new Font(Font.FontFamily.TIMES_ROMAN, 18, 1)));
            complicatedPhrase.Add(new Chunk("TPE/SH/JP/US/HK", new Font(Font.FontFamily.TIMES_ROMAN, 14, 1)));
            PdfPCell c = new PdfPCell(complicatedPhrase);

            c.Border              = Rectangle.NO_BORDER;
            c.VerticalAlignment   = Element.ALIGN_TOP;
            c.HorizontalAlignment = Element.ALIGN_CENTER;
            head.AddCell(c);
            head.WriteSelectedRows(
                // first/last row; -1 writes all rows
                0, -1,
                // left offset
                0,
                // ** bottom** yPos of the table
                page.Height - document.TopMargin + head.TotalHeight + 20,
                writer.DirectContent
                );

            //logo
            //將圖片加入到某個座標位置absolute position
            var imageFileName = @"test11\logo.jpg";

            iTextSharp.text.Image googleJPG1 = iTextSharp.text.Image.GetInstance(imageFileName);
            //調整圖片大小
            googleJPG1.ScalePercent(60f);
            googleJPG1.SetAbsolutePosition(65, 755);
            document.Add(googleJPG1);

            //畫圖
            PdfContentByte grx = writer.DirectContent;

            // add a rectangle
            //grx.Rectangle(100, 700, 100, 100);
            // add the diagonal
            grx.SetLineWidth(5);
            grx.SetColorStroke(BaseColor.LIGHT_GRAY);
            grx.MoveTo(40, 753);
            grx.LineTo(550, 753);
            // stroke the lines
            grx.Stroke();

            // footer設定
            PdfPTable footer = new PdfPTable(1);

            footer.TotalWidth = page.Width;
            Phrase phrase2 = new Phrase();

            phrase2.Add(new Chunk("test11 \n", new iTextSharp.text.Font(chBaseFont, 10)));
            phrase2.Add(new Chunk("test11 \n", new Font(Font.FontFamily.UNDEFINED, 10, 1)));
            phrase2.Add(new Chunk("test11 \n", new Font(Font.FontFamily.UNDEFINED, 10, 1)));

            Chunk underLineChunk = new Chunk("WWW.test11.COM ", new Font(Font.FontFamily.UNDEFINED, 10, 1));  //style =1:粗體

            underLineChunk.SetUnderline(0.2f, -2f);
            phrase2.Add(underLineChunk);
            PdfPCell c2 = new PdfPCell(phrase2);

            c2.Border              = Rectangle.NO_BORDER;
            c2.VerticalAlignment   = Element.ALIGN_TOP;
            c2.HorizontalAlignment = Element.ALIGN_CENTER;
            footer.AddCell(c2);
            footer.WriteSelectedRows(
                // first/last row; -1 writes all rows
                0, -1,
                // left offset
                0,
                // ** bottom** yPos of the table
                document.Bottom - 20,
                writer.DirectContent
                );
        }
    public byte[] PrintOPDMedicalTestRegistrationInvoice(string invoiceId, string patientName,
                                                         string patientId, string testDate, string testTime, List <string> medicalTestList)
    {
        Document document   = new Document(PageSize.A4);
        Font     NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);

        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {
            PdfWriter writer    = PdfWriter.GetInstance(document, memoryStream);
            PdfPTable table     = null;
            Phrase    phrase    = null;
            PdfPCell  cell      = null;
            Paragraph paragraph = null;
            Color     color     = null;

            document.Open();

            table = new PdfPTable(2);
            float[] widths = new float[] { 5f, 10f };
            table.SetWidths(widths);

            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("../images/logo.png"));
            image.ScaleAbsolute(80, 80);
            cell = new PdfPCell(image);

            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("ABC Hospital\n\n", FontFactory.GetFont("Arial", 18, Font.BOLD, Color.RED)));
            phrase.Add(new Chunk("123, Bodakdev\n", FontFactory.GetFont("Arial", 9, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("Ahmedabad 380015\n", FontFactory.GetFont("Arial", 9, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("INDIA\n", FontFactory.GetFont("Arial", 9, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("Ph:- 9543289345\n", FontFactory.GetFont("Arial", 9, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("Website:- http://www.abchospital.com\n", FontFactory.GetFont("Arial", 9, Font.NORMAL, Color.BLACK)));

            cell = new PdfPCell(phrase);

            table.AddCell(cell);

            color = new Color(System.Drawing.ColorTranslator.FromHtml("#000000"));
            DrawLine(writer, 25f, document.Top - 110f, document.PageSize.Width - 25f, document.Top - 110f, color);
            DrawLine(writer, 25f, document.Top - 110f, document.PageSize.Width - 25f, document.Top - 110f, color);

            phrase = new Phrase();
            phrase.Add(new Chunk("OPD MEDICAL TEST REGISTRATION INVOICE\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.BLACK)));

            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment     = Element.ALIGN_CENTER;
            paragraph.SpacingBefore = 50;
            paragraph.SpacingAfter  = 30;

            document.Add(table);
            document.Add(paragraph);

            table = new PdfPTable(2);

            phrase = new Phrase();
            phrase.Add(new Chunk("Invoice ID", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            cell.PaddingBottom = 20;
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(invoiceId, FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Invoice Date", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 20;
            paragraph          = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(DateTime.Now.ToString(), FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Patient Name", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 20;
            paragraph          = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(patientName, FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Patient ID", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 20;
            paragraph          = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(patientId, FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Date Of Medical Test", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 20;
            paragraph          = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(testDate, FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Time Of Medical Test", FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 20;
            paragraph          = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk(testTime, FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            table.AddCell(cell);

            table.HorizontalAlignment = Element.ALIGN_CENTER;

            document.Add(table);

            paragraph = new Paragraph();
            paragraph.Add(new Chunk("\n"));
            document.Add(paragraph);

            table  = new PdfPTable(2);
            widths = new float[] { 2f, 10f };
            table.SetWidths(widths);

            phrase = new Phrase();
            phrase.Add(new Chunk("Sr. No.", FontFactory.GetFont("Arial", 12, Font.BOLD, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            cell.PaddingBottom = 20;
            table.AddCell(cell);

            phrase = new Phrase();
            phrase.Add(new Chunk("Medical Test Type", FontFactory.GetFont("Arial", 12, Font.BOLD, Color.BLACK)));
            cell      = new PdfPCell(phrase);
            paragraph = new Paragraph();
            paragraph.Add(phrase);
            paragraph.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(paragraph);
            cell.PaddingBottom = 20;
            table.AddCell(cell);

            for (int i = 0; i < medicalTestList.Count; i++)
            {
                phrase = new Phrase();
                phrase.Add(new Chunk((i + 1).ToString(), FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
                cell      = new PdfPCell(phrase);
                paragraph = new Paragraph();
                paragraph.Add(phrase);
                paragraph.Alignment = Element.ALIGN_CENTER;
                cell.AddElement(paragraph);
                table.AddCell(cell);

                phrase = new Phrase();
                phrase.Add(new Chunk(medicalTestList.ElementAt(i), FontFactory.GetFont("Arial", 11, Font.NORMAL, Color.BLACK)));
                cell      = new PdfPCell(phrase);
                paragraph = new Paragraph();
                paragraph.Add(phrase);
                paragraph.Alignment = Element.ALIGN_CENTER;
                cell.AddElement(paragraph);
                cell.PaddingBottom = 10;
                table.AddCell(cell);
            }

            table.HorizontalAlignment = Element.ALIGN_CENTER;

            document.Add(table);

            DrawLine(writer, 25f, document.Top - 750f, document.PageSize.Width - 25f, document.Top - 750f, color);
            DrawLine(writer, 25f, document.Top - 750f, document.PageSize.Width - 25f, document.Top - 750f, color);

            document.Close();
            byte[] bytes = memoryStream.ToArray();
            using (FileStream fs = File.Create(System.Web.HttpContext.Current.Server.MapPath("../Invoice/OPDMedicalTestRegistration/" + invoiceId + ".pdf")))
            {
                fs.Write(bytes, 0, (int)bytes.Length);
            }
            memoryStream.Close();
            return(bytes);
        }
    }
Ejemplo n.º 12
0
    private static void AddProductsToBro(String imgMDirectory, PdfPTable tblbro, Product p, int isNewPage)
    {
        tblbro.HorizontalAlignment = 0;
        tblbro.TotalWidth          = 838f;
        //tblPro.WidthPercentage = 100;
        tblbro.LockedWidth = true;
        float[] tblwidths = new float[] { 280f, 284f, 274f };
        tblbro.SetWidths(tblwidths);

        Regex regex = new Regex(@"(<br />|<br/>|</ br>|</br>|<p>|</p>|<h1>|<h2>|<h3>|<h3>|</h1>|</h2>|</h3>|</h3>|<div>|</div>|<strong>|</strong>)");

        // Replace new line with <br/> tag
        var prodDesc = p.ProductName.ToUpper() + "<br/>" + p.Description;

        prodDesc = regex.Replace(prodDesc, "\r\n");

        p.Size    = regex.Replace(p.Size, "\r\n");
        p.Colours = regex.Replace(p.Colours, "\r\n");

        // 1st column Product
        iTextSharp.text.Image mainImg;
        try { mainImg = iTextSharp.text.Image.GetInstance(imgMDirectory + p.MainImage); }
        catch { mainImg = iTextSharp.text.Image.GetInstance(imgMDirectory + "errorImage.png"); }

        mainImg.ScaleToFit(250f, 230f);

        PdfPCell cellProductImage = new PdfPCell();

        cellProductImage.AddElement(mainImg);
        cellProductImage.PaddingLeft = 10f;
        cellProductImage.PaddingTop  = 10f;
        if (isNewPage == 2)
        {
            cellProductImage.BorderColorTop    = BaseColor.GRAY;
            cellProductImage.BorderWidthBottom = 0f;
            cellProductImage.BorderWidthLeft   = 0f;
            cellProductImage.BorderWidthTop    = 3f;
            cellProductImage.BorderWidthRight  = 0f;
        }
        else
        {
            cellProductImage.Border = iTextSharp.text.Rectangle.NO_BORDER;
        }

        tblbro.AddCell(cellProductImage);
        //End 1st column product


        //DESCRIPTION
        PdfPCell cellDescription = new PdfPCell();

        cellDescription.BackgroundColor   = new BaseColor(247, 247, 247);
        cellDescription.VerticalAlignment = Element.ALIGN_TOP;
        if (isNewPage == 2)
        {
            cellDescription.BorderColorTop    = BaseColor.GRAY;
            cellDescription.BorderWidthBottom = 0f;
            cellDescription.BorderWidthLeft   = 0f;
            cellDescription.BorderWidthTop    = 3f;
            cellDescription.BorderWidthRight  = 0f;
        }
        else
        {
            cellDescription.Border = iTextSharp.text.Rectangle.NO_BORDER;
        }
        Phrase phDesc = new Phrase();

        phDesc.Add(new Phrase(prodDesc, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
        cellDescription.AddElement(phDesc);
        cellDescription.FixedHeight = 270f;
        tblbro.AddCell(cellDescription);
        //End DESCRIPTION


        cellDescription = new PdfPCell();
        cellDescription.VerticalAlignment = Element.ALIGN_TOP;
        phDesc = new Phrase();

        if (p.ProductId == 21 || p.ProductId == 23)
        {
            cellDescription.PaddingTop = 10f;
            String imgKidsSize = HttpContext.Current.Server.MapPath("~") + @"\images\ProductImages\childsizes.jpg";
            var    sizeImg     = iTextSharp.text.Image.GetInstance(imgKidsSize);

            cellDescription.AddElement(sizeImg);

            phDesc.Add(new Phrase(p.Colours, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
            cellDescription.AddElement(phDesc);
            //dCell1.PaddingLeft = 20f;
        }
        else
        {
            if (p.ProductFixedSizes != null && p.ProductFixedSizes != "")
            {
                string[] prodFixedSizes = p.ProductFixedSizes.Split(',');

                Paragraph pr = new Paragraph();
                cellDescription.PaddingTop = 20f;

                foreach (string prodFixedSize in prodFixedSizes)
                {
                    if (prodFixedSize.Length > 0)
                    {
                        String imgS       = HttpContext.Current.Server.MapPath("~") + @"\images\Assets\" + prodFixedSize + ".png";
                        var    sizeFxdImg = iTextSharp.text.Image.GetInstance(imgS);
                        sizeFxdImg.ScaleToFit(30, 30);
                        sizeFxdImg.Alignment = iTextSharp.text.Image.ALIGN_LEFT;

                        pr.Add(new Chunk(sizeFxdImg, 0, 0));
                    }
                }
                cellDescription.AddElement(pr);
                phDesc.Add(new Phrase(p.Colours, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                cellDescription.AddElement(phDesc);
            }
            else
            {
                phDesc.Add(new Phrase(p.Size + p.Colours, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                cellDescription.AddElement(phDesc);
            }
        }



        //topMidSpacer.FixedHeight = 340f;
        if (isNewPage == 2)
        {
            cellDescription.BorderColorTop    = BaseColor.GRAY;
            cellDescription.BorderWidthBottom = 0f;
            cellDescription.BorderWidthLeft   = 0f;
            cellDescription.BorderWidthTop    = 3f;
            cellDescription.BorderWidthRight  = 0f;
        }
        else
        {
            cellDescription.Border = iTextSharp.text.Rectangle.NO_BORDER;
        }

        tblbro.AddCell(cellDescription);
    }
Ejemplo n.º 13
0
    public void CreatePDF_OLDStyle()
    {
        String pdfDirectory  = HttpContext.Current.Server.MapPath("~") + @"\Resources\";
        String imgDirectory  = HttpContext.Current.Server.MapPath("~") + @"\images\";
        String imgMDirectory = HttpContext.Current.Server.MapPath("~") + @"\images\ProductImages\";
        String imgSize       = HttpContext.Current.Server.MapPath("~") + @"\images\ProductImages\childsizes.jpg";

        using (FileStream fs = new FileStream(pdfDirectory + "RKBrochure.pdf", FileMode.Create))
        {
            Document doc = new Document(PageSize.A4, 2f, 2f, 2f, 2f);
            doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

            PdfWriter.GetInstance(doc, fs);
            doc.Open();

            Paragraph paragraphTable1 = new Paragraph();
            paragraphTable1.SpacingAfter = 15f;

            PdfPTable table = new PdfPTable(3);
            table.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;

            PdfPCell cell = new PdfPCell(new Phrase(""));
            cell.Colspan             = 3;
            cell.FixedHeight         = 200f;
            cell.HorizontalAlignment = 2;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
            table.AddCell(cell);



            table.AddCell(" ");

            // add a image
            iTextSharp.text.Image Logo = iTextSharp.text.Image.GetInstance(imgDirectory + "hunter_small.gif");
            Logo.ScaleAbsolute(120f, 155.25f);
            table.AddCell(Logo);
            table.AddCell(" ");


            table.AddCell(" ");


            PdfPCell cell1 = new PdfPCell(new Phrase("Hunter-Outdoor"));
            cell1.HorizontalAlignment = Element.ALIGN_CENTER;
            cell1.Border = iTextSharp.text.Rectangle.NO_BORDER;
            table.AddCell(cell1);
            //table.AddCell("Hunter-Outdoor");
            table.AddCell(" ");


            table.AddCell(" ");

            PdfPCell cell2 = new PdfPCell(new Phrase("BROCHURE " + DateTime.Now.ToShortDateString()));
            cell2.HorizontalAlignment = Element.ALIGN_CENTER;
            cell2.Border = iTextSharp.text.Rectangle.NO_BORDER;
            table.AddCell(cell2);
            //table.AddCell("BROCHURE " + DateTime.Now.ToShortDateString());
            table.AddCell(" ");
            //bro.Append("<div class=\"blockPad\"><h2>Hunter-Outdoor</h2><p>BROCHURE " + DateTime.Now.ToShortDateString() + "</p>");


            paragraphTable1.Add(table);
            doc.Add(table);

            doc.NewPage();


            //Products page builder
            Products prods = new Products();
            prods.GetProducts(null);

            int    isNewPage = 0;
            int    pageNo    = 0;
            string prodName  = string.Empty;
            string prodDesc  = string.Empty;
            string prodImg   = string.Empty;
            string prodName2 = string.Empty;
            string prodDesc2 = string.Empty;
            string prodImg2  = string.Empty;
            string errorImg  = "errorImage.png";
            int    prodid1   = 0;
            int    prodid2   = 0;
            string prodSize1 = string.Empty;
            string prodSize2 = string.Empty;
            foreach (Product p in prods)
            {
                isNewPage++;

                if (isNewPage == 1)
                {
                    prodid1   = p.ProductId;
                    prodName  = p.ProductName;
                    prodDesc  = p.Description + "<br/>" + p.Colours;
                    prodImg   = p.MainImage;
                    prodSize1 = p.Size;

                    System.Text.RegularExpressions.Regex regex  = new System.Text.RegularExpressions.Regex(@"(<br />|<br/>|</ br>|</br>)");
                    System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@"(<p>|</p>|<h1>|<h2>|<h3>|<h3>|</h1>|</h2>|</h3>|</h3>|<div>|</div>)");

                    // Replace new line with <br/> tag
                    prodDesc = regex.Replace(prodDesc, "\r\n");
                    prodDesc = regex2.Replace(prodDesc, "\r\n");
                }
                else if (isNewPage == 2)
                {
                    pageNo++;

                    prodid1   = p.ProductId;
                    prodName2 = p.ProductName;
                    prodDesc2 = p.Description + "<br/>" + p.Colours;
                    prodImg2  = p.MainImage;
                    prodSize2 = p.Size;

                    System.Text.RegularExpressions.Regex regex  = new System.Text.RegularExpressions.Regex(@"(<br />|<br/>|</ br>|</br>)");
                    System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@"(<p>|</p>|<h1>|<h2>|<h3>|<h3>|</h1>|</h2>|</h3>|</h3>|<div>|</div>)");

                    // Replace new line with <br/> tag
                    prodDesc2 = regex.Replace(prodDesc2, "\r\n");
                    prodDesc2 = regex2.Replace(prodDesc2, "\r\n");
                }

                if (isNewPage == 2)
                {
                    PdfPTable tblPro = new PdfPTable(3);

                    tblPro.HorizontalAlignment = 0;
                    tblPro.TotalWidth          = 830f;
                    //tblPro.WidthPercentage = 100;
                    tblPro.LockedWidth = true;
                    float[] widths = new float[] { 410f, 10f, 410f };
                    tblPro.SetWidths(widths);

                    //Logo for header
                    Logo.ScaleAbsolute(100f, 75f);
                    PdfPCell headerCell = new PdfPCell(Logo);
                    headerCell.FixedHeight     = 50f;
                    headerCell.Colspan         = 2;
                    headerCell.Border          = iTextSharp.text.Rectangle.NO_BORDER;
                    headerCell.BackgroundColor = BaseColor.BLACK;
                    tblPro.AddCell(headerCell);


                    var FontColour = new BaseColor(31, 73, 125);
                    var MyFont     = FontFactory.GetFont("Times New Roman", 11, FontColour);

                    var pageHeaderCell = new PdfPCell(new Phrase("Page " + pageNo, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 9f, iTextSharp.text.Font.NORMAL, BaseColor.WHITE)));
                    pageHeaderCell.VerticalAlignment   = Element.ALIGN_BOTTOM;
                    pageHeaderCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    pageHeaderCell.BackgroundColor     = BaseColor.BLACK;
                    pageHeaderCell.PaddingBottom       = 10f;
                    pageHeaderCell.PaddingRight        = 10f;
                    pageHeaderCell.Border = iTextSharp.text.Rectangle.NO_BORDER;

                    tblPro.AddCell(pageHeaderCell);
                    //End Header



                    // 1st column Product
                    iTextSharp.text.Image mainImg;
                    try { mainImg = iTextSharp.text.Image.GetInstance(imgMDirectory + prodImg); }
                    catch { mainImg = iTextSharp.text.Image.GetInstance(imgMDirectory + errorImg); }

                    mainImg.ScaleToFit(250f, 290f);

                    PdfPCell imgCell1 = new PdfPCell();
                    imgCell1.Border = iTextSharp.text.Rectangle.NO_BORDER;

                    Phrase phProdName = new Phrase();
                    phProdName.Add(new Phrase(prodName));
                    imgCell1.AddElement(phProdName);
                    imgCell1.AddElement(mainImg);
                    imgCell1.PaddingLeft = 20f;
                    imgCell1.PaddingTop  = 10f;
                    tblPro.AddCell(imgCell1);
                    //End 1st column product


                    //Middle spacer
                    PdfPCell topMidSpacer = new PdfPCell(new Phrase(" "));
                    topMidSpacer.FixedHeight = 340f;
                    topMidSpacer.Border      = iTextSharp.text.Rectangle.NO_BORDER;
                    tblPro.AddCell(topMidSpacer);
                    //End middle spacer


                    // 1st column Product
                    iTextSharp.text.Image mainImg2;
                    try { mainImg2 = iTextSharp.text.Image.GetInstance(imgMDirectory + prodImg2); }
                    catch { mainImg2 = iTextSharp.text.Image.GetInstance(imgMDirectory + errorImg); }

                    mainImg2.ScaleToFit(250f, 290f);

                    PdfPCell imgCell2 = new PdfPCell();
                    imgCell2.Border = iTextSharp.text.Rectangle.NO_BORDER;

                    Phrase phProdName2 = new Phrase();
                    phProdName2.Add(new Phrase(prodName2));
                    imgCell2.AddElement(phProdName2);
                    imgCell2.AddElement(mainImg2);
                    imgCell2.PaddingLeft = 20f;
                    imgCell2.PaddingTop  = 10f;
                    tblPro.AddCell(imgCell2);
                    //End 1st column product


                    //1st prod description

                    /*PdfPCell cellProdDesc1 = new PdfPCell(new Phrase(prodDesc, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                     * cellProdDesc1.BorderColor = BaseColor.LIGHT_GRAY;
                     * cellProdDesc1.PaddingLeft = 5f;
                     * cellProdDesc1.PaddingTop = 10f;
                     * tblPro.AddCell(cellProdDesc1);*/


                    PdfPCell dCell1 = new PdfPCell();
                    dCell1.BorderColor = BaseColor.LIGHT_GRAY;

                    Phrase phD1 = new Phrase();
                    phD1.Add(new Phrase(prodDesc, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                    dCell1.AddElement(phD1);

                    if (prodid1 == 21 || prodid1 == 23)
                    {
                        var sizeImg = iTextSharp.text.Image.GetInstance(imgSize);

                        dCell1.AddElement(sizeImg);
                        //dCell1.PaddingLeft = 20f;
                        //dCell1.PaddingTop = 10f;
                    }
                    else
                    {
                        Phrase phProdd1 = new Phrase();
                        phProdd1.Add(new Phrase(prodSize1));
                        dCell1.AddElement(phProdd1);
                    }
                    tblPro.AddCell(dCell1);

                    //End 1st prod description

                    PdfPCell bottomSpacer = new PdfPCell(new Phrase(" "));
                    bottomSpacer.FixedHeight = 190f;
                    bottomSpacer.Border      = Rectangle.NO_BORDER;
                    tblPro.AddCell(bottomSpacer);

                    //2nd prod description

                    /*PdfPCell cellProdDesc2 = new PdfPCell(new Phrase(prodDesc2, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                     * cellProdDesc2.BorderColor = BaseColor.LIGHT_GRAY;
                     * cellProdDesc2.PaddingLeft = 5f;
                     * cellProdDesc2.PaddingTop = 10f;
                     * tblPro.AddCell(cellProdDesc2);*/


                    PdfPCell dCell2 = new PdfPCell();
                    dCell2.BorderColor = BaseColor.LIGHT_GRAY;

                    Phrase phD2 = new Phrase();
                    phD2.Add(new Phrase(prodDesc2, new Font(Font.FontFamily.HELVETICA, 9f, Font.NORMAL, BaseColor.BLACK)));
                    dCell2.AddElement(phD2);

                    if (prodid2 == 21 || prodid2 == 23)
                    {
                        var sizeImg = iTextSharp.text.Image.GetInstance(imgSize);

                        dCell2.AddElement(sizeImg);
                        //dCell1.PaddingLeft = 20f;
                        //dCell1.PaddingTop = 10f;
                    }
                    else
                    {
                        Phrase phProdd2 = new Phrase();
                        phProdd2.Add(new Phrase(prodSize2));
                        dCell2.AddElement(phProdd2);
                    }
                    tblPro.AddCell(dCell2);


                    //End 2nd prod description

                    Paragraph proPara = new Paragraph();
                    proPara.SpacingAfter = 15f;

                    proPara.Add(tblPro);
                    doc.Add(proPara);
                }

                //Create a new page after 2 products
                if (isNewPage == 2)
                {
                    isNewPage = 0;
                    doc.NewPage();
                }
            }


            doc.Close();
        }
    }
Ejemplo n.º 14
0
        private void WriteDetail(PdfPTable detailsTable, int tableColspan)
        {
            //WriteCell(detailsTable, "ICN:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            Phrase spacePhrase    = new Phrase(new Chunk(" ") + "", ReportFontBold);
            Phrase icnLinePhrase  = new Phrase("", ReportFont);
            Phrase icnLabelPhrase = new Phrase("ICN:", ReportFontBold);
            Phrase icnPhrase      = new Phrase(GetFormattedICNPhrase(ReportObject.InventoryChargeOffFields.ICN));

            icnLinePhrase.Add(icnLabelPhrase);
            icnLinePhrase.Add(spacePhrase);
            icnLinePhrase.Add(icnPhrase);

            PdfPCell cell = new PdfPCell();

            cell.Colspan = 2;
            cell.AddElement(icnLinePhrase);
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            cell.Border = Rectangle.NO_BORDER;
            detailsTable.AddCell(cell);

            WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, "Emp#:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.EmployeeNumber, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);

            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.MerchandiseDescription, ReportFont, 2, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, "Charge Off Amount:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.ChargeOffAmount, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);

            //new line
            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, "Reason for Charge Off:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.ReasonForChargeOff, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            if (string.IsNullOrEmpty(ReportObject.InventoryChargeOffFields.ReplacementLoanNumber))
            {
                WriteCell(detailsTable, string.Empty, ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            else
            {
                WriteCell(detailsTable, "Replacement Loan#:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.ReplacementLoanNumber, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }

            //new line
            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, "Comment:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.Comment, ReportFont, 2, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            if (string.IsNullOrEmpty(ReportObject.InventoryChargeOffFields.CustomerName))
            {
                WriteCell(detailsTable, string.Empty, ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            else
            {
                WriteCell(detailsTable, "Customer Name:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.CustomerName, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }

            //new line
            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, "Authorized By:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.AuthorizedBy, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);

            WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            if (string.IsNullOrEmpty(ReportObject.InventoryChargeOffFields.CharitableOrganization))
            {
                WriteCell(detailsTable, string.Empty, ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            else
            {
                WriteCell(detailsTable, "Charitable Organization:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.CharitableOrganization, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }

            //new line
            WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            if (!string.IsNullOrEmpty(ReportObject.InventoryChargeOffFields.PoliceCaseNumber))
            {
                WriteCell(detailsTable, "Police Case #:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.PoliceCaseNumber, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            else
            {
                WriteCell(detailsTable, string.Empty, ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            if (!string.IsNullOrEmpty(ReportObject.InventoryChargeOffFields.ATFIncidentNumber))
            {
                WriteCell(detailsTable, "ATF Incident #:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.ATFIncidentNumber, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            else
            {
                WriteCell(detailsTable, string.Empty, ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, string.Empty, ReportFont, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
            //add gun number here if it exists

            if (ReportObject.InventoryChargeOffFields.IsGun)
            {
                WriteCell(detailsTable, string.Empty, ReportFont, tableColspan, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, "Gun #:", ReportFontBold, 1, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
                WriteCell(detailsTable, ReportObject.InventoryChargeOffFields.GunNumber.ToString(), ReportFont, 4, Element.ALIGN_LEFT, Element.ALIGN_TOP, Rectangle.NO_BORDER);
            }
        }
Ejemplo n.º 15
0
        public ActionResult Disbursement(Int32 DisbursementId)
        {
            var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d;

            MemoryStream memoryStream = new MemoryStream();
            Document     document     = new Document(PageSize.LETTER, 30f, 30f, 110f, 60f);

            PdfWriter pdfWriter = PdfWriter.GetInstance(document, memoryStream);

            pdfWriter.PageEvent = new DisbrusementHeaderFooter(currentUser.FirstOrDefault().Id, DisbursementId);

            document.Open();

            Font fontArial09       = FontFactory.GetFont("Arial", 9);
            Font fontArial09Bold   = FontFactory.GetFont("Arial", 9, Font.BOLD);
            Font fontArial09Italic = FontFactory.GetFont("Arial", 09, Font.ITALIC);
            Font fontArial10       = FontFactory.GetFont("Arial", 10);
            Font fontArial10Bold   = FontFactory.GetFont("Arial", 10, Font.BOLD);

            var disbursement = from d in db.TrnDisbursements where d.Id == DisbursementId && d.IsLocked == true select d;

            if (disbursement.Any())
            {
                var currentCVFooter = currentUser.FirstOrDefault().MstCompany.CVFooter;

                String payee          = disbursement.FirstOrDefault().Payee;
                String bank           = disbursement.FirstOrDefault().MstArticle1.Article;
                String particulars    = disbursement.FirstOrDefault().Particulars;
                String checkNo        = disbursement.FirstOrDefault().CheckNumber;
                String CVNumber       = disbursement.FirstOrDefault().CVNumber;
                String CVDate         = disbursement.FirstOrDefault().CVDate.ToShortDateString();
                String ManualCVNumber = disbursement.FirstOrDefault().ManualCVNumber;
                String checkDate      = disbursement.FirstOrDefault().CheckDate.ToShortDateString();
                String preparedBy     = disbursement.FirstOrDefault().MstUser3.FullName;
                String checkedBy      = disbursement.FirstOrDefault().MstUser1.FullName;
                String approvedBy     = disbursement.FirstOrDefault().MstUser.FullName;

                PdfPTable tableDisbursement = new PdfPTable(4);
                tableDisbursement.SetWidths(new float[] { 50f, 140f, 70f, 70f });
                tableDisbursement.WidthPercentage = 100;
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Payee:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(payee, fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("No.:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("CV-" + disbursement.FirstOrDefault().MstBranch.BranchCode + "-" + CVNumber, fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Check No.:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(checkNo, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Date:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(CVDate, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Check Date:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(checkDate, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("CV Ref. No.:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(ManualCVNumber, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Bank:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(bank, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("", fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2, Colspan = 2
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("Particulars:", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase(particulars, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableDisbursement.AddCell(new PdfPCell(new Phrase("", fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 2, Colspan = 2
                });
                document.Add(tableDisbursement);

                PdfPTable spaceTable = new PdfPTable(1);
                spaceTable.SetWidths(new float[] { 100f });
                spaceTable.WidthPercentage = 100;
                spaceTable.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 5f
                });
                document.Add(spaceTable);

                var journals = from d in disbursement.FirstOrDefault().TrnJournals where d.CVId != null select d;
                if (journals.Any())
                {
                    PdfPTable tableJournal = new PdfPTable(6);
                    tableJournal.SetWidths(new float[] { 120f, 90f, 130f, 150f, 100f, 100f });
                    tableJournal.WidthPercentage = 100;
                    tableJournal.AddCell(new PdfPCell(new Phrase("Branch", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Code", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Account", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Article", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Debit", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase("Credit", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });

                    Decimal totalDebitAmount  = 0;
                    Decimal totalCreditAmount = 0;

                    Decimal count = 0;

                    foreach (var journal in journals)
                    {
                        count += 1;

                        float paddingBottom = 3f;
                        if (count == journals.Count())
                        {
                            paddingBottom = 6f;
                        }

                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.MstBranch.Branch, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.MstAccount.AccountCode, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.MstAccount.Account, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.MstArticle.Article, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.DebitAmount.ToString("#,##0.00"), fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableJournal.AddCell(new PdfPCell(new Phrase(journal.CreditAmount.ToString("#,##0.00"), fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });

                        totalDebitAmount  += journal.DebitAmount;
                        totalCreditAmount += journal.CreditAmount;
                    }

                    tableJournal.AddCell(new PdfPCell(new Phrase("Total", fontArial10Bold))
                    {
                        Colspan = 4, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase(totalDebitAmount.ToString("#,##0.00"), fontArial10Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableJournal.AddCell(new PdfPCell(new Phrase(totalCreditAmount.ToString("#,##0.00"), fontArial10Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                    });

                    document.Add(tableJournal);
                    document.Add(spaceTable);
                }

                var disbursementLines = from d in disbursement.FirstOrDefault().TrnDisbursementLines select d;
                if (disbursementLines.Any())
                {
                    PdfPTable tableDisbursementLines       = new PdfPTable(4);
                    float[]   widthscellsDisbursementLines = new float[] { 120f, 80f, 140f, 100f };
                    tableDisbursementLines.SetWidths(widthscellsDisbursementLines);
                    tableDisbursementLines.WidthPercentage = 100;
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("RR No.", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("RR Date", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Particulars", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Paid Amount", fontArial10Bold))
                    {
                        HorizontalAlignment = 1, PaddingTop = 3f, PaddingBottom = 7f
                    });

                    Decimal totalPaidAmount = 0;
                    Decimal count           = 0;

                    foreach (var disbursementLine in disbursementLines)
                    {
                        count += 1;

                        float paddingBottom = 3f;
                        if (count == disbursementLines.Count())
                        {
                            paddingBottom = 6f;
                        }

                        String RRNumber = " ", RRDate = " ";
                        if (disbursementLine.RRId != null)
                        {
                            RRNumber = "RR-" + disbursementLine.TrnReceivingReceipt.MstBranch.BranchCode + "-" + disbursementLine.TrnReceivingReceipt.RRNumber;
                            RRDate   = disbursementLine.TrnReceivingReceipt.RRDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);
                        }

                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(RRNumber, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(RRDate, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(disbursementLine.Particulars, fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 0, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });
                        tableDisbursementLines.AddCell(new PdfPCell(new Phrase(disbursementLine.Amount.ToString("#,##0.00"), fontArial10))
                        {
                            Border = 0, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = paddingBottom, PaddingLeft = 5f, PaddingRight = 5f
                        });

                        totalPaidAmount += disbursementLine.Amount;
                    }

                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase("Total", fontArial10Bold))
                    {
                        Colspan = 3, HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                    });
                    tableDisbursementLines.AddCell(new PdfPCell(new Phrase(totalPaidAmount.ToString("#,##0.00"), fontArial10Bold))
                    {
                        HorizontalAlignment = 2, PaddingTop = 3f, PaddingBottom = 7f, PaddingLeft = 5f, PaddingRight = 5f
                    });

                    document.Add(tableDisbursementLines);
                    document.Add(spaceTable);
                }

                PdfPTable tableUserss = new PdfPTable(3);
                tableUserss.SetWidths(new float[] { 100f, 100f, 100f });
                tableUserss.WidthPercentage = 100;
                tableUserss.AddCell(new PdfPCell(new Phrase("Prepared by", fontArial10Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase("Checked by", fontArial10Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase("Approved by", fontArial10Bold))
                {
                    PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 30f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 30f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(" "))
                {
                    PaddingBottom = 30f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(preparedBy, fontArial10))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(checkedBy, fontArial10))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableUserss.AddCell(new PdfPCell(new Phrase(approvedBy, fontArial10))
                {
                    HorizontalAlignment = 1, PaddingTop = 5f, PaddingBottom = 9f, PaddingLeft = 5f, PaddingRight = 5f
                });
                document.Add(tableUserss);

                document.Add(spaceTable);

                PdfPTable tableMoneyWord = new PdfPTable(3);
                tableMoneyWord.SetWidths(new float[] { 40f, 100f, 140f });
                tableMoneyWord.WidthPercentage = 100;
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Check No.", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(checkNo, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });

                String paidAmount = Convert.ToString(Math.Round(disbursement.FirstOrDefault().Amount * 100) / 100);

                var amountTablePhrase = new Phrase();
                var amountString      = "ZERO";

                if (Convert.ToDecimal(paidAmount) != 0)
                {
                    amountString = GetMoneyWord(paidAmount).ToUpper();
                }

                amountTablePhrase.Add(new Chunk("Representing Payment from " + currentUser.FirstOrDefault().MstCompany.Company + " the amount of ", fontArial10));
                amountTablePhrase.Add(new Chunk(amountString + " (P " + disbursement.FirstOrDefault().Amount.ToString("#,##0.00") + ")", fontArial10Bold));

                Paragraph paragraphAmountTable = new Paragraph();
                paragraphAmountTable.SetLeading(0, 1.4f);
                paragraphAmountTable.Add(amountTablePhrase);

                PdfPCell chunkyAmountTable = new PdfPCell();
                chunkyAmountTable.AddElement(paragraphAmountTable);
                chunkyAmountTable.BorderWidth = PdfPCell.NO_BORDER;

                tableMoneyWord.AddCell(new PdfPCell(chunkyAmountTable)
                {
                    Rowspan = 4, Border = 0, PaddingTop = 0f, PaddingLeft = 5f, PaddingRight = 5f, HorizontalAlignment = 0
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Check Date", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(checkDate, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Bank", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(bank, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase("Manual No.", fontArial10Bold))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                tableMoneyWord.AddCell(new PdfPCell(new Phrase(ManualCVNumber, fontArial10))
                {
                    Border = 0, PaddingTop = 3f, PaddingLeft = 5f, PaddingRight = 5f
                });
                document.Add(tableMoneyWord);

                document.Add(spaceTable);
                document.Add(spaceTable);

                PdfPTable tableUserSign = new PdfPTable(4);
                tableUserSign.SetWidths(new float[] { 115f, 60f, 5f, 40f });
                tableUserSign.WidthPercentage = 100;
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10))
                {
                    Border = 0,
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase("Signature Over Printed Name", fontArial10Bold))
                {
                    Border = 1, HorizontalAlignment = 1
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase(" ", fontArial10Bold))
                {
                    Border = 0
                });
                tableUserSign.AddCell(new PdfPCell(new Phrase("Date", fontArial10Bold))
                {
                    Border = 1, HorizontalAlignment = 1
                });
                document.Add(tableUserSign);
                document.Add(spaceTable);

                PdfPTable tableFooter = new PdfPTable(1);
                tableFooter.SetWidths(new float[] { 100f });
                tableFooter.WidthPercentage = 100;
                tableFooter.AddCell(new PdfPCell(new Phrase(currentCVFooter, fontArial09Italic))
                {
                    Border = 0, PaddingTop = 5f, HorizontalAlignment = 1
                });
                document.Add(tableFooter);

                if (!disbursement.FirstOrDefault().IsPrinted)
                {
                    disbursement.FirstOrDefault().IsPrinted = true;
                    db.SubmitChanges();
                }
            }

            document.Close();

            byte[] bytesStream = memoryStream.ToArray();

            memoryStream = new MemoryStream();
            memoryStream.Write(bytesStream, 0, bytesStream.Length);
            memoryStream.Position = 0;

            return(new FileStreamResult(memoryStream, "application/pdf"));
        }
Ejemplo n.º 16
0
        public byte[] Generate()
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                Document  document = new Document(PageSize.A4, 25, 25, 30, 30);
                PdfWriter writer   = PdfWriter.GetInstance(document, memStream);
                document.Open();

                PdfPTable topSection = new PdfPTable(2);
                topSection.DefaultCell.Border = Rectangle.NO_BORDER;

                // Full Name
                var fullNamePhrase = new Phrase();
                topSection.DefaultCell.Border = Rectangle.NO_BORDER;
                fullNamePhrase.Add(new Chunk("Name: ", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16)));
                fullNamePhrase.Add(new Chunk(FullName, FontFactory.GetFont(FontFactory.HELVETICA, 16)));
                PdfPCell fullNameCell = new PdfPCell(fullNamePhrase);
                fullNameCell.Border = Rectangle.NO_BORDER;
                topSection.AddCell(fullNameCell);

                // Base Salary
                var annualSalaryPhrase = new Phrase();
                annualSalaryPhrase.Add(new Chunk("Base Salary: ", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16)));
                annualSalaryPhrase.Add(new Chunk("$" + AnnualSalary.ToString("f2"), FontFactory.GetFont(FontFactory.HELVETICA, 16)));
                PdfPCell baseSalaryCell = new PdfPCell(annualSalaryPhrase);
                baseSalaryCell.Border = Rectangle.NO_BORDER;
                topSection.AddCell(baseSalaryCell);

                document.Add(topSection);

                PdfPTable dependentSection = new PdfPTable(1);
                dependentSection.SpacingBefore      = 20f;
                dependentSection.DefaultCell.Border = Rectangle.NO_BORDER;
                PdfPCell headerLabel = new PdfPCell(new Phrase(new Chunk("Dependents", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16))));
                headerLabel.Border = Rectangle.NO_BORDER;
                dependentSection.AddCell(headerLabel);

                foreach (var dependent in Dependents.Where(x => !string.IsNullOrEmpty(x)))
                {
                    PdfPCell dependentCell = new PdfPCell(new Phrase(new Chunk("-" + dependent, FontFactory.GetFont(FontFactory.HELVETICA, 14))));
                    dependentCell.Border = Rectangle.NO_BORDER;
                    dependentSection.AddCell(dependentCell);
                }

                document.Add(dependentSection);

                PdfPTable bottomSection = new PdfPTable(1);
                bottomSection.SpacingBefore      = 40f;
                bottomSection.DefaultCell.Border = Rectangle.NO_BORDER;

                PdfPTable detailsTable = new PdfPTable(2);
                detailsTable.DefaultCell.Border = Rectangle.NO_BORDER;
                PdfPCell discountHeaderCell = new PdfPCell(new Phrase(new Chunk("Dependents", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14))));
                discountHeaderCell.Colspan = 2;
                detailsTable.AddCell(discountHeaderCell);

                foreach (var discount in Discounts)
                {
                    PdfPCell discountItemCell = new PdfPCell(new Phrase(new Chunk(discount, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))));
                    discountItemCell.Colspan = 2;
                    detailsTable.AddCell(discountItemCell);
                }

                detailsTable.AddCell(new PdfPCell(new Phrase(new Chunk("Total: ", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)))));
                detailsTable.AddCell(new PdfPCell(new Phrase(new Chunk(Total.ToString("f2"), FontFactory.GetFont(FontFactory.HELVETICA, 14)))));
                detailsTable.AddCell(new PdfPCell(new Phrase(new Chunk("Total Per Check: ", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)))));
                detailsTable.AddCell(new PdfPCell(new Phrase(new Chunk(TotalPerCheck.ToString("f2"), FontFactory.GetFont(FontFactory.HELVETICA, 14)))));
                bottomSection.AddCell(new PdfPCell(detailsTable));
                document.Add(bottomSection);

                PdfContentByte canvas   = writer.DirectContent;
                PieChart       pieChart = new PieChart(new double[] { Total, TotalEmployeeBenefitCost, TotalDependentsBenefitCost },
                                                       new[] { "Total After Benefits", "Employee Benefits", "Employee Dependent Benefits" });

                canvas.DrawPieChart(pieChart, 300, 300, 100);

                document.Close();
                return(memStream.ToArray());
            }
        }
Ejemplo n.º 17
0
        public static Phrase GetTokens(this Tree tree, Tree root = null, Rhetorica.Sentence sentence = null, string ignore = "", string punctuation = null, AnalyzerOptions options = AnalyzerOptions.None)
        {
            var tokens = new Phrase(sentence: sentence);
              java.util.List leaves = tree.getLeaves();

              for (java.util.Iterator i = leaves.iterator(); i.hasNext(); ) {
            Tree leaf = (Tree)i.next();
            string token = leaf.value().Trim();

            Tree preterminal = leaf.parent(tree);
            if (preterminal == null)
              continue;
            string tag = preterminal.value().Trim();

            bool ignoreMeansInclude = options.HasFlag(AnalyzerOptions.IgnoreMeansInclude);
            if (ignore != string.Empty) {
              bool isMatch = Regex.IsMatch(token, ignore);
              if (ignoreMeansInclude) {
            if (!isMatch) continue;
              }
              else {
            if (isMatch) continue;
              }
            }

            bool omitPunctuation = options.HasFlag(AnalyzerOptions.OmitPunctuationTokens);
            if (omitPunctuation) {
              // Leave out certain types of punctuation:
              bool isPunctuation = Regex.IsMatch(tag, punctuation ?? Analyzer.PunctuationPatterns)
            || Regex.IsMatch(token, punctuation ?? Analyzer.PunctuationPatterns);
              if (isPunctuation) {
            tokens.IsPunctuationOmitted = true;
            continue;
              }

              // But also remove any straggler punctuation missed within a token...? Maybe not. Use RegExp 'FloatingPunctuationPatterns' if so.
            }

            root = root ?? tree;
            int depth = root.depth() - root.depth(preterminal);

            var characterEdges = new CharacterEdges(root.leftCharEdge(leaf), root.rightCharEdge(leaf));
            tokens.Add(new Token(token, tag, depth, characterEdges));
              }

              return tokens;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Tilføj noget tekst hurtigt
        ///
        /// med text coder så man kan lave noget af teksten fed eller andet
        /// </summary>
        private PdfPCell InsertTextExpert(string text, int[] padding = null)
        {
            Font   fontNormal    = new Font(Font.FontFamily.HELVETICA, 12f);
            Font   fontBold      = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD);
            Font   fontUnderline = new Font(Font.FontFamily.HELVETICA, 12f, Font.UNDERLINE);
            Font   fontItalic    = new Font(Font.FontFamily.HELVETICA, 12f, Font.ITALIC);
            Phrase phraseText    = new Phrase();

            bool tagFound = false;

            string[] tagStart      = new string[] { "<b>", "<u>", "<i>", "<p>" };
            string[] tagEnd        = new string[] { "</b>", "</u>", "</i>", "</p>" };
            int      tagStartFound = -1;
            int      tagEndFound   = -1;
            string   textValue     = "";

            //<b>Test</b>Hallo
            //så der ikke sker fejl ved at bruge substring
            text += "0000";
            for (int i = 0; i < text.Length - 4; i++)
            {
                string startTag = text.Substring(i, 3);
                string endTag   = text.Substring(i, 4);

                //System.Windows.MessageBox.Show(text + "\n" +
                //    "StartTag: " + startTag + "\n" +
                //    "EndTag: "+endTag+"\n" +
                //"Tagfound: "+tagFound+"\n" +
                //"StartTag ID: "+tagStartFound+ "\n" +
                //"EndTag ID: " + tagEndFound + "\n");

                if (!tagFound && tagStart.Contains(startTag))
                {
                    i            += 2; //ungå at få tag med
                    tagStartFound = Array.IndexOf(tagStart, startTag);

                    if (textValue.Length > 0)
                    {
                        phraseText.Add(new Chunk(textValue, fontNormal));
                        textValue = "";
                    }

                    tagFound = true;
                }
                else if (tagFound && tagEnd.Contains(endTag))
                {
                    i          += 3; //ungå at få tag med
                    tagEndFound = Array.IndexOf(tagEnd, endTag);

                    //hvis det er det samme tag tillad at luk
                    if (tagStartFound == tagEndFound)
                    {
                        tagFound = false;


                        if (textValue.Length > 0)
                        {
                            Font tagFont = fontNormal;
                            switch (tagStartFound)
                            {
                            case 0:
                                tagFont = fontBold;
                                break;

                            case 1:
                                tagFont = fontUnderline;
                                break;

                            case 2:
                                tagFont = fontItalic;
                                break;

                            case 3:
                                tagFont = fontItalic;
                                break;
                            }
                            phraseText.Add(new Chunk(textValue, tagFont));
                            textValue = "";
                        }
                    }
                }
                else //tilføj tekst
                {
                    //System.Windows.MessageBox.Show(i.ToString() + " < " + (text.Length - 4).ToString() + "\n" + i.ToString() + " == " + (text.Length - 5).ToString());

                    textValue += text.Substring(i, 1);
                }
            }

            //Hvis der ikke blev fundet nogle tag
            if (textValue.Length != 0)
            {
                phraseText.Add(new Chunk(textValue, fontNormal));
            }


            PdfPCell textCell = new PdfPCell(phraseText);

            textCell.Border = 0;

            if (padding != null)
            {
                textCell.PaddingLeft   = padding[0];
                textCell.PaddingTop    = padding[1];
                textCell.PaddingRight  = padding[2];
                textCell.PaddingBottom = padding[3];
            }


            return(textCell);
        }
Ejemplo n.º 19
0
 /**
 * Process the text so that it will render with a combination of fonts
 * if needed.
 * @param text the text
 * @return a <CODE>Phrase</CODE> with one or more chunks
 */
 public virtual Phrase Process(String text) {
     if (fonts.Count == 0)
         throw new ArgumentOutOfRangeException(MessageLocalization.GetComposedMessage("no.font.is.defined"));
     char[] cc = text.ToCharArray();
     int len = cc.Length;
     StringBuilder sb = new StringBuilder();
     Phrase ret = new Phrase();
     currentFont = null;
     for (int k = 0; k < len; ++k) {
         Chunk newChunk = ProcessChar(cc, k, sb);
         if (newChunk != null) {
             ret.Add(newChunk);
         }
     }
     if (sb.Length > 0) {
         Chunk ck = new Chunk(sb.ToString(), currentFont ?? fonts[0]);
         ret.Add(ck);
     }
     return ret;
 }
Ejemplo n.º 20
0
        // ---------------------------------------------------------------------------

        /**
         * Creates a Phrase containing information about a movie.
         * @param    movie    the movie for which you want to create a Paragraph
         */
        public Phrase CreateMovieInformation(Movie movie)
        {
            Phrase p = new Phrase();

            p.Font = FilmFonts.NORMAL;
            p.Add(new Phrase("Title: ", FilmFonts.BOLDITALIC));
            p.Add(PojoToElementFactory.GetMovieTitlePhrase(movie));
            p.Add(" ");
            if (!string.IsNullOrEmpty(movie.OriginalTitle))
            {
                p.Add(new Phrase("Original title: ", FilmFonts.BOLDITALIC));
                p.Add(PojoToElementFactory.GetOriginalTitlePhrase(movie));
                p.Add(" ");
            }
            p.Add(new Phrase("Country: ", FilmFonts.BOLDITALIC));
            foreach (Country country in movie.Countries)
            {
                p.Add(PojoToElementFactory.GetCountryPhrase(country));
                p.Add(" ");
            }
            p.Add(new Phrase("Director: ", FilmFonts.BOLDITALIC));
            foreach (Director director in movie.Directors)
            {
                p.Add(PojoToElementFactory.GetDirectorPhrase(director));
                p.Add(" ");
            }
            p.Add(new Chunk("Year: ", FilmFonts.BOLDITALIC));
            p.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
            p.Add(new Chunk(" Duration: ", FilmFonts.BOLDITALIC));
            p.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
            p.Add(new Chunk(" minutes", FilmFonts.NORMAL));
            p.Add(new LineSeparator(0.3f, 100, null, Element.ALIGN_CENTER, -2));
            return(p);
        }
Ejemplo n.º 21
0
        private void generate_Click(object sender, EventArgs e)
        {
            int cena      = Int32.Parse(cena_txt.Text);
            int zadatek   = Int32.Parse(zadatek_txt.Text);
            int pozostala = cena - zadatek;

            var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var fullFileName  = Path.Combine(desktopFolder, "umowa.pdf");

            FileStream fs = new FileStream(fullFileName, FileMode.Create, FileAccess.Write, FileShare.None);

            iTextSharp.text.Font timesBoldItalic = FontFactory.GetFont(FontFactory.TIMES_BOLDITALIC, BaseFont.CP1250, 11);
            iTextSharp.text.Font timesBold       = FontFactory.GetFont(FontFactory.TIMES_BOLD, BaseFont.CP1250, 11);
            iTextSharp.text.Font times           = FontFactory.GetFont(FontFactory.TIMES, BaseFont.CP1250, 11);
            Document             doc             = new Document(PageSize.A4, 40, 40, 20, 40);
            PdfWriter            writer          = PdfWriter.GetInstance(doc, fs);

            iTextSharp.text.Image flisy_1 = iTextSharp.text.Image.GetInstance("flisy_01.png");
            doc.Open();
            doc.SetMargins(40f, 40f, 40f, 40f);
            doc.AddTitle("Umowa Flisy");
            doc.AddAuthor("Flisy");
            // first image
            flisy_1.ScaleToFit(600f, 70f);
            flisy_1.Alignment = Element.ALIGN_CENTER;
            doc.Add(flisy_1);

            Paragraph title = new Paragraph("UMOWA O DZIEŁO", timesBoldItalic);

            title.Alignment = Element.ALIGN_CENTER;
            doc.Add(title);
            // &0
            var zero_ph = new Phrase();

            zero_ph.Add(new Chunk("Zawarta w dniu ", times));
            zero_ph.Add(new Chunk(data_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" pomiędzy zespołem muzycznym FLISY reprezentowanym przez Arkadiusza Olka zamieszkałym w Gorzowie Wlkp.ul.Wiedeńska 1i / 15 zwanym w treści umowy wykonawcą, a organizatorem imprezy czyli ", times));
            zero_ph.Add(new Chunk(zlece_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" zamieszkałym ", times));
            zero_ph.Add(new Chunk(adr_zlece_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" zwanym w treści umowy zamawiającym.", times));

            Paragraph zero = new Paragraph(zero_ph);

            zero.Alignment = Element.ALIGN_JUSTIFIED;
            zero.SetLeading(0.0f, 1.5f);
            doc.Add(zero);

            // &1
            Paragraph one_amp = new Paragraph("&1", timesBold);

            one_amp.Alignment = Element.ALIGN_CENTER;
            one_amp.SetLeading(0.0f, 1.5f);
            doc.Add(one_amp);

            var one_ph = new Phrase();

            one_ph.Add(new Chunk("Zamawiający zamawia wykonanie a wykonawca zobowiązuje się wykonać dzieło polegające na: \na) oprawie muzyczno - wokalnej uroczystości weselnej \nb) oprawie muzyczno-wokalnej uroczystości weselnej wraz z poprawinami \nc) oprawie muzyczno-wokalnej imprezy", times));

            Paragraph one = new Paragraph(one_ph);

            one.Alignment = Element.ALIGN_JUSTIFIED;
            one.SetLeading(0.0f, 1.5f);
            doc.Add(one);

            // &2
            Paragraph two_amp = new Paragraph("&2", timesBold);

            two_amp.Alignment = Element.ALIGN_CENTER;
            two_amp.SetLeading(0.0f, 1.5f);
            doc.Add(two_amp);

            var two_ph = new Phrase();

            two_ph.Add(new Chunk("W terminie dnia ", times));
            two_ph.Add(new Chunk(termin_txt.Text, timesBold));
            two_ph.Add(new Chunk(" od godz. 16:00 do godz. 4:00 w miejscu ", times));
            two_ph.Add(new Chunk(miejsce_txt.Text, timesBold));
            two_ph.Add(new Chunk(".", times));

            Paragraph two = new Paragraph(two_ph);

            two.Alignment = Element.ALIGN_JUSTIFIED;
            two.SetLeading(0.0f, 1.5f);
            doc.Add(two);

            // &3
            Paragraph three_amp = new Paragraph("&3", timesBold);

            three_amp.Alignment = Element.ALIGN_CENTER;
            three_amp.SetLeading(0.0f, 1.5f);
            doc.Add(three_amp);

            var three_ph = new Phrase();

            three_ph.Add(new Chunk("Za wykonanie dzieła zamawiający wypłaci wykonawcy wynagrodzenie w wysokości ", times));
            three_ph.Add(new Chunk(cena_txt.Text + ",00", timesBold));
            three_ph.Add(new Chunk(" słownie ", times));
            three_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(cena), Formatowanie.WalutaSlownie(cena, "PLN")), timesBold));
            three_ph.Add(new Chunk(".", times));

            Paragraph three = new Paragraph(three_ph);

            three.Alignment = Element.ALIGN_JUSTIFIED;
            three.SetLeading(0.0f, 1.5f);
            doc.Add(three);

            // &4
            Paragraph four_amp = new Paragraph("&4", timesBold);

            four_amp.Alignment = Element.ALIGN_CENTER;
            four_amp.SetLeading(0.0f, 1.5f);
            doc.Add(four_amp);

            var four_ph = new Phrase();

            four_ph.Add(new Chunk("Zadatek w kwocie ", times));
            four_ph.Add(new Chunk(zadatek_txt.Text + ",00", timesBold));
            four_ph.Add(new Chunk(" słownie ", times));
            four_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(zadatek), Formatowanie.WalutaSlownie(zadatek, "PLN")), timesBold));
            four_ph.Add(new Chunk(" pobrano w dniu sporządzenia umowy. Do uregulowania pozostaje kwota ", times));
            four_ph.Add(new Chunk(pozostala.ToString() + ",00", timesBold));
            four_ph.Add(new Chunk(" słownie ", times));
            four_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(pozostala), Formatowanie.WalutaSlownie(pozostala, "PLN")), timesBold));
            four_ph.Add(new Chunk(" która wypłacona będzie bezpośrednio po zakończeniu imprezy.", times));

            Paragraph four = new Paragraph(four_ph);

            four.Alignment = Element.ALIGN_JUSTIFIED;
            four.SetLeading(0.0f, 1.5f);
            doc.Add(four);

            // &5
            Paragraph five_amp = new Paragraph("&5", timesBold);

            five_amp.Alignment = Element.ALIGN_CENTER;
            five_amp.SetLeading(0.0f, 1.5f);
            doc.Add(five_amp);

            var five_ph = new Phrase();

            five_ph.Add(new Chunk("Wykonawca nie może powierzyć dzieła innym osobom bez zgody zamawiającego. ", times));

            Paragraph five = new Paragraph(five_ph);

            five.Alignment = Element.ALIGN_JUSTIFIED;
            five.SetLeading(0.0f, 1.5f);
            doc.Add(five);

            // &6
            Paragraph six_amp = new Paragraph("&6", timesBold);

            six_amp.Alignment = Element.ALIGN_CENTER;
            six_amp.SetLeading(0.0f, 1.5f);
            doc.Add(six_amp);

            var six_ph = new Phrase();

            six_ph.Add(new Chunk("Zamawiający jest jednocześnie organizatorem imprezy. ", times));

            Paragraph six = new Paragraph(six_ph);

            six.Alignment = Element.ALIGN_JUSTIFIED;
            six.SetLeading(0.0f, 1.5f);
            doc.Add(six);

            // &7
            Paragraph seven_amp = new Paragraph("&7", timesBold);

            seven_amp.Alignment = Element.ALIGN_CENTER;
            seven_amp.SetLeading(0.0f, 1.5f);
            doc.Add(seven_amp);

            var seven_ph = new Phrase();

            seven_ph.Add(new Chunk("Zamawiający ponosi odpowiedzialność materialną za zniszczenie lub uszkodzenie sprzętu powstałe z winy osób nie będących członkami zespołu.", times));

            Paragraph seven = new Paragraph(seven_ph);

            seven.Alignment = Element.ALIGN_JUSTIFIED;
            seven.SetLeading(0.0f, 1.5f);
            doc.Add(seven);

            // &8
            Paragraph eight_amp = new Paragraph("&8", timesBold);

            eight_amp.Alignment = Element.ALIGN_CENTER;
            eight_amp.SetLeading(0.0f, 1.5f);
            doc.Add(eight_amp);

            var eight_ph = new Phrase();

            eight_ph.Add(new Chunk("W przypadku rozwiązania umowy przez zamawiającego, zadatek przechodzi na rzecz wykonawcy. ", times));

            Paragraph eight = new Paragraph(eight_ph);

            eight.Alignment = Element.ALIGN_JUSTIFIED;
            eight.SetLeading(0.0f, 1.5f);
            doc.Add(eight);

            // &9
            Paragraph nine_amp = new Paragraph("&9", timesBold);

            nine_amp.Alignment = Element.ALIGN_CENTER;
            nine_amp.SetLeading(0.0f, 1.5f);
            doc.Add(nine_amp);

            var nine_ph = new Phrase();

            nine_ph.Add(new Chunk("W przypadku rozwiązania umowy przez wykonawcę, zadatek w podwójnej wysokości przechodzi na rzecz zamawiającego.", times));

            Paragraph nine = new Paragraph(nine_ph);

            nine.Alignment = Element.ALIGN_JUSTIFIED;
            nine.SetLeading(0.0f, 1.5f);
            doc.Add(nine);

            // &10
            Paragraph ten_amp = new Paragraph("&10", timesBold);

            ten_amp.Alignment = Element.ALIGN_CENTER;
            ten_amp.SetLeading(0.0f, 1.5f);
            doc.Add(ten_amp);

            var ten_ph = new Phrase();

            ten_ph.Add(new Chunk("W sprawach nie uregulowanych niniejszą umową mają zastosowanie przepisy kodeksu cywilnego.", times));

            Paragraph ten = new Paragraph(ten_ph);

            ten.Alignment = Element.ALIGN_JUSTIFIED;
            ten.SetLeading(0.0f, 1.5f);
            doc.Add(ten);

            // &11
            Paragraph eleven_amp = new Paragraph("&11", timesBold);

            eleven_amp.Alignment = Element.ALIGN_CENTER;
            eleven_amp.SetLeading(0.0f, 1.5f);
            doc.Add(eleven_amp);

            var eleven_ph = new Phrase();

            eleven_ph.Add(new Chunk("Umowę sporządzono w dwóch jednobrzmiących egzemplarzach, po jednym dla każdej ze stron.", times));

            Paragraph eleven = new Paragraph(eleven_ph);

            eleven.Alignment = Element.ALIGN_JUSTIFIED;
            eleven.SetLeading(0.0f, 1.5f);
            doc.Add(eleven);

            // signatures
            var signatures_ph = new Phrase();

            signatures_ph.Add(new Chunk("\n\n             (zamawiający)                                                                                               (wykonawca)    ", times));

            Paragraph signatures = new Paragraph(signatures_ph);

            signatures.Alignment = Element.ALIGN_JUSTIFIED;
            doc.Add(signatures);

            doc.Close();
            System.Windows.Forms.MessageBox.Show("Umowa została wygenerowana.");
        }
Ejemplo n.º 22
0
        public int create()
        {
            doc = new Document(iTextSharp.text.PageSize.A4, 1, 0, 50, 35);
            PdfWriter writer;

            try {
                // writer = PdfWriter.GetInstance(doc, new FileStream(bill_nr + ".pdf", FileMode.Create));
                writer = PdfWriter.GetInstance(doc, new FileStream("Abrechnung.pdf", FileMode.Create));
            } catch (IOException) {
                return(-1);
            }
            doc.Open();

            float Margin_Left   = doc.LeftMargin;
            float Magrin_Right  = doc.RightMargin;
            float Margin_Bottom = doc.BottomMargin;
            float Margin_Top    = doc.TopMargin;

            Paragraph paragraph;


            //Import header-image
            var   logo      = System.Drawing.Image.FromHbitmap(TTB_Manager.Properties.Resources.pdf_header.GetHbitmap());
            Image ABCRCLogo = Image.GetInstance(logo, System.Drawing.Imaging.ImageFormat.Tiff);

            ABCRCLogo.ScaleAbsolute(doc.PageSize.Width, doc.PageSize.Width * logo.Height / logo.Width - 5);
            doc.Add(Image.GetInstance(ABCRCLogo));

            //Import underlined-adress-header

            String pdf_header_adress = "TTBPersonal UG, Martin-Luther-Straße 17, 01099 Dresden";

            paragraph = new Paragraph(pdf_header_adress, Default_Font(8, Font.UNDERLINE));
            doc.Add(setProps(paragraph, 1));
            doc.Add(new Paragraph("\n\n"));

            //Import header left and right
            PdfPTable table_header_text = new PdfPTable(2);

            table_header_text.DefaultCell.Border = 0;
            table_header_text.TotalWidth         = doc.PageSize.Width * (content_width_percentage / 100);


            String pdf_adress = workplace.name + "\n"
                                + workplace.ust_id + "\n"
                                + workplace.extra + "\n"
                                + workplace.accounting_adress.street + " " + workplace.accounting_adress.number + "\n"
                                + workplace.accounting_adress.plz + " " + workplace.accounting_adress.city + "\n"
                                + workplace.accounting_adress.country + "\n";

            paragraph = new Paragraph(pdf_adress, Default_Font(10));

            table_header_text.AddCell(paragraph);

            Phrase phrase = new Phrase();

            phrase.Add(new Chunk("Personalvermittlung & Personalleasing", Default_Font(11)));

            String pdf_header_right = "\n\nAnsprechpartner: Thomas Jahn\n\n"
                                      + "Tel.: (+49) 351 897 368 99\n"
                                      + "E-Mail: [email protected]\n"
                                      + "Steuernummer: 202/121/09429\n\n"
                                      + "Datum: " + cur_date;

            phrase.Add(new Chunk(pdf_header_right, Default_Font(10)));

            paragraph = new Paragraph(phrase);
            PdfPCell cell = new PdfPCell(paragraph);

            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.Border = 0;
            table_header_text.AddCell(cell);


            doc.Add(table_header_text);



            //Import bill-nr
            String pdf_bill_nr = "Rechnung Nr.: " + bill_nr;

            paragraph = new Paragraph(pdf_bill_nr, Default_Font(10, Font.BOLD));
            doc.Add(setProps(paragraph, 1));

            doc.Add(new Paragraph("\n\n"));

            //Import prev-mail
            String pdf_prev_mail = "";

            if (!workplace.contact_person.Equals(""))
            {
                if (workplace.gender_of_contact_person == 0)
                {
                    pdf_prev_mail = "Sehr geehrter Herr ";
                }
                else
                {
                    pdf_prev_mail = "Sehr geehrte Frau ";
                }
                pdf_prev_mail += workplace.contact_person;
            }
            else
            {
                pdf_prev_mail = "Sehr geehrte Damen und Herren";
            }


            pdf_prev_mail += ",\n\n"
                             + "vielen Dank für die Zusammenarbeit mit unserem Unternehmen. Für die bei Ihnen erbrachten Leistungen stellen wir Ihnen folgenden Betrag in Rechnung:\n\n"
                             + "Leistungszeitraum: " + date_start_string + " bis " + date_end_string + "\n"
                             + "Entleiher: " + workplace.name;
            paragraph = new Paragraph(pdf_prev_mail, Default_Font(10));
            doc.Add(setProps(paragraph, 1.1f));

            //Import usage-line
            phrase = new Phrase();
            phrase.Add(new Chunk("Verwendungszweck: ", Default_Font(10)));
            phrase.Add(new Chunk(bill_nr, Default_Font(10, Font.BOLD)));

            paragraph = new Paragraph(phrase);
            doc.Add(setProps(paragraph, 1.1f));

            doc.Add(new Paragraph("\n"));

            /*
             * //Testliste
             * for (int k=0;k<5;k++) {
             *  Accounting_Position ap = new Accounting_Position();
             *  ap.amount = k + 3;
             *  ap.description = "";
             *  ap.price = 2.5f;
             *  ap.tax = 19f;
             *  ap.unit = Unit.Std;
             *  position_list.Add(ap);
             *
             * }
             */

            //Import position_table
            PdfPTable table_positions = new PdfPTable(7);

            table_positions.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
            float default_border_width = table_positions.DefaultCell.BorderWidth;

            table_positions.DefaultCell.BorderWidth = 2;

            table_positions.AddCell(new Paragraph("Pos.", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("Anzahl", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("Einheit", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("Beschreibung", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("Preis in €/h", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("MwSt. in %", Default_Font(10, Font.BOLD)));
            table_positions.AddCell(new Paragraph("Gesamt in €", Default_Font(10, Font.BOLD)));


            float[] floatWidths = { 7, 10, 10, 43, 7, 8, 10 };
            table_positions.SetWidths(floatWidths);
            table_positions.TotalWidth = doc.PageSize.Width * (content_width_percentage / 100);

            table_positions.DefaultCell.Border      = Rectangle.BOTTOM_BORDER;
            table_positions.DefaultCell.BorderWidth = default_border_width;

            for (int i = 0; i < position_list.Count; i++)
            {
                table_positions.AddCell(new Paragraph("" + (i + 1), Default_Font(10)));
                table_positions.AddCell(new Paragraph("" + position_list[i].amount.ToString("0.0"), Default_Font(10)));
                table_positions.AddCell(new Paragraph("" + position_list[i].unit + ".", Default_Font(10)));
                try {
                    if (position_list[i].description.Equals(""))
                    {
                        table_positions.AddCell(new Paragraph("Personalüberlassung", Default_Font(10)));
                    }
                    else
                    {
                        table_positions.AddCell(new Paragraph("" + position_list[i].description, Default_Font(10)));
                    }
                } catch (NullReferenceException) {
                    doc.Close();
                    return(0);
                }


                table_positions.AddCell(new Paragraph("" + position_list[i].price.ToString("0.00"), Default_Font(10)));
                table_positions.AddCell(new Paragraph("" + position_list[i].tax.ToString("0.00"), Default_Font(10)));
                table_positions.AddCell(new Paragraph("" + (position_list[i].price * position_list[i].amount).ToString("0.00"), Default_Font(10)));
            }
            doc.Add(table_positions);

            //Calculate Sums
            double pdf_netto = 0,
                   pdf_mwst  = 0,
                   pdf_sum   = 0;

            for (int i = 0; i < position_list.Count; i++)
            {
                pdf_netto += position_list[i].amount * position_list[i].price;
                pdf_mwst  += position_list[i].amount * position_list[i].price * (position_list[i].tax / 100);
            }
            pdf_sum = pdf_mwst + pdf_netto;


            //Import Results (Netto ...)

            PdfPTable table_sums = new PdfPTable(2);

            table_sums.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
            float[] sumtable_floatWidths = { 65, 35 };
            table_sums.SetWidths(sumtable_floatWidths);
            table_sums.TotalWidth          = 200f;
            table_sums.LockedWidth         = true;
            table_sums.HorizontalAlignment = Element.ALIGN_RIGHT;

            table_sums.AddCell(new Paragraph("NETTO", Default_Font(10, Font.BOLD)));
            table_sums.AddCell(new Paragraph(pdf_netto.ToString("0.00") + " €", Default_Font(10, Font.BOLD)));
            table_sums.AddCell(new Paragraph("MwSt.", Default_Font(10, Font.BOLD)));
            table_sums.AddCell(new Paragraph(pdf_mwst.ToString("0.00") + " €", Default_Font(10, Font.BOLD)));
            table_sums.AddCell(new Paragraph("Summe", Default_Font(10, Font.BOLD)));
            table_sums.AddCell(new Paragraph(pdf_sum.ToString("0.00") + " €", Default_Font(10, Font.BOLD)));

            PdfPTable table_sumsInSums = new PdfPTable(2);

            table_sumsInSums.TotalWidth         = doc.PageSize.Width * (content_width_percentage / 100);
            table_sumsInSums.DefaultCell.Border = 0;
            cell = new PdfPCell(table_sums);
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.Border = 0;
            table_sumsInSums.AddCell("");
            table_sumsInSums.AddCell(cell);

            doc.Add(table_sumsInSums);



            doc.Add(new Paragraph("\n"));

            //Import suf-mail
            phrase = new Phrase();
            String pdf_suf_mail1 = "Die genauen Arbeitszeiten entnehmen Sie bitte dem Ihnen vorliegenden „Arbeitszeitennachweis Arbeitgeber“. Bitte überweisen Sie den Betrag ";
            String pdf_suf_mail2 = "bis " + deadline;
            String pdf_suf_mail3 = " auf das unten angegebene Konto. Über eine weitere Zusammenarbeit mit Ihnen freuen wir uns sehr.\n"
                                   + "Sehr geehrte Daen und Herren, unsere Kontoverbindungen haben sich geändert. Bitte überweisen Sie künftig die Rechnungen auf das Konto mit der\n";

            phrase.Add(new Chunk(pdf_suf_mail1, Default_Font(10)));
            phrase.Add(new Chunk(pdf_suf_mail2, Default_Font(10, Font.BOLD)));
            phrase.Add(new Chunk(pdf_suf_mail3, Default_Font(10)));

            String pdf_iban = "            IBAN: " + iban + "\n";

            phrase.Add(new Chunk(pdf_iban, Default_Font(10, Font.BOLD)));

            String pdf_suf_mail4 = "bei der Commerzbank Dresden. Bis 30.03.2017 ist unser Konto bei der Dresdner Volksbank noch aktiv.";

            phrase.Add(new Chunk(pdf_suf_mail4, Default_Font(10)));

            paragraph = new Paragraph(phrase);
            doc.Add(setProps(paragraph, 1.1f));

            doc.Add(new Paragraph("\n\n"));

            //Import greeting
            String pdf_greeting = "Mit freundlichen Grüßen\n\n"
                                  + "Thomas Jahn\n"
                                  + "TTBPersonal UG";

            paragraph = new Paragraph(pdf_greeting, Default_Font(10));
            doc.Add(setProps(paragraph, 1.1f));


            doc.Close();
            return(1);
        }
Ejemplo n.º 23
0
        public void pdfClassAssignment(int class_id, int section_id, int month_no, string session)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (Document doc = new Document(PageSize.A4.Rotate()))
                {
                    using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                    {
                        string query = @"SELECT 
                                            b.subject_name,
                                            a.subject_id,
                                            CONCAT(IFNULL(c.FirstName, ''),
                                                    ' ',
                                                    IFNULL(c.LastName, '')) teacher_name
                                        FROM
                                            mst_class_subject_teacher a,
                                            mst_subject b,
                                            emp_profile c
                                        WHERE
                                            a.session = b.session
                                                AND a.subject_id = b.subject_id
                                                AND a.class_id = @class_id
                                                AND a.session = @session
                                                AND a.section_id = @section_id
                                                AND a.subject_teacher_id = c.user_id";

                        IEnumerable <class_subject> class_subject = con.Query <class_subject>(query, new { class_id = class_id, session = session, section_id = section_id });

                        query = @"SELECT 
                                    CONCAT('Class: ',
                                            class_name,
                                            '  ',
                                            'Section: ',
                                            section_name) class_name
                                FROM
                                    mst_section a,
                                    mst_class b
                                WHERE
                                    a.session = b.session
                                        AND a.class_id = b.class_id
                                        AND a.session = @session
                                        AND b.class_id = @class_id
                                        AND a.section_id = @section_id";

                        string class_name = con.Query <string>(query, new { class_id = class_id, session = session, section_id = section_id }).SingleOrDefault();

                        PdfWriter writer = PdfWriter.GetInstance(doc, ms);

                        // writer.PageEvent = new PDFFooter();
                        doc.Open();
                        PdfPTable pt = new PdfPTable(10);
                        pt.WidthPercentage = 90;
                        // string imageURL = "E:\\HPS\\logo.jpg";
                        string imageURL = System.Web.Hosting.HostingEnvironment.MapPath("/images/logo.jpg");
                        Image  jpg      = Image.GetInstance(imageURL);
                        jpg.ScaleAbsolute(60f, 60f);

                        imageURL = System.Web.Hosting.HostingEnvironment.MapPath("/images/cbse.png");
                        Image cbse = Image.GetInstance(imageURL);
                        cbse.ScaleAbsolute(60f, 60f);



                        PdfPCell _cell;
                        Chunk    text;
                        Phrase   ph;
                        _cell        = new PdfPCell(cbse);
                        _cell.Border = 0;

                        _cell.Border        = Rectangle.NO_BORDER;
                        _cell.PaddingBottom = 5;

                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        pt.AddCell(_cell);


                        text = new Chunk(SchoolName, FontFactory.GetFont("Areal", 24));
                        ph   = new Phrase();
                        ph.Add(text);
                        ph.Add("\n");
                        ph.Add("\n");
                        text = new Chunk("(" + Affiliation + ")", FontFactory.GetFont("Areal", 12));
                        ph.Add(text);
                        _cell                     = new PdfPCell(ph);
                        _cell.Colspan             = 8;
                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        _cell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                        _cell.PaddingBottom       = 5;
                        //_cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        pt.AddCell(_cell);

                        ph                        = new Phrase();
                        _cell                     = new PdfPCell(jpg);
                        _cell.Border              = 0;
                        _cell.Border              = Rectangle.NO_BORDER;
                        _cell.PaddingBottom       = 5;
                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        pt.AddCell(_cell);


                        ph   = new Phrase();
                        text = new Chunk("\n", FontFactory.GetFont("Areal", 12));
                        ph.Add(text);
                        _cell                     = new PdfPCell(ph);
                        _cell.Colspan             = 10;
                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        _cell.Border              = iTextSharp.text.Rectangle.TOP_BORDER;
                        _cell.PaddingBottom       = 5;
                        //_cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        pt.AddCell(_cell);

                        mst_sessionMain sess = new mst_sessionMain();

                        mst_session mst = sess.getStartEndDate(session);

                        int year = 0;
                        if (month_no == 1 || month_no == 2 || month_no == 3)
                        {
                            year = mst.session_end_date.Year;
                        }
                        else
                        {
                            year = mst.session_start_date.Year;
                        }

                        ph   = new Phrase();
                        text = new Chunk("Date-wise Assignment Chart for the Month of " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month_no) + " " + year.ToString() + " " + class_name, FontFactory.GetFont("Areal", 15));
                        ph.Add(text);
                        _cell                     = new PdfPCell(ph);
                        _cell.Colspan             = 10;
                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        _cell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                        _cell.PaddingBottom       = 5;
                        //_cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        pt.AddCell(_cell);


                        ph   = new Phrase();
                        text = new Chunk("\n", FontFactory.GetFont("Areal", 12));
                        ph.Add(text);
                        _cell                     = new PdfPCell(ph);
                        _cell.Colspan             = 10;
                        _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        _cell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                        _cell.PaddingBottom       = 5;
                        //_cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        pt.AddCell(_cell);



                        doc.Add(pt);

                        var date_list = getAllDates(year, month_no);

                        pt = new PdfPTable(date_list.Count() + 12);
                        pt.WidthPercentage = 95f;
                        doc.Add(pt);

                        var startOfMonth = new DateTime(year, month_no, 1);
                        var endOfMonth   = startOfMonth.AddMonths(1).AddDays(-1);

                        query = @"SELECT 
                                    subject_id,work_type,DAY(work_date) day
                                FROM
                                    mst_class_notebook
                                WHERE
                                    class_id = @class_id AND session = @session
                                        AND work_date BETWEEN @startOfMonth AND @endOfMonth
                                        AND section_id = @section_id";

                        IEnumerable <mst_class_notebook> CW_HW = con.Query <mst_class_notebook>(query, new { session = session, class_id = class_id, section_id = section_id, startOfMonth = startOfMonth, endOfMonth = endOfMonth });



                        foreach (class_subject dtt in class_subject)
                        {
                            ph   = new Phrase();
                            text = new Chunk("Teacher Name", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 5;
                            _cell.BackgroundColor     = BaseColor.LIGHT_GRAY;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            _cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            pt.AddCell(_cell);

                            ph   = new Phrase();
                            text = new Chunk("Subject Name", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 4;
                            _cell.BackgroundColor     = BaseColor.LIGHT_GRAY;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            _cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            pt.AddCell(_cell);

                            ph   = new Phrase();
                            text = new Chunk("W.Type", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 3;
                            _cell.BackgroundColor     = BaseColor.LIGHT_GRAY;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            _cell.VerticalAlignment   = Element.ALIGN_MIDDLE;

                            pt.AddCell(_cell);

                            for (int i = 0; i <= date_list.Count() - 1; i++)
                            {
                                ph   = new Phrase();
                                text = new Chunk(date_list[i].Day.ToString(), FontFactory.GetFont("Areal", 8));
                                ph.Add(text);
                                ph.Add("\n");
                                text = new Chunk(date_list[i].DayOfWeek.ToString().Substring(0, 1), FontFactory.GetFont("Areal", 8));
                                ph.Add(text);
                                _cell = new PdfPCell(ph);
                                _cell.BackgroundColor     = BaseColor.LIGHT_GRAY;
                                _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                                pt.AddCell(_cell);
                            }

                            ph   = new Phrase();
                            text = new Chunk(dtt.teacher_name, FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 5;
                            _cell.Rowspan             = 2;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            _cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            pt.AddCell(_cell);

                            ph   = new Phrase();
                            text = new Chunk(dtt.subject_name, FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 4;
                            _cell.Rowspan             = 2;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            _cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            pt.AddCell(_cell);

                            ph   = new Phrase();
                            text = new Chunk("C.W", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 3;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            pt.AddCell(_cell);

                            for (int i = 0; i <= date_list.Count() - 1; i++)
                            {
                                var check = (from e in CW_HW where e.day == i + 1 where e.subject_id == dtt.subject_id where e.work_type == "CW" select e).ToList();



                                if (check.Count() > 0)
                                {
                                    ph = new Phrase();

                                    if (System.DateTime.Now >= startOfMonth && System.DateTime.Now <= endOfMonth)
                                    {
                                        if (i <= System.DateTime.Now.Day - 1)
                                        {
                                            text = new Chunk("Y", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                        }
                                        else
                                        {
                                            text = new Chunk("", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                        }
                                    }
                                    else
                                    {
                                        text = new Chunk("Y", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                    }


                                    ph.Add(text);
                                    _cell = new PdfPCell(ph);
                                    _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                                    pt.AddCell(_cell);
                                }
                                else
                                {
                                    ph = new Phrase();
                                    if (System.DateTime.Now >= startOfMonth && System.DateTime.Now <= endOfMonth)
                                    {
                                        if (i <= System.DateTime.Now.Day - 1)
                                        {
                                            text = new Chunk("N", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                        }
                                        else
                                        {
                                            text = new Chunk("", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                        }
                                    }
                                    else
                                    {
                                        text = new Chunk("N", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                    }
                                    ph.Add(text);
                                    _cell = new PdfPCell(ph);
                                    _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                                    pt.AddCell(_cell);
                                }
                            }

                            ph   = new Phrase();
                            text = new Chunk("H.W", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = 3;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            pt.AddCell(_cell);

                            for (int i = 0; i <= date_list.Count() - 1; i++)
                            {
                                var check = (from e in CW_HW where e.day == i + 1 where e.subject_id == dtt.subject_id where e.work_type == "HW" select e).ToList();



                                if (check.Count() > 0)
                                {
                                    ph = new Phrase();

                                    if (System.DateTime.Now >= startOfMonth && System.DateTime.Now <= endOfMonth)
                                    {
                                        if (i <= System.DateTime.Now.Day - 1)
                                        {
                                            text = new Chunk("Y", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                        }
                                        else
                                        {
                                            text = new Chunk("", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                        }
                                    }
                                    else
                                    {
                                        text = new Chunk("Y", FontFactory.GetFont("Areal", 8, BaseColor.BLACK));
                                    }

                                    ph.Add(text);
                                    _cell = new PdfPCell(ph);
                                    _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                                    pt.AddCell(_cell);
                                }
                                else
                                {
                                    ph = new Phrase();

                                    if (System.DateTime.Now >= startOfMonth && System.DateTime.Now <= endOfMonth)
                                    {
                                        if (i <= System.DateTime.Now.Day - 1)
                                        {
                                            text = new Chunk("N", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                        }
                                        else
                                        {
                                            text = new Chunk("", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                        }
                                    }
                                    else
                                    {
                                        text = new Chunk("N", FontFactory.GetFont("Areal", 8, BaseColor.RED));
                                    }

                                    ph.Add(text);
                                    _cell = new PdfPCell(ph);
                                    _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                                    pt.AddCell(_cell);
                                }
                            }

                            ph   = new Phrase();
                            text = new Chunk("\n", FontFactory.GetFont("Areal", 8));
                            ph.Add(text);
                            _cell                     = new PdfPCell(ph);
                            _cell.Colspan             = date_list.Count() + 12;
                            _cell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            pt.AddCell(_cell);
                        }
                        doc.Add(pt);
                        doc.Close();
                        byte[] bytes = ms.ToArray();
                        ms.Close();
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.ContentType = "application/pdf";
                        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=comparative_result.pdf");
                        HttpContext.Current.Response.ContentType = "application/pdf";
                        HttpContext.Current.Response.Buffer      = true;
                        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        HttpContext.Current.Response.BinaryWrite(bytes);
                        HttpContext.Current.Response.End();
                        HttpContext.Current.Response.Close();
                    }
                }
            }
        }
        public void PrintNewCustomerReciept(CustomerMgntRef.Customer customer)
        {
            Distributor dis     = new Distributor();
            string      disName = dis.AgencyName;
            string      disCode = dis.code.ToString();
            string      addr    = dis.Address + ", " + dis.City + "\n" + "District: " + dis.District + ", State: " + dis.State;
            string      phon    = dis.ContectNo;
            string      gstin   = dis.GSTIN;

            try
            {
                #region Page
                #region Section-1

                iTextSharp.text.Font fontH1 = new iTextSharp.text.Font(BaseFont.CreateFont(
                                                                           BaseFont.TIMES_ROMAN,
                                                                           BaseFont.CP1252,
                                                                           BaseFont.EMBEDDED), 8, iTextSharp.text.Font.NORMAL);

                var boldFont = FontFactory.GetFont(FontFactory.TIMES_BOLD, 8);

                PdfPTable pdfTable1 = new PdfPTable(1);//Here 1 is Used For Count of Column
                PdfPTable pdfTable2 = new PdfPTable(2);
                PdfPTable pdfTable3 = new PdfPTable(2);

                pdfTable1.WidthPercentage = 100;
                pdfTable1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable1.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                pdfTable1.DefaultCell.BorderWidth         = 0;

                pdfTable2.WidthPercentage = 100;
                pdfTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable2.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                pdfTable2.DefaultCell.BorderWidth         = 0;

                pdfTable3.WidthPercentage = 100;
                pdfTable3.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                pdfTable3.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                pdfTable3.DefaultCell.BorderWidth         = 0.5f;

                int[] firstTablecellwidth = { 10, 90 };
                pdfTable2.SetWidths(firstTablecellwidth);
                string imageURL = @"./../Debug/Bill/logo.png";
                iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(imageURL);
                myImage.ScaleToFit(38f, 38f);
                myImage.SpacingBefore = 5f;
                myImage.SpacingAfter  = 10f;

                PdfPCell cellWithRowspan = new PdfPCell(myImage);
                cellWithRowspan.BorderWidth         = 0.0f;
                cellWithRowspan.Rowspan             = 3;
                cellWithRowspan.HorizontalAlignment = Element.ALIGN_RIGHT;
                pdfTable2.AddCell(cellWithRowspan);

                Chunk c1 = new Chunk(disName + " (" + disCode + ") ", FontFactory.GetFont("Times New Roman"));
                c1.Font.Color = new iTextSharp.text.BaseColor(255, 0, 0);
                c1.Font.SetStyle(0);
                c1.Font.Size = 10;
                Phrase p1 = new Phrase();
                p1.Add(c1);
                pdfTable2.AddCell(p1);

                Chunk c2 = new Chunk(addr, FontFactory.GetFont("Times New Roman"));
                c2.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
                c2.Font.SetStyle(0);//0 For Normal Font
                c2.Font.Size = 8;
                Phrase p2 = new Phrase();
                p2.Add(c2);
                pdfTable2.AddCell(p2);
                //pdfTable2.AddCell(p2);

                Chunk c3 = new Chunk("Phone No : " + phon + " | GSTIN : " + gstin + "\n\n", FontFactory.GetFont("Times New Roman"));
                c3.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
                c3.Font.SetStyle(0);
                c3.Font.Size = 8;
                Phrase p3 = new Phrase();
                p3.Add(c3);
                pdfTable2.AddCell(p3);
                //pdfTable2.AddCell(p3);
                #endregion


                #region section Table

                pdfTable1.AddCell(new Phrase("New Connetion Reciept"));

                pdfTable3.AddCell(new Phrase(""));

                pdfTable3.AddCell(new Phrase("Customer Id: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.CustomerId + "", fontH1));

                pdfTable3.AddCell(new Phrase("Customer Name: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.CustomerName + "", fontH1));

                pdfTable3.AddCell(new Phrase("Gender: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.Gender + "", fontH1));

                pdfTable3.AddCell(new Phrase("Customer Type: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.CustomerType + "", fontH1));

                pdfTable3.AddCell(new Phrase("Adhar Number: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.AadharNo + "", fontH1));

                pdfTable3.AddCell(new Phrase("Ration Card Number: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.RashanCardNo + "", fontH1));

                pdfTable3.AddCell(new Phrase("Address: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.Address + "", fontH1));

                pdfTable3.AddCell(new Phrase("City/Village: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.City + "", fontH1));

                pdfTable3.AddCell(new Phrase("Taluka: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.Taluka + "", fontH1));

                pdfTable3.AddCell(new Phrase("District: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.District + "", fontH1));

                pdfTable3.AddCell(new Phrase("State: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.State + "", fontH1));

                pdfTable3.AddCell(new Phrase("PIN No.: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.PinNo + "", fontH1));

                pdfTable3.AddCell(new Phrase("Contect No.: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.ContactNo + "", fontH1));

                pdfTable3.AddCell(new Phrase("Email: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.Email + "", fontH1));

                pdfTable3.AddCell(new Phrase("Bank IFSC: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.BankIFSC + "", fontH1));

                pdfTable3.AddCell(new Phrase("Bank Account No.: ", fontH1));
                pdfTable3.AddCell(new Phrase(customer.BankAccountNo + "", fontH1));

                var cell = new PdfPCell(new Phrase("\n'Your Safety is our Priority' In case of Emergency Call 1906 For any complaints / Queries call: 1800 - 233 - 3555(Toll Free)", fontH1));
                cell.Colspan = 2;
                pdfTable3.AddCell(cell);

                var cell1 = new PdfPCell(new Phrase("\n\n" + dis.AgencyName + "\n" + "\t\t" + "Signature & Sign of Distributor", fontH1));
                var cell2 = new PdfPCell(new Phrase("\n\n\n" + "\t\t" + "Signature of Customer", fontH1));
                cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                cell2.HorizontalAlignment = Element.ALIGN_CENTER;
                pdfTable3.AddCell(cell1);
                pdfTable3.AddCell(cell2);
                #endregion

                #endregion


                SaveFileDialog sfd = new SaveFileDialog();
                sfd.InitialDirectory = @"C:\";
                sfd.RestoreDirectory = true;
                sfd.FileName         = "CloseCust";
                sfd.DefaultExt       = "pdf";
                sfd.Filter           = "Pdf Files|*.pdf";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string path = sfd.FileName;
                    using (FileStream stream = new FileStream(path, FileMode.Create))
                    {
                        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                        PdfWriter.GetInstance(pdfDoc, stream);
                        pdfDoc.Open();
                        #region PAGE-1
                        pdfDoc.Add(pdfTable2);
                        pdfDoc.Add(pdfTable1);
                        pdfDoc.Add(pdfTable3);
                        pdfDoc.NewPage();
                        #endregion

                        pdfDoc.Close();
                        stream.Close();
                    }
                    MessageBox.Show("New Connetion Reciept is generated successfully!!!");
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 25
0
        //InovoiceTitle: PDF 标题, invoiceName:给谁发invoice,invoicemount:总共的amount, infos:看models文件夹,这个list里的东西全放在pdf里的table里、
        //filename 文件保存的名字
        protected static void InvoiceGenerator(string invoiceTitle, string invoiceName, decimal invoiceAmount, List <InvoicePdfGeneratorModel> infos, string filename)
        {
            //title

            PdfPTable title = new PdfPTable(1);

            title.WidthPercentage = 80;
            title.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            title.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
            title.DefaultCell.BorderWidth         = 0;
            Chunk titleChunk = new Chunk(invoiceTitle, FontFactory.GetFont("Times New Roman"));

            titleChunk.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
            titleChunk.Font.SetStyle(0);
            titleChunk.Font.Size = 18;
            Phrase titlePhrase = new Phrase();

            titlePhrase.Add(titleChunk);
            title.AddCell(titlePhrase);

            //blank
            PdfPTable pdfTableBlank = new PdfPTable(1);

            pdfTableBlank.DefaultCell.BorderWidth = 0;
            pdfTableBlank.DefaultCell.Border      = 0;
            pdfTableBlank.AddCell(new Phrase(" "));

            //invoice to (who)
            PdfPTable name = new PdfPTable(1);

            name.WidthPercentage         = 80;
            name.DefaultCell.BorderWidth = 0;
            Chunk nameChunk = new Chunk("Invoice To: " + invoiceName, FontFactory.GetFont("Times New Roman"));

            nameChunk.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
            nameChunk.Font.SetStyle(0);
            nameChunk.Font.Size = 10;
            Phrase namePhrase = new Phrase();

            namePhrase.Add(nameChunk);
            name.AddCell(namePhrase);

            //detail table
            PdfPTable table = new PdfPTable(2);

            table.DefaultCell.Padding     = 5;
            table.WidthPercentage         = 80;
            table.DefaultCell.BorderWidth = 0.5f;
            table.AddCell(new Phrase("Title"));
            table.AddCell(new Phrase("Amount"));
            infos.ForEach(s =>
            {
                table.AddCell(s.title);
                table.AddCell("$ " + s.amount);
            });

            //Total Amount
            PdfPTable amount = new PdfPTable(1);

            amount.WidthPercentage         = 80;
            amount.DefaultCell.BorderWidth = 0;
            Chunk amountchunk = new Chunk("Total Amount: $ " + invoiceAmount, FontFactory.GetFont("Times New Roman"));

            amountchunk.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0);
            amountchunk.Font.SetStyle(0);
            amountchunk.Font.Size = 14;
            Phrase amountPhrase = new Phrase();

            amountPhrase.Add(amountchunk);
            amount.AddCell(amountPhrase);


            var filenameToKeep = filename + ".pdf";
            var path           = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "invoice", filenameToKeep);

            using (FileStream stream = new FileStream(path, FileMode.Create))
            {
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();

                pdfDoc.Add(title);
                pdfDoc.Add(pdfTableBlank);
                pdfDoc.Add(name);
                pdfDoc.Add(pdfTableBlank);
                pdfDoc.Add(table);
                pdfDoc.Add(pdfTableBlank);
                pdfDoc.Add(amount);
                pdfDoc.Close();
                stream.Close();
            }
        }
Ejemplo n.º 26
0
        public void DoPdf(object sender, EventArgs e)
        {
            string _dateDebut = this.startdate.Text.ToString();
            string _dateFin   = this.enddate.Text.ToString();
            string _id        = _idv;
            ////string _contact = "L'Etat du moteur";
            ////string _speed = "Vitesse";

            string req1 = "select aff.matricule,aff.DateAlert,aff.titre,aff.Descriptione from( "
                          + " select v.matricule ,n.DateAlert,a.titre,n.Descriptione ,	ROW_NUMBER()OVER (partition BY n.DateAlert order by n.DateAlert) as numero "
                          + " from  Notification n "
                          + "   inner join alerte a on a.alerteid=n.alerteid "
                          + "  inner join vehicules v on v.vehiculeid=n.vehiculeid "
                          + "  inner join user_alerte ua on ua.utilisateurid=n.utilisateurid where"
                          + "  n.utilisateurid='" + this.getCurrentUser().getUserId() + "' and n.vehiculeid='" + _idv + "'  "
                          + "   and cast(n.DateAlert AS datetime) >= '" + _dateDebut + "'"
                          + "   and  cast(n.DateAlert AS datetime) <= '" + _dateFin + "' )aff where aff.numero=1 ";

            DataTable dat = GetData(req1);

            if (dat.Rows.Count > 0)
            {
                DataRow  dr         = dat.Rows[0];
                Document document   = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
                Font     NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
                using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
                {
                    float[] widths             = new float[] { 6f, 6f, 6f, 11f };
                    iTextSharp.text.Font font5 = FontFactory.GetFont("Arial", 7);
                    iTextSharp.text.Font font6 = FontFactory.GetFont("Arial", 9);

                    PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
                    Phrase    phrase = null;
                    PdfPCell  cell   = null;
                    PdfPTable table  = null;
                    PdfPTable table2 = null;
                    Color     color  = null;

                    document.Open();

                    table             = new PdfPTable(2);
                    table.TotalWidth  = 800f;
                    table.LockedWidth = true;
                    table.SetWidths(new float[] { 0.4f, 0.6f });
                    double somkm = 0;
                    double tpm   = 0;
                    double vts   = 0;
                    int    idt   = 0;
                    foreach (DataRow row in dat.Rows)
                    {
                        idt++;
                    }


                    //Company Logo
                    cell = ImageCell("~/Ressources/Images/logo.png", 70f, PdfPCell.ALIGN_CENTER);
                    table.AddCell(cell);

                    //Company Name and Address
                    phrase = new Phrase();
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));

                    phrase.Add(new Chunk("Rapport  des alertes \n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.GRAY)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk("Reference vehicule :" + _idv, FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));

                    phrase.Add(new Chunk("De : " + startdate.Text, FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk("A  : " + enddate.Text, FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));

                    TimeSpan tm = TimeSpan.FromMinutes(tpm);

                    DateTime d1  = DateTime.ParseExact(startdate.Text + " 00:00:00", "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                    DateTime d2  = DateTime.ParseExact(enddate.Text + " 00:00:00", "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                    TimeSpan ts  = d2 - d1;
                    TimeSpan th  = TimeSpan.FromHours(24);
                    TimeSpan def = th - tm;

                    phrase.Add(new Chunk("Nombre alertes :" + idt, FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));

                    //phrase.Add(new Chunk("Vitesse moyenne : " + (int)vts / idt + " Km/h", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    //phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));

                    phrase.Add(new Chunk("\n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                    cell.VerticalAlignment = PdfCell.ALIGN_TOP;
                    table.AddCell(cell);

                    color = new Color(System.Drawing.ColorTranslator.FromHtml("#A9A9A9"));
                    DrawLine(writer, 25f, document.Top - 150f, document.PageSize.Width - 25f, document.Top - 150f, color);
                    DrawLine(writer, 25f, document.Top - 150f, document.PageSize.Width - 25f, document.Top - 150f, color);


                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk("\n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    phrase.Add(new Chunk(" \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
                    cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
                    cell.VerticalAlignment = PdfCell.ALIGN_TOP;
                    table.AddCell(cell);



                    document.Add(table);



                    //Separater Line
                    table2                 = new PdfPTable(dat.Columns.Count);
                    table2.TotalWidth      = 500f;
                    table2.LockedWidth     = true;
                    table2.WidthPercentage = 100;
                    table2.SetWidths(widths);


                    //table2.SetWidths(new float[] { 0.4f, 0.6f });


                    for (int j = 0; j < dat.Columns.Count; j++)
                    {
                        table2.AddCell(new Phrase(dat.Columns[j].ColumnName, font6));
                    }

                    table2.HeaderRows = 1;


                    for (int i = 0; i < dat.Rows.Count; i++)
                    {
                        for (int k = 0; k < dat.Columns.Count; k++)
                        {
                            if (dat.Rows[i][k] != null)
                            {
                                table2.AddCell(new Phrase(dat.Rows[i][k].ToString(), font5));
                            }
                        }
                    }

                    string msg1 = "brrrrrr";
                    document.Add(table2);
                    document.Close();
                    byte[] bytes = memoryStream.ToArray();
                    memoryStream.Close();
                    Response.Clear();
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("Content-Disposition", "attachment; filename=Rapport" + DateTime.Now.Ticks + ".pdf");
                    Response.Write(msg1);
                    Response.Buffer = true;
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.BinaryWrite(bytes);
                    Response.End();
                    Response.Close();
                }
            }
            else
            {
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Aucun Rapport trouver dans cette periode ! ')</SCRIPT>");
            }
        }
Ejemplo n.º 27
0
        public void DownloadPDFFormat()
        {
            try
            {
                Document pdfReport = new Document(PageSize.A4, 25, 25, 40, 25);
                System.IO.MemoryStream msReport = new System.IO.MemoryStream();
                PdfWriter writer = PdfWriter.GetInstance(pdfReport, msReport);
                pdfReport.Open();

                string datetime = string.Empty;
                datetime = Convert.ToString(System.DateTime.Now);
                string str = string.Empty;

                if (txtpersonnel.Text != "")
                {
                    str = ("   Personnel : " + txtpersonnel.Text);
                }
                if (txtchkpoint.Text != "")
                {
                    str = ("   Check Point : " + txtchkpoint.Text);
                }
                if (txtdatefrom.Text != "" && txtdateto.Text != "")
                {
                    str = ("   Date  From :" + txtdatefrom.Text + "      To :" + txtdateto.Text);
                }


                //Create Heading
                Phrase headerPhrase = new Phrase("Guard Patro System Report                                                       ", FontFactory.GetFont("Garamond", 14));

                headerPhrase.Add("                                                     Generated On : ");
                headerPhrase.Add(datetime);
                headerPhrase.Add("                                                                           Searching Parameter  : ");
                headerPhrase.Add(str);



                //Create Heading
                // Phrase headerPhrase = new Phrase("Contractor Report", FontFactory.GetFont("TIMES_ROMAN", 16));
                HeaderFooter header = new HeaderFooter(headerPhrase, false);
                header.Border    = Rectangle.NO_BORDER;
                header.Alignment = Element.ALIGN_CENTER;
                header.Alignment = Element.ALIGN_BOTTOM;
                pdfReport.Header = header;
                pdfReport.Add(headerPhrase);


                // Creates the Table
                PdfPTable ptData = new PdfPTable(gvLoctionTable.Columns.Count);
                ptData.SpacingBefore       = 8;
                ptData.DefaultCell.Padding = 1;

                float[] headerwidths = new float[gvLoctionTable.Columns.Count]; // percentage

                headerwidths[0] = 4.2F;
                headerwidths[1] = 3.5F;
                headerwidths[2] = 4.2F;
                headerwidths[3] = 4.2F;
                headerwidths[4] = 3.2F;
                headerwidths[5] = 4.2F;

                ptData.SetWidths(headerwidths);
                ptData.WidthPercentage = 100;
                ptData.DefaultCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
                ptData.DefaultCell.VerticalAlignment   = Element.ALIGN_MIDDLE;

                //Insert the Table Headers
                for (int intK = 0; intK < gvLoctionTable.Columns.Count; intK++)
                {
                    PdfPCell cell = new PdfPCell();
                    cell.BorderWidth     = 0.001f;
                    cell.BackgroundColor = new Color(200, 200, 200);
                    cell.BorderColor     = new Color(100, 100, 100);
                    cell.Phrase          = new Phrase(gvLoctionTable.Columns[intK].HeaderText.ToString(), FontFactory.GetFont("TIMES_ROMAN", BaseFont.WINANSI, 7, Font.BOLD));
                    ptData.AddCell(cell);
                }

                ptData.HeaderRows = 1;  // this is the end of the table header

                //Insert the Table Data

                for (int intJ = 0; intJ < gvLoctionTable.Rows.Count; intJ++)
                {
                    for (int intK = 0; intK < gvLoctionTable.Columns.Count; intK++)
                    {
                        PdfPCell cell = new PdfPCell();
                        cell.BorderWidth     = 0.001f;
                        cell.BorderColor     = new Color(100, 100, 100);
                        cell.BackgroundColor = new Color(250, 250, 250);
                        if (gvLoctionTable.Rows[intJ].Cells[intK].Text.ToString() != "&nbsp;")
                        {
                            cell.Phrase = new Phrase(gvLoctionTable.Rows[intJ].Cells[intK].Text.ToString(), FontFactory.GetFont("TIMES_ROMAN", BaseFont.WINANSI, 6));
                        }
                        else
                        {
                            cell.Phrase = new Phrase("", FontFactory.GetFont("TIMES_ROMAN", BaseFont.WINANSI, 6));
                        }
                        ptData.AddCell(cell);
                    }
                }

                //Insert the Table

                pdfReport.Add(ptData);

                //Closes the Report and writes to Memory Stream

                pdfReport.Close();

                //Writes the Memory Stream Data to Response Object
                Response.Clear();
                // Response.AddHeader("content-disposition", string.Format("attachment;filename=" + ConfigurationManager.AppSettings["TxnInfoPdfFile"]));
                Response.AddHeader("content-disposition", string.Format("attachment;filename=GuardPatrosystempfd.pdf"));
                Response.Charset     = "";
                Response.ContentType = "application/pdf";
                Response.BinaryWrite(msReport.ToArray());
                Response.End();
            }
            catch (Exception ex)
            {
                // logger.Info(ex.Message);
            }
        }
        public string SavePage(string appid)
        {
            DBConnection dBConnection = new DBConnection();

            string[] str = new string[5];
            str = dBConnection.getNewData(appid);
            string pdfLocation  = ConfigurationManager.AppSettings["SavePdfLocation"];
            string fontBase     = ConfigurationManager.AppSettings["rootPath"];
            string fontLocation = ConfigurationManager.AppSettings["fontsLocation"];

            Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
            BaseFont marathi;
            BaseFont english;

            try
            {
                marathi = iTextSharp.text.pdf.BaseFont.CreateFont(fontBase + fontLocation + "aarti_0.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED
                english = iTextSharp.text.pdf.BaseFont.CreateFont(fontBase + fontLocation + "times_1.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED
                iTextSharp.text.Font fontenglish     = new iTextSharp.text.Font(english, 14, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font marathiContent  = new iTextSharp.text.Font(marathi, 23, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font englishContent  = new iTextSharp.text.Font(english, 14, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font fontNormal      = new iTextSharp.text.Font(marathi, 30, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font fontNormaladd   = new iTextSharp.text.Font(marathi, 20, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font fontNormalemail = new iTextSharp.text.Font(marathi, 14, iTextSharp.text.Font.NORMAL);
                string str1 = appid;
                Regex  reg  = new Regex("[*'-/\",_&#^@]");
                str1 = reg.Replace(str1, string.Empty);

                Regex reg1 = new Regex("[ ]");
                str1 = reg.Replace(str1, "-");
                Console.WriteLine(str1);
                bool exists = Directory.Exists(pdfLocation);
                if (!exists)
                {
                    Directory.CreateDirectory(pdfLocation);
                }

                PdfWriter wri;
                try
                {
                    wri = PdfWriter.GetInstance(doc, new FileStream(pdfLocation + "Application-" + str1 + ".pdf", FileMode.Create));
                    //Open Document to write
                    try
                    {
                        doc.Open();
                        PdfPTable table = new PdfPTable(5);
                        PdfPCell  cell;

                        string logoLocation = ConfigurationManager.AppSettings["logoLocation"];
                        string imageURL     = fontBase + logoLocation;
                        Image  jpg;
                        try
                        {
                            jpg = Image.GetInstance(imageURL);
                            jpg.ScaleToFit(140f, 120f);
                            jpg.Alignment            = Element.ALIGN_CENTER;
                            cell                     = new PdfPCell(jpg);
                            cell.Rowspan             = 3;
                            cell.Colspan             = 1;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            table.AddCell(cell);
                        }
                        catch (Exception)
                        {
                        }


                        string bline = "" + Chunk.NEWLINE;
                        iTextSharp.text.Paragraph header = new iTextSharp.text.Paragraph(bline, fontNormal); // --->> CHANGED Specify the font to use
                        Phrase head = new Phrase();
                        head.Add(new Chunk("AaidvaasaI ivacaar pa`itaYzana" + Chunk.NEWLINE, fontNormal));
                        head.Add(new Chunk("(rija.k` . maha. óf ó34054)" + Chunk.NEWLINE + Chunk.NEWLINE, fontNormaladd));
                        cell = new PdfPCell(new Phrase(head));
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                        cell.Colspan             = 5;
                        cell.Rowspan             = 2;
                        table.AddCell(cell);

                        iTextSharp.text.Paragraph addrPara = new iTextSharp.text.Paragraph(bline, fontNormaladd); // --->> CHANGED Specify the font to use
                        string address   = "pattaa: maataaoEa`I nagar, 3Aó105, ivamk ao naa@yaajavaL, gaavadovaI raoD, AMbarnaaqa(pa), ijalha zaNao 421505";
                        string eid       = "*****@*****.**";
                        string email     = "[-maola : ";
                        string sampark   = "saMpak-  : 9833176150ó9766676150";
                        Phrase head_addr = new Phrase();
                        head_addr.Add(new Chunk(address + Chunk.NEWLINE, fontNormaladd));
                        head_addr.Add(new Chunk(email, fontNormalemail));
                        head_addr.Add(new Chunk(eid + Chunk.NEWLINE, fontenglish));
                        head_addr.Add(new Chunk(sampark + Chunk.NEWLINE, fontNormalemail));
                        cell = new PdfPCell(new Phrase(head_addr));
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                        cell.Colspan             = 5;
                        cell.Rowspan             = 1;
                        table.AddCell(cell);

                        string pavti = "paavataI k` .";
                        string srNo  = appid + Chunk.NEWLINE;
                        iTextSharp.text.Paragraph receiptno = new iTextSharp.text.Paragraph(); // --->> CHANGED Specify the font to use
                        Phrase appNo = new Phrase();
                        appNo.Add(new Chunk(pavti, marathiContent));
                        appNo.Add(new Chunk(srNo + Chunk.NEWLINE, fontenglish));
                        cell                     = new PdfPCell(new Phrase(appNo));
                        cell.Colspan             = 5;
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        table.AddCell(cell);



                        string message1 = "Ea`IósaaO ……………… ";
                        string fullName = str[0] + " " + str[1] + ".";
                        string message2 = " rhaNaar…………. ";
                        string custAddr = str[2];
                        string message3 = "  …………………yaaMjak DUna AaidvaasaI ivacaar ";
                        string message4 = "pa`itaYzana saMsqaolaa Aaiqa-k  doNagaI mhNaUna ";
                        string message5 = "r]  ";
                        string amount   = str[3];
                        string message6 = "   (AXarI…………………......................................)";
                        string message7 = "raoKa r@k ma imaLalaI." + Chunk.NEWLINE;
                        string message8 = "Aaiqa-k  madtaIba_la Qanyavaad…." + Chunk.NEWLINE;
                        string message9 = "idnaaMk  : ";
                        string date     = str[4];


                        iTextSharp.text.Paragraph namefield = new iTextSharp.text.Paragraph(); // --->> CHANGED Specify the font to use
                        Phrase myContent = new Phrase();
                        myContent.Add(new Chunk(bline, fontNormal));
                        myContent.Add(new Chunk(message1, marathiContent));
                        myContent.Add(new Chunk(fullName, englishContent));
                        myContent.Add(new Chunk(message2, marathiContent));
                        myContent.Add(new Chunk(custAddr, englishContent));
                        myContent.Add(new Chunk(message3, marathiContent));
                        myContent.Add(new Chunk(message4, marathiContent));
                        myContent.Add(new Chunk(message5, marathiContent));
                        myContent.Add(new Chunk(amount, englishContent));
                        myContent.Add(new Chunk(message6, marathiContent));
                        myContent.Add(new Chunk(message7, marathiContent));
                        myContent.Add(new Chunk(message8, marathiContent));
                        myContent.Add(new Chunk(message9, marathiContent));
                        myContent.Add(new Chunk(date, englishContent));
                        myContent.Add(new Chunk(bline, fontNormal));
                        cell                     = new PdfPCell(new Phrase(myContent));
                        cell.Colspan             = 5;
                        cell.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
                        table.AddCell(cell);


                        string message10 = "sahI       " + Chunk.NEWLINE;
                        string message11 = "(AQyaXaóKaijanadar)";
                        iTextSharp.text.Paragraph signPara = new iTextSharp.text.Paragraph(); // --->> CHANGED Specify the font to use
                        Phrase sign = new Phrase();
                        sign.Add(new Chunk(bline, fontNormal));
                        sign.Add(new Chunk(message10, marathiContent));
                        sign.Add(new Chunk(message11, marathiContent));
                        sign.Add(new Chunk(bline, fontNormal));
                        cell                     = new PdfPCell(new Phrase(sign));
                        cell.Colspan             = 5;
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        table.AddCell(cell);

                        string message12 = "This is Computer generated receipt hence does not require signature";
                        iTextSharp.text.Paragraph signNotRequirePara = new iTextSharp.text.Paragraph(); // --->> CHANGED Specify the font to use
                        Phrase signnotReq = new Phrase();
                        signnotReq.Add(new Chunk(message12, englishContent));
                        cell                     = new PdfPCell(new Phrase(signnotReq));
                        cell.Colspan             = 5;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        table.AddCell(cell);

                        doc.Add(table);
                        doc.Close(); //Close document
                        return("");
                    }
                    catch (Exception e) {
                        return("Document cannot be Created");
                    }
                }
                catch (Exception e)
                {
                    return("File not found.Check path,font path,image path");
                }
            }
            catch (Exception e)
            {
                return("File not found.Check path,font path,image path");
            }
            //  BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont("E:\\AVP-payment\\Avp-Payment\\Avp-Payment\\Font\\aarti_0.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED
            // BaseFont english = iTextSharp.text.pdf.BaseFont.CreateFont("E:\\AVP-payment\\Avp-Payment\\Avp-Payment\\Font\\times_1.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED
        }
Ejemplo n.º 29
0
        public MemoryStream GeneratePdfTemplate(GarmentPackingListViewModel viewModel)
        {
            //int maxSizesCount = viewModel.Items == null || viewModel.Items.Count < 1 ? 0 : viewModel.Items.Max(i => i.Details == null || i.Details.Count < 1 ? 0 : i.Details.Max(d => d.Sizes == null || d.Sizes.Count < 1 ? 0 : d.Sizes.GroupBy(g => g.Size.Id).Count()));
            int maxSizesCount = 0;
            var sizesMax      = new Dictionary <int, string>();

            foreach (var item in viewModel.Items)
            {
                foreach (var detail in item.Details)
                {
                    foreach (var size in detail.Sizes)
                    {
                        sizesMax[size.Size.Id] = size.Size.Size;
                    }
                }
            }
            maxSizesCount = sizesMax.Count;
            int SIZES_COUNT = maxSizesCount > 11 ? 20 : 11;

            Font header_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 14);
            Font normal_font            = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font body_font              = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE);
            Font bold_font              = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);

            Document     document = new Document(maxSizesCount > 11 ? PageSize.A4.Rotate() : PageSize.A4, 20, 20, 70, 30);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            writer.PageEvent = new GarmentPackingListDraftPdfByCartonTemplatePageEvent(_identityProvider, viewModel);

            document.Open();
            PdfContentByte cb = writer.DirectContent;

            PdfPCell cellBorderBottomRight = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };
            PdfPCell cellBorderBottom = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER
            };

            var           cartons       = new List <GarmentPackingListDetailViewModel>();
            double        grandTotal    = 0;
            var           arraySubTotal = new Dictionary <String, double>();
            List <string> cartonNumbers = new List <string>();

            var newItems   = new List <GarmentPackingListItemViewModel>();
            var newItems2  = new List <GarmentPackingListItemViewModel>();
            var newDetails = new List <GarmentPackingListDetailViewModel>();

            foreach (var item in viewModel.Items.OrderBy(a => a.RONo))
            {
                foreach (var detail in item.Details)
                {
                    newDetails.Add(detail);
                }
            }
            newDetails = newDetails.OrderBy(a => a.Carton1).ToList();

            foreach (var d in newDetails)
            {
                if (newItems.Count == 0)
                {
                    var i = viewModel.Items.Single(a => a.Id == d.PackingListItemId);
                    i.Details = new List <GarmentPackingListDetailViewModel>();
                    i.Details.Add(d);
                    newItems.Add(i);
                }
                else
                {
                    if (newItems.Last().Id == d.PackingListItemId)
                    {
                        newItems.Last().Details.Add(d);
                    }
                    else
                    {
                        var y = viewModel.Items.OrderBy(o => o.RONo).Select(a => new GarmentPackingListItemViewModel
                        {
                            Id                  = a.Id,
                            RONo                = a.RONo,
                            Article             = a.Article,
                            BuyerAgent          = a.BuyerAgent,
                            ComodityDescription = a.ComodityDescription,
                            OrderNo             = a.OrderNo,
                            AVG_GW              = a.AVG_GW,
                            AVG_NW              = a.AVG_NW,
                            Uom                 = a.Uom
                        })
                                .Single(a => a.Id == d.PackingListItemId);
                        y.Details = new List <GarmentPackingListDetailViewModel>();
                        y.Details.Add(d);
                        newItems.Add(y);
                    }
                }
            }

            foreach (var item in newItems)
            {
                if (newItems2.Count == 0)
                {
                    newItems2.Add(item);
                }
                else
                {
                    if (newItems2.Last().RONo == item.RONo && newItems2.Last().OrderNo == item.OrderNo)
                    {
                        foreach (var d in item.Details.OrderBy(a => a.Carton1))
                        {
                            newItems2.Last().Details.Add(d);
                        }
                    }
                    else
                    {
                        newItems2.Add(item);
                    }
                }
            }

            document.Add(new Paragraph("SHIPPING METHOD : " + viewModel.ShipmentMode + "\n", normal_font));

            foreach (var item in newItems2)
            {
                #region Item

                PdfPTable tableItem = new PdfPTable(6);
                tableItem.SetWidths(new float[] { 2f, 0.2f, 2.8f, 2f, 0.2f, 2.8f });
                PdfPCell cellItemContent = new PdfPCell()
                {
                    Border = Rectangle.NO_BORDER
                };

                cellItemContent.Phrase = new Phrase("RO No", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(":", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(item.RONo, normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase("ARTICLE", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(":", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(item.Article, normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase("BUYER", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(":", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(viewModel.BuyerAgent.Name, normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase("", normal_font);
                cellItemContent.Phrase = new Phrase("DESCRIPTION OF GOODS", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(":", normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase(item.ComodityDescription, normal_font);
                tableItem.AddCell(cellItemContent);
                cellItemContent.Phrase = new Phrase("", normal_font);
                tableItem.AddCell(cellItemContent);
                tableItem.AddCell(cellItemContent);
                tableItem.AddCell(cellItemContent);

                new PdfPCell(tableItem);
                tableItem.ExtendLastRow = false;
                document.Add(tableItem);

                #endregion

                var sizes = new Dictionary <int, string>();
                foreach (var detail in item.Details)
                {
                    foreach (var size in detail.Sizes)
                    {
                        sizes[size.Size.Id] = size.Size.Size;
                    }
                }

                PdfPTable tableDetail = new PdfPTable(SIZES_COUNT + 11);
                var       width       = new List <float> {
                    2f, 3.5f, 4f, 4f
                };
                for (int i = 0; i < SIZES_COUNT; i++)
                {
                    width.Add(1f);
                }
                width.AddRange(new List <float> {
                    1.5f, 1f, 1.5f, 2f, 1.5f, 1.5f, 1.5f
                });
                tableDetail.SetWidths(width.ToArray());

                PdfPCell cellDetailLine = new PdfPCell()
                {
                    Border = Rectangle.BOTTOM_BORDER, Colspan = 19, Padding = 0.5f, Phrase = new Phrase("")
                };
                tableDetail.AddCell(cellDetailLine);
                tableDetail.AddCell(cellDetailLine);

                cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk("CARTON NO.", normal_font, 0.75f));
                cellBorderBottomRight.Rowspan = 2;
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("COLOUR", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("STYLE", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("ORDER NO.", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk("S I Z E", normal_font, 0.75f));
                cellBorderBottomRight.Colspan = SIZES_COUNT;
                cellBorderBottomRight.Rowspan = 1;
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk("CTNS", normal_font, 0.75f));
                cellBorderBottomRight.Colspan = 1;
                cellBorderBottomRight.Rowspan = 2;
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("@", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("QTY", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk("SATUAN", normal_font, 0.75f));
                cellBorderBottomRight.Colspan = 1;
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk("GW/\nCTN", normal_font, 0.75f));
                cellBorderBottomRight.Rowspan = 2;
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("NW/\nCTN", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("NNW/\nCTN", normal_font, 0.75f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Rowspan = 1;

                for (int i = 0; i < SIZES_COUNT; i++)
                {
                    var size = sizes.OrderBy(a => a.Value).ElementAtOrDefault(i);
                    cellBorderBottomRight.Phrase  = new Phrase(GetScalledChunk(size.Key == 0 ? "" : size.Value, normal_font, 0.5f));
                    cellBorderBottomRight.Rowspan = 1;
                    tableDetail.AddCell(cellBorderBottomRight);
                }

                var subCartons      = new List <GarmentPackingListDetailViewModel>();
                var subGrossWeight  = new List <GarmentPackingListDetailViewModel>();
                var subNetWeight    = new List <GarmentPackingListDetailViewModel>();
                var subNetNetWeight = new List <GarmentPackingListDetailViewModel>();

                double subTotal   = 0;
                var    sizeSumQty = new Dictionary <int, double>();
                foreach (var detail in item.Details)
                {
                    var ctnsQty      = detail.CartonQuantity;
                    var grossWeight  = detail.GrossWeight;
                    var netWeight    = detail.NetWeight;
                    var netNetWeight = detail.NetNetWeight;
                    if (cartonNumbers.Contains($"{detail.Index}-{detail.Carton1}- {detail.Carton2}"))
                    {
                        ctnsQty      = 0;
                        grossWeight  = 0;
                        netWeight    = 0;
                        netNetWeight = 0;
                    }
                    else
                    {
                        cartonNumbers.Add($"{detail.Index}-{detail.Carton1}- {detail.Carton2}");
                    }
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk($"{detail.Carton1}- {detail.Carton2}", normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(detail.Colour, normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(detail.Style, normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(item.OrderNo, normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    for (int i = 0; i < SIZES_COUNT; i++)
                    {
                        var    size     = sizes.OrderBy(a => a.Value).ElementAtOrDefault(i);
                        double quantity = 0;
                        if (size.Key != 0)
                        {
                            quantity = detail.Sizes.Where(w => w.Size.Id == size.Key).Sum(s => s.Quantity);
                        }

                        if (sizeSumQty.ContainsKey(size.Key))
                        {
                            sizeSumQty[size.Key] += quantity * detail.CartonQuantity;
                        }
                        else
                        {
                            sizeSumQty.Add(size.Key, quantity * detail.CartonQuantity);
                        }

                        cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(quantity == 0 ? "" : quantity.ToString(), normal_font, 0.6f));

                        tableDetail.AddCell(cellBorderBottomRight);
                    }
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(ctnsQty.ToString(), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(detail.QuantityPCS.ToString(), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    var totalQuantity = (detail.CartonQuantity * detail.QuantityPCS);
                    subTotal += totalQuantity;
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(totalQuantity.ToString(), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(item.Uom.Unit, normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(string.Format("{0:n2}", detail.GrossWeight), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(string.Format("{0:n2}", detail.NetWeight), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);
                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(string.Format("{0:n2}", detail.NetNetWeight), normal_font, 0.6f));
                    tableDetail.AddCell(cellBorderBottomRight);

                    if (cartons.FindIndex(c => c.Carton1 == detail.Carton1 && c.Carton2 == detail.Carton2 && c.Index == detail.Index) < 0)
                    {
                        cartons.Add(new GarmentPackingListDetailViewModel {
                            Carton1 = detail.Carton1, Carton2 = detail.Carton2, CartonQuantity = ctnsQty
                        });
                    }
                    if (subCartons.FindIndex(c => c.Carton1 == detail.Carton1 && c.Carton2 == detail.Carton2 && c.Index == detail.Index) < 0)
                    {
                        subCartons.Add(new GarmentPackingListDetailViewModel {
                            Carton1 = detail.Carton1, Carton2 = detail.Carton2, CartonQuantity = ctnsQty
                        });
                        subGrossWeight.Add(new GarmentPackingListDetailViewModel {
                            Carton1 = detail.Carton1, Carton2 = detail.Carton2, CartonQuantity = detail.CartonQuantity, GrossWeight = grossWeight
                        });
                        subNetWeight.Add(new GarmentPackingListDetailViewModel {
                            Carton1 = detail.Carton1, Carton2 = detail.Carton2, CartonQuantity = detail.CartonQuantity, NetWeight = netWeight
                        });
                        subNetNetWeight.Add(new GarmentPackingListDetailViewModel {
                            Carton1 = detail.Carton1, Carton2 = detail.Carton2, CartonQuantity = detail.CartonQuantity, NetNetWeight = netNetWeight
                        });
                    }
                }

                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.5f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.5f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.5f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("SUMMARY", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                for (int i = 0; i < SIZES_COUNT; i++)
                {
                    var    size     = sizes.OrderBy(a => a.Value).ElementAtOrDefault(i);
                    double quantity = 0;
                    if (size.Key != 0)
                    {
                        quantity = sizeSumQty.Where(w => w.Key == size.Key).Sum(a => a.Value);
                    }

                    cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk(quantity == 0 ? "" : quantity.ToString(), normal_font, 0.5f));

                    tableDetail.AddCell(cellBorderBottomRight);
                }
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);
                cellBorderBottomRight.Phrase = new Phrase(GetScalledChunk("", normal_font, 0.6f));
                tableDetail.AddCell(cellBorderBottomRight);


                grandTotal += subTotal;
                if (!arraySubTotal.ContainsKey(item.Uom.Unit))
                {
                    arraySubTotal.Add(item.Uom.Unit, subTotal);
                }
                else
                {
                    arraySubTotal[item.Uom.Unit] += subTotal;
                }

                tableDetail.AddCell(new PdfPCell()
                {
                    Border  = Rectangle.BOTTOM_BORDER,
                    Colspan = SIZES_COUNT + 7,
                    Padding = 5,
                    Phrase  = new Phrase("SUB TOTAL ....................................................................................................................................................................... ", normal_font)
                });
                cellBorderBottom.Phrase  = new Phrase(subTotal.ToString() + " " + item.Uom.Unit, normal_font);
                cellBorderBottom.Colspan = 2;
                tableDetail.AddCell(cellBorderBottom);
                cellBorderBottom.Phrase  = new Phrase("", normal_font);
                cellBorderBottom.Colspan = 3;
                tableDetail.AddCell(cellBorderBottom);
                cellBorderBottom.Colspan = 1;

                var subCtns = subCartons.Sum(c => c.CartonQuantity);
                var subGw   = subGrossWeight.Sum(c => c.CartonQuantity * c.GrossWeight);
                var subNw   = subNetWeight.Sum(c => c.CartonQuantity * c.NetWeight);
                var subNnw  = subNetNetWeight.Sum(c => c.CartonQuantity * c.NetNetWeight);

                tableDetail.AddCell(new PdfPCell()
                {
                    Border  = Rectangle.BOTTOM_BORDER,
                    Colspan = SIZES_COUNT + 11,
                    Phrase  = new Phrase($"      - Sub Ctns = {subCtns}           - Sub G.W. = {String.Format("{0:0.00}", subGw)} Kgs           - Sub N.W. = {String.Format("{0:0.00}", subNw)} Kgs            - Sub N.N.W. = {String.Format("{0:0.00}", subNnw)} Kgs", normal_font)
                });

                new PdfPCell(tableDetail);
                tableDetail.ExtendLastRow = false;
                //tableDetail.KeepTogether = true;
                tableDetail.WidthPercentage = 95f;
                //tableDetail.HeaderRows = 3;
                document.Add(tableDetail);
            }

            #region GrandTotal

            PdfPTable tableGrandTotal = new PdfPTable(2);
            tableGrandTotal.SetWidths(new float[] { 18f + SIZES_COUNT * 1f, 5f });
            PdfPCell cellHeaderLine = new PdfPCell()
            {
                Border = Rectangle.BOTTOM_BORDER, Colspan = 2, Padding = 0.5f, Phrase = new Phrase("")
            };

            tableGrandTotal.AddCell(cellHeaderLine);
            tableGrandTotal.AddCell(new PdfPCell()
            {
                Border  = Rectangle.BOTTOM_BORDER,
                Padding = 5,
                Phrase  = new Phrase("GRAND TOTAL .......................................................................................................................................................................", normal_font)
            });
            var grandTotalResult = string.Join(" / ", arraySubTotal.Select(x => x.Value + " " + x.Key).ToArray());
            tableGrandTotal.AddCell(new PdfPCell()
            {
                Border              = Rectangle.BOTTOM_BORDER,
                Padding             = 5,
                HorizontalAlignment = Element.ALIGN_CENTER,
                Phrase              = new Phrase(grandTotalResult, normal_font)
            });
            tableGrandTotal.AddCell(cellHeaderLine);
            var totalCtns  = cartons.Sum(c => c.CartonQuantity);
            var comodities = viewModel.Items.Select(s => s.Comodity.Name.ToUpper()).Distinct();
            tableGrandTotal.AddCell(new PdfPCell()
            {
                Border  = Rectangle.NO_BORDER,
                Colspan = 2,
                Padding = 5,
                Phrase  = new Phrase($"{totalCtns} {viewModel.SayUnit} [ {NumberToTextEN.toWords(totalCtns).Trim().ToUpper()} {viewModel.SayUnit} OF {string.Join(" AND ", comodities)}]", normal_font)
            });

            new PdfPCell(tableGrandTotal);
            tableGrandTotal.ExtendLastRow   = false;
            tableGrandTotal.WidthPercentage = 95f;
            tableGrandTotal.SpacingAfter    = 5f;
            document.Add(tableGrandTotal);

            #endregion

            #region Mark

            PdfPTable tableMark = new PdfPTable(2);
            tableMark.SetWidths(new float[] { 1f, 1f });

            PdfPCell cellShippingMark = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            Chunk chunkShippingMark = new Chunk("SHIPPING MARKS", normal_font);
            chunkShippingMark.SetUnderline(0.5f, -1);
            Phrase phraseShippingMark = new Phrase();
            phraseShippingMark.Add(chunkShippingMark);
            phraseShippingMark.Add(new Chunk("     :", normal_font));
            cellShippingMark.AddElement(phraseShippingMark);
            cellShippingMark.AddElement(new Paragraph(viewModel.ShippingMark, normal_font));
            tableMark.AddCell(cellShippingMark);

            PdfPCell cellSideMark = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            Chunk chunkSideMark = new Chunk("SIDE MARKS", normal_font);
            chunkSideMark.SetUnderline(0.5f, -1);
            Phrase phraseSideMark = new Phrase();
            phraseSideMark.Add(chunkSideMark);
            phraseSideMark.Add(new Chunk("     :", normal_font));
            cellSideMark.AddElement(phraseSideMark);
            cellSideMark.AddElement(new Paragraph(viewModel.SideMark, normal_font)
            {
            });
            tableMark.AddCell(cellSideMark);
            var    noImage = "data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA0NDQ0ODQ4QEA4UFhMWFB4bGRkbHi0gIiAiIC1EKjIqKjIqRDxJOzc7STxsVUtLVWx9aWNpfZeHh5e+tb75+f8BDQ0NDQ4NDhAQDhQWExYUHhsZGRseLSAiICIgLUQqMioqMipEPEk7NztJPGxVS0tVbH1pY2l9l4eHl761vvn5///CABEIAAoACgMBIgACEQEDEQH/xAAVAAEBAAAAAAAAAAAAAAAAAAAAB//aAAgBAQAAAACnD//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIQAAAAf//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMQAAAAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8AH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z";
            byte[] shippingMarkImage;

            if (String.IsNullOrEmpty(viewModel.ShippingMarkImageFile))
            {
                viewModel.ShippingMarkImageFile = noImage;
            }

            if (IsBase64String(Base64.GetBase64File(viewModel.ShippingMarkImageFile)))
            {
                shippingMarkImage = Convert.FromBase64String(Base64.GetBase64File(viewModel.ShippingMarkImageFile));

                Image shipMarkImage = Image.GetInstance(imgb: shippingMarkImage);
                if (shipMarkImage.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 100 / shipMarkImage.Width;
                    shipMarkImage.ScalePercent(percentage * 100);
                    PdfPCell shipMarkImageCell = new PdfPCell(shipMarkImage);
                    shipMarkImageCell.Border = Rectangle.NO_BORDER;
                    tableMark.AddCell(shipMarkImageCell);
                }
            }

            byte[] sideMarkImage;

            if (String.IsNullOrEmpty(viewModel.SideMarkImageFile))
            {
                viewModel.SideMarkImageFile = noImage;
            }

            if (IsBase64String(Base64.GetBase64File(viewModel.SideMarkImageFile)))
            {
                sideMarkImage = Convert.FromBase64String(Base64.GetBase64File(viewModel.SideMarkImageFile));
                Image _sideMarkImage = Image.GetInstance(imgb: sideMarkImage);
                if (_sideMarkImage.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 100 / _sideMarkImage.Width;
                    _sideMarkImage.ScalePercent(percentage * 100);
                }

                PdfPCell _sideMarkImageCell = new PdfPCell(_sideMarkImage);
                _sideMarkImageCell.Border = Rectangle.NO_BORDER;
                tableMark.AddCell(_sideMarkImageCell);
            }

            new PdfPCell(tableMark);
            tableMark.ExtendLastRow = false;
            tableMark.SpacingAfter  = 5f;
            document.Add(tableMark);

            #endregion

            #region Measurement

            PdfPTable tableMeasurement = new PdfPTable(3);
            tableMeasurement.SetWidths(new float[] { 2f, 0.2f, 12f });
            PdfPCell cellMeasurement = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };

            cellMeasurement.Phrase = new Phrase("GROSS WEIGHT", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(":", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(viewModel.GrossWeight + " KGS", normal_font);
            tableMeasurement.AddCell(cellMeasurement);

            cellMeasurement.Phrase = new Phrase("NET WEIGHT", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(":", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(viewModel.NettWeight + " KGS", normal_font);
            tableMeasurement.AddCell(cellMeasurement);

            cellMeasurement.Phrase = new Phrase("NET NET WEIGHT", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(":", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(viewModel.NetNetWeight + " KGS", normal_font);
            tableMeasurement.AddCell(cellMeasurement);

            cellMeasurement.Phrase = new Phrase("MEASUREMENT", normal_font);
            tableMeasurement.AddCell(cellMeasurement);
            cellMeasurement.Phrase = new Phrase(":", normal_font);
            tableMeasurement.AddCell(cellMeasurement);

            PdfPTable tableMeasurementDetail = new PdfPTable(5);
            tableMeasurementDetail.SetWidths(new float[] { 1f, 1f, 1f, 1.5f, 2f });
            PdfPCell cellMeasurementDetail = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT
            };
            decimal totalCbm = 0;
            foreach (var measurement in viewModel.Measurements)
            {
                cellMeasurementDetail.Phrase = new Phrase(measurement.Length + " CM X ", normal_font);
                tableMeasurementDetail.AddCell(cellMeasurementDetail);
                cellMeasurementDetail.Phrase = new Phrase(measurement.Width + " CM X ", normal_font);
                tableMeasurementDetail.AddCell(cellMeasurementDetail);
                cellMeasurementDetail.Phrase = new Phrase(measurement.Height + " CM X ", normal_font);
                tableMeasurementDetail.AddCell(cellMeasurementDetail);
                cellMeasurementDetail.Phrase = new Phrase(measurement.CartonsQuantity + " CTNS = ", normal_font);
                tableMeasurementDetail.AddCell(cellMeasurementDetail);
                var cbm = (decimal)measurement.Length * (decimal)measurement.Width * (decimal)measurement.Height * (decimal)measurement.CartonsQuantity / 1000000;
                totalCbm += cbm;
                cellMeasurementDetail.Phrase = new Phrase(string.Format("{0:N3} CBM", cbm), normal_font);
                tableMeasurementDetail.AddCell(cellMeasurementDetail);
            }

            cellMeasurementDetail.Border = Rectangle.TOP_BORDER;
            cellMeasurementDetail.Phrase = new Phrase("", normal_font);
            tableMeasurementDetail.AddCell(cellMeasurementDetail);
            tableMeasurementDetail.AddCell(cellMeasurementDetail);
            cellMeasurementDetail.Phrase = new Phrase("TOTAL", normal_font);
            tableMeasurementDetail.AddCell(cellMeasurementDetail);
            cellMeasurementDetail.Phrase = new Phrase(viewModel.Measurements.Sum(m => m.CartonsQuantity) + " CTNS .", normal_font);
            tableMeasurementDetail.AddCell(cellMeasurementDetail);
            cellMeasurementDetail.Phrase = new Phrase(string.Format("{0:N3} CBM", totalCbm), normal_font);
            tableMeasurementDetail.AddCell(cellMeasurementDetail);

            new PdfPCell(tableMeasurementDetail);
            tableMeasurementDetail.ExtendLastRow = false;
            var paddingRight = SIZES_COUNT > 11 ? 400 : 200;
            tableMeasurement.AddCell(new PdfPCell(tableMeasurementDetail)
            {
                Border = Rectangle.NO_BORDER, PaddingRight = paddingRight
            });

            tableMeasurement.AddCell(new PdfPCell
            {
                Border  = Rectangle.NO_BORDER,
                Colspan = 3,
                Phrase  = new Phrase("REMARK :", normal_font_underlined)
            });
            tableMeasurement.AddCell(new PdfPCell
            {
                Border  = Rectangle.NO_BORDER,
                Colspan = 3,
                Phrase  = new Phrase(viewModel.Remark, normal_font)
            });
            byte[] remarkImage;

            if (String.IsNullOrEmpty(viewModel.RemarkImageFile))
            {
                viewModel.RemarkImageFile = noImage;
            }

            if (IsBase64String(Base64.GetBase64File(viewModel.RemarkImageFile)))
            {
                remarkImage = Convert.FromBase64String(Base64.GetBase64File(viewModel.RemarkImageFile));

                Image images = Image.GetInstance(imgb: remarkImage);

                if (images.Width > 60)
                {
                    float percentage = 0.0f;
                    percentage = 100 / images.Width;
                    images.ScalePercent(percentage * 100);
                }

                PdfPCell imageCell = new PdfPCell(images);
                imageCell.Border  = Rectangle.NO_BORDER;
                imageCell.Colspan = 3;
                tableMeasurement.AddCell(imageCell);
            }

            new PdfPCell(tableMeasurement);
            tableMeasurement.ExtendLastRow = false;
            tableMeasurement.SpacingAfter  = 5f;
            document.Add(tableMeasurement);
            //document.Add(images);

            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
Ejemplo n.º 30
0
        public MemoryStream GetPDF(Factura entity)
        {
            Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream PDFData = new MemoryStream();
            PdfWriter    writer  = PdfWriter.GetInstance(pdfDoc, PDFData);

            var       titleFont     = FontFactory.GetFont("Arial", 12, Font.BOLD);
            var       titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE);
            var       boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
            var       bodyFont      = FontFactory.GetFont("Arial", 8, Font.NORMAL);
            var       EmailFont     = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE);
            BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");

            Rectangle pageSize = writer.PageSize;

            // Open the Document for writing
            pdfDoc.Open();
            //Add elements to the document here

            #region Top table
            // Create the header table
            PdfPTable headertable = new PdfPTable(3);
            headertable.HorizontalAlignment = 0;
            headertable.WidthPercentage     = 100;
            headertable.SetWidths(new float[] { 100f, 320f, 100f });  // then set the column's __relative__ widths
            headertable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
            //headertable.DefaultCell.Border = Rectangle.BOX; //for testing

            iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Content/img/logo.png"));
            logo.ScaleToFit(100, 15);

            {
                PdfPCell pdfCelllogo = new PdfPCell(logo);
                pdfCelllogo.Border            = iTextSharp.text.Rectangle.NO_BORDER;
                pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                pdfCelllogo.BorderWidthBottom = 1f;
                headertable.AddCell(pdfCelllogo);
            }

            {
                PdfPCell middlecell = new PdfPCell();
                middlecell.Border            = iTextSharp.text.Rectangle.NO_BORDER;
                middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                middlecell.BorderWidthBottom = 1f;
                headertable.AddCell(middlecell);
            }

            {
                PdfPTable nested = new PdfPTable(1);
                nested.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Happy Pets", titleFont));
                nextPostCell1.Border = iTextSharp.text.Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell1);
                PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Bernardo de Irigoyen 696, Boulogne", bodyFont));
                nextPostCell2.Border = iTextSharp.text.Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell2);
                PdfPCell nextPostCell3 = new PdfPCell(new Phrase("(111) 4444-5555", bodyFont));
                nextPostCell3.Border = iTextSharp.text.Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell3);
                PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont));
                nextPostCell4.Border = iTextSharp.text.Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell4);
                nested.AddCell("");
                PdfPCell nesthousing = new PdfPCell(nested);
                nesthousing.Border            = iTextSharp.text.Rectangle.NO_BORDER;
                nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                nesthousing.BorderWidthBottom = 1f;
                nesthousing.Rowspan           = 5;
                nesthousing.PaddingBottom     = 10f;
                headertable.AddCell(nesthousing);
            }


            PdfPTable Invoicetable = new PdfPTable(3);
            Invoicetable.HorizontalAlignment = 0;
            Invoicetable.WidthPercentage     = 100;
            Invoicetable.SetWidths(new float[] { 100f, 320f, 100f });  // then set the column's __relative__ widths
            Invoicetable.DefaultCell.Border = Rectangle.NO_BORDER;

            {
                PdfPTable nested = new PdfPTable(1);
                nested.DefaultCell.Border = Rectangle.NO_BORDER;
                PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Cliente:", bodyFont));
                nextPostCell1.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell1);
                PdfPCell nextPostCell2 = new PdfPCell(new Phrase(entity.Cliente.NombreCompleto, titleFont));
                nextPostCell2.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell2);
                PdfPCell nextPostCell3 = new PdfPCell(new Phrase(entity.Cliente.Direccion, bodyFont));
                nextPostCell3.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell3);
                PdfPCell nextPostCell4 = new PdfPCell(new Phrase("", EmailFont));
                nextPostCell4.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell4);
                nested.AddCell("");
                PdfPCell nesthousing = new PdfPCell(nested);
                nesthousing.Border = Rectangle.NO_BORDER;
                //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                //nesthousing.BorderWidthBottom = 1f;
                nesthousing.Rowspan       = 5;
                nesthousing.PaddingBottom = 10f;
                Invoicetable.AddCell(nesthousing);
            }

            {
                PdfPCell middlecell = new PdfPCell();
                middlecell.Border = Rectangle.NO_BORDER;
                //middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                //middlecell.BorderWidthBottom = 1f;
                Invoicetable.AddCell(middlecell);
            }


            {
                PdfPTable nested = new PdfPTable(1);
                nested.DefaultCell.Border = Rectangle.NO_BORDER;
                PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Factura Nro " + entity.Numero.ToString(), titleFontBlue));
                nextPostCell1.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell1);
                PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Fecha: " + entity.Fecha, bodyFont));
                nextPostCell2.Border = Rectangle.NO_BORDER;
                nested.AddCell(nextPostCell2);
                //PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Due Date: " + DateTime.Now.AddDays(30).ToShortDateString(), bodyFont));
                //nextPostCell3.Border = Rectangle.NO_BORDER;
                //nested.AddCell(nextPostCell3);
                nested.AddCell("");
                nested.AddCell("");
                PdfPCell nesthousing = new PdfPCell(nested);
                nesthousing.Border = Rectangle.NO_BORDER;
                //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                //nesthousing.BorderWidthBottom = 1f;
                nesthousing.Rowspan       = 5;
                nesthousing.PaddingBottom = 10f;
                Invoicetable.AddCell(nesthousing);
            }


            pdfDoc.Add(headertable);
            Invoicetable.PaddingTop = 10f;

            pdfDoc.Add(Invoicetable);
            #endregion

            #region Items Table
            //Create body table
            PdfPTable itemTable = new PdfPTable(5);

            itemTable.HorizontalAlignment = 0;
            itemTable.WidthPercentage     = 100;
            itemTable.SetWidths(new float[] { 5, 40, 10, 20, 25 });  // then set the column's __relative__ widths
            itemTable.SpacingAfter       = 40;
            itemTable.DefaultCell.Border = Rectangle.BOX;
            PdfPCell cell1 = new PdfPCell(new Phrase("NRO.", boldTableFont));
            cell1.BackgroundColor     = TabelHeaderBackGroundColor;
            cell1.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell1);
            PdfPCell cell2 = new PdfPCell(new Phrase("DESCRIPCION", boldTableFont));
            cell2.BackgroundColor     = TabelHeaderBackGroundColor;
            cell2.HorizontalAlignment = 1;
            itemTable.AddCell(cell2);
            PdfPCell cell3 = new PdfPCell(new Phrase("CANTIDAD", boldTableFont));
            cell3.BackgroundColor     = TabelHeaderBackGroundColor;
            cell3.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell3);
            PdfPCell cell4 = new PdfPCell(new Phrase("PRECIO UNITARIO", boldTableFont));
            cell4.BackgroundColor     = TabelHeaderBackGroundColor;
            cell4.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell4);
            PdfPCell cell5 = new PdfPCell(new Phrase("TOTAL", boldTableFont));
            cell5.BackgroundColor     = TabelHeaderBackGroundColor;
            cell5.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell5);
            foreach (var item in entity.ItemFactura.ToList())
            {
                int      ind        = entity.ItemFactura.ToList().IndexOf(item) + 1;
                PdfPCell numberCell = new PdfPCell(new Phrase(ind.ToString(), bodyFont));
                numberCell.HorizontalAlignment = 1;
                numberCell.PaddingLeft         = 10f;
                numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                itemTable.AddCell(numberCell);

                var _phrase = new Phrase();
                _phrase.Add(new Chunk(item.Item.Descripcion, EmailFont));
                _phrase.Add(new Chunk("", bodyFont));
                PdfPCell descCell = new PdfPCell(_phrase);
                descCell.HorizontalAlignment = 0;
                descCell.PaddingLeft         = 10f;
                descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                itemTable.AddCell(descCell);

                PdfPCell qtyCell = new PdfPCell(new Phrase(item.Cantidad.ToString(), bodyFont));
                qtyCell.HorizontalAlignment = 1;
                qtyCell.PaddingLeft         = 10f;
                qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                itemTable.AddCell(qtyCell);

                PdfPCell amountCell = new PdfPCell(new Phrase(item.Precio.ToString(), bodyFont));
                amountCell.HorizontalAlignment = 1;
                amountCell.PaddingLeft         = 10f;
                amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                itemTable.AddCell(amountCell);

                PdfPCell totalamtCell = new PdfPCell(new Phrase(item.Total.ToString(), bodyFont));
                totalamtCell.HorizontalAlignment = 1;
                totalamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                itemTable.AddCell(totalamtCell);
            }
            // Table footer
            PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));
            totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell1);
            PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));
            totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell2);
            PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));
            totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            itemTable.AddCell(totalAmtCell3);
            PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total", boldTableFont));
            totalAmtStrCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
            totalAmtStrCell.HorizontalAlignment = 1;
            itemTable.AddCell(totalAmtStrCell);
            PdfPCell totalAmtCell = new PdfPCell(new Phrase(entity.Importe.ToString(), boldTableFont));
            totalAmtCell.HorizontalAlignment = 1;
            itemTable.AddCell(totalAmtCell);

            //PdfPCell cell = new PdfPCell(new Phrase("***NOTICE: A finance charge of 1.5% will be made on unpaid balances after 30 days. ***", bodyFont));
            //cell.Colspan = 5;
            //cell.HorizontalAlignment = 1;
            //itemTable.AddCell(cell);
            pdfDoc.Add(itemTable);
            #endregion

            PdfContentByte cb = new PdfContentByte(writer);


            //BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);
            //cb = new PdfContentByte(writer);
            //cb = writer.DirectContent;
            //cb.BeginText();
            //cb.SetFontAndSize(bf, 8);
            //cb.SetTextMatrix(pageSize.GetLeft(120), 20);
            //cb.ShowText("Invoice was created on a computer and is valid without the signature and seal. ");
            //cb.EndText();

            ////Move the pointer and draw line to separate footer section from rest of page
            //cb.MoveTo(40, pdfDoc.PageSize.GetBottom(50));
            //cb.LineTo(pdfDoc.PageSize.Width - 40, pdfDoc.PageSize.GetBottom(50));
            //cb.Stroke();

            pdfDoc.Close();
            return(PDFData);
        }
Ejemplo n.º 31
0
 /**
 * Process the text so that it will render with a combination of fonts
 * if needed.
 * @param text the text
 * @return a <CODE>Phrase</CODE> with one or more chunks
 */
 public Phrase Process(String text)
 {
     int fsize = fonts.Count;
     if (fsize == 0)
         throw new ArgumentException("No font is defined.");
     char[] cc = text.ToCharArray();
     int len = cc.Length;
     StringBuilder sb = new StringBuilder();
     Font font = null;
     int lastidx = -1;
     Phrase ret = new Phrase();
     for (int k = 0; k < len; ++k) {
         char c = cc[k];
         if (c == '\n' || c == '\r') {
             sb.Append(c);
             continue;
         }
         if (Utilities.IsSurrogatePair(cc, k)) {
             int u = Utilities.ConvertToUtf32(cc, k);
             for (int f = 0; f < fsize; ++f) {
                 font = (Font)fonts[f];
                 if (font.BaseFont.CharExists(u)) {
                     if (lastidx != f) {
                         if (sb.Length > 0 && lastidx != -1) {
                             Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
                             ret.Add(ck);
                             sb.Length = 0;
                         }
                         lastidx = f;
                     }
                     sb.Append(c);
                     sb.Append(cc[++k]);
                     break;
                 }
             }
         }
         else {
             for (int f = 0; f < fsize; ++f) {
                 font = (Font)fonts[f];
                 if (font.BaseFont.CharExists(c)) {
                     if (lastidx != f) {
                         if (sb.Length > 0 && lastidx != -1) {
                             Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx]);
                             ret.Add(ck);
                             sb.Length = 0;
                         }
                         lastidx = f;
                     }
                     sb.Append(c);
                     break;
                 }
             }
         }
     }
     if (sb.Length > 0) {
         Chunk ck = new Chunk(sb.ToString(), (Font)fonts[lastidx == -1 ? 0 : lastidx]);
         ret.Add(ck);
     }
     return ret;
 }
        public async Task <ActionResult> ProcessOrderAsync(FormCollection frc)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var Delivery            = (from x in db.Maps
                                       where x.Email == User.Identity.Name
                                       orderby x.Id descending
                                       select x.Distance).First().ToString();
            var order = (from i in db.Orders
                         where i.Email == User.Identity.Name
                         orderby i.OrderID descending
                         select i).First();
            // string cos = Delivery.Distance;
            var             UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
            ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId());
            string          ID          = currentUser.Id;
            string          Email       = currentUser.Email;
            string          Name        = currentUser.Name;
            string          SName       = currentUser.Surname;

            byte[] Sign = currentUser.MySignature;
            //var Delivery = (from i in db.Maps
            //                select i).Last();

            List <Cart> lstCart = (List <Cart>)Session[strCart];
            //Models.Order ord = new Models.Order();

            //string a = ord.CollDate.ToString();
            //1.savw the order into order table
            //var order = new Models.Order()
            //{
            //    MySignature = Sign,
            //    CustomerName = frc["cusName"],
            //    Surname = frc["cusSurname"],
            //    CustomerPhone = frc["cusPhone"],
            //    Email = frc["cusEmail"],
            //     //CollDate = Convert.ToDateTime(frc["colDate"]).ToShortDateString(),
            //     CollDate = Convert.ToDateTime(frc["collDate"]).ToShortDateString(),
            //      OrderDate = DateTime.Now,
            //     PaymentType = "PayPal",
            //     //ExpectedReturnDate = Convert.ToDateTime(frc["collDate"]).AddDays(2).ToString("dd/MM/yyyy")
            //     ExpectedReturnDate = Convert.ToDateTime(frc["collDate"]).Date.AddDays(2)
            //     //Status = "Processing"

            // };
            // db.Orders.Add(order);
            //string ReturnDate = "";
            //ReturnDate = Convert.ToDateTime(order.CollDate).AddDays(3).ToString(/*"dd/MM/yyyy"*/);

            OrderDetail orderDetail = new OrderDetail();

            //2. save the order detail into the Order detail table
            List <string>  productName     = new List <string>();
            List <int>     productId       = new List <int>();
            List <int>     productQuantity = new List <int>();
            List <decimal> productPrice    = new List <decimal>();
            List <string>  distance        = new List <string>();
            //List<decimal> deposit = new List<decimal>();
            List <Cart> temp = (List <Cart>)Session["Cart"];
            //var deposit = String.Format("{0:C}", temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2));
            var total = String.Format("{0:C}", (temp.Sum(x => x.Quantity * x.ItemsHire.Price) + temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2)) /* + Delivery.ToString()*//* + Delivery.Distance.ToString()*/);

            foreach (Cart cart in lstCart)
            {
                orderDetail.OrderID     = order.OrderID;
                orderDetail.ProductName = cart.ItemsHire.ProductName;
                orderDetail.ProductID   = cart.ItemsHire.ProductID;
                orderDetail.Quantity    = cart.Quantity;
                orderDetail.Price       = cart.ItemsHire.Price;
                //orderDetail.Distance = Delivery.ToString();
                orderDetail.Deposit = temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2);
                orderDetail.Total   = temp.Sum(x => x.Quantity * x.ItemsHire.Price /* + Convert.ToDecimal(Delivery)*/) + orderDetail.Deposit /* + Convert.ToDecimal(Delivery.Distance.ToString())*/;


                productName.Add(cart.ItemsHire.ProductName);
                productQuantity.Add(cart.Quantity);
                productPrice.Add(cart.ItemsHire.Price);
                //deposit.Add(orderDetail.Deposit);


                db.OrderDetails.Add(orderDetail);
                ItemsHire prod = (from p in db.ItemsHires where p.ProductID == orderDetail.ProductID select p).Single();
                prod.Quantity -= orderDetail.Quantity;
                db.SaveChanges();
            }
            try
            {
                ViewBag.Orders = db.Orders.ToList().FindAll(x => x.OrderID == order.OrderID);


                MemoryStream memoryStream = new MemoryStream();

                StringBuilder status        = new StringBuilder("");
                var           doc           = new Document(PageSize.A4, 10, 10, 10, 10);
                PdfWriter     writer        = PdfWriter.GetInstance(doc, memoryStream);
                var           titleFont     = FontFactory.GetFont("Arial", 12, Font.BOLD);
                var           titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE);
                var           boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
                var           bodyFont      = FontFactory.GetFont("Arial", 8, Font.NORMAL);
                var           EmailFont     = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE);
                BaseColor     TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");
                // doc.SetWidths(headers);

                Rectangle pageSize = writer.PageSize;
                doc.Open();
                PdfPTable header = new PdfPTable(3);
                header.HorizontalAlignment = 0;
                header.WidthPercentage     = 100;
                header.SetWidths(new float[] { 100f, 320f, 100f });
                header.DefaultCell.Border = Rectangle.NO_BORDER;

                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Server.MapPath("~/Content/Images/GP_BLUE.jpg"));
                //var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Content/Images/GP_BLUE.jpg"));
                logo.ScaleToFit(100, 100);
                {
                    PdfPCell pdfCelllogo = new PdfPCell(logo);
                    pdfCelllogo.Border            = Rectangle.NO_BORDER;
                    pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    pdfCelllogo.BorderWidthBottom = 1f;
                    header.AddCell(pdfCelllogo);
                }
                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border            = Rectangle.NO_BORDER;
                    middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    middlecell.BorderWidthBottom = 1f;
                    header.AddCell(middlecell);
                }
                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Gold Pride", titleFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("90 street, Durban, SA,", bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("(082) 0798501", bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border            = Rectangle.NO_BORDER;
                    nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan           = 5;
                    nesthousing.PaddingBottom     = 10f;
                    header.AddCell(nesthousing);
                }
                PdfPTable Invoicetable = new PdfPTable(3);
                Invoicetable.HorizontalAlignment = 0;
                Invoicetable.WidthPercentage     = 100;
                Invoicetable.SetWidths(new float[] { 100f, 320f, 100f });  // then set the column's __relative__ widths
                Invoicetable.DefaultCell.Border = Rectangle.NO_BORDER;

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("INVOICE TO:", bodyFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase(" " + Name, bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("" + order.CollDate, bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase(" " + Email, EmailFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }
                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border = Rectangle.NO_BORDER;
                    //middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //middlecell.BorderWidthBottom = 1f;
                    Invoicetable.AddCell(middlecell);
                }

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Invoice Number: " + order.OrderID, titleFontBlue));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);

                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Date of Invoice: " + order.OrderDate.ToString("dd/MM/yyyy HH:mm:ss"), bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);

                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Pick Up Date: " + order.CollDate.ToShortDateString(), bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);

                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase("Return Date: " + order.ExpectedReturnDate.ToShortDateString(), bodyFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);


                    //PdfPCell nextPostCell5 = new PdfPCell(new Phrase(" Hire Period: " , bodyFont));
                    //nextPostCell5.Border = Rectangle.NO_BORDER;
                    //nested.AddCell(nextPostCell5);


                    PdfPCell nextPostCell5 = new PdfPCell(new Phrase("Collection Status: " + order.PickUp, bodyFont));
                    nextPostCell5.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell5);

                    PdfPCell nextPostCell6 = new PdfPCell(new Phrase("Collectors Name: " + order.CustomerName, bodyFont));
                    nextPostCell6.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell6);

                    //PdfPCell nextPostCell6 = new PdfPCell(new Phrase("Collectors Address" + order.CustomerName, bodyFont));
                    //nextPostCell5.Border = Rectangle.NO_BORDER;
                    //nested.AddCell(nextPostCell6);

                    PdfPCell nextPostCell7 = new PdfPCell(new Phrase("Collectors Number: " + "\n" + order.CustomerPhone, bodyFont));
                    nextPostCell7.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell7);

                    PdfPCell nextPostCell8 = new PdfPCell(new Phrase("Payment Mehtod: " + "PayFast", bodyFont));
                    nextPostCell8.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell8);



                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }


                doc.Add(header);
                Invoicetable.PaddingTop = 10f;

                doc.Add(Invoicetable);

                #region Items Table
                //Create body table
                PdfPTable itemTable = new PdfPTable(5);

                itemTable.HorizontalAlignment = 0;
                itemTable.WidthPercentage     = 100;
                itemTable.SetWidths(new float[] { 5, 40, 10, 20, 25 });  // then set the column's __relative__ widths
                itemTable.SpacingAfter       = 40;
                itemTable.DefaultCell.Border = Rectangle.BOX;
                PdfPCell cell1 = new PdfPCell(new Phrase("PROD ID", boldTableFont));
                cell1.BackgroundColor     = TabelHeaderBackGroundColor;
                cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell1);
                PdfPCell cell2 = new PdfPCell(new Phrase("PRODUCT NAME", boldTableFont));
                cell2.BackgroundColor     = TabelHeaderBackGroundColor;
                cell2.HorizontalAlignment = 1;
                itemTable.AddCell(cell2);

                PdfPCell cell3 = new PdfPCell(new Phrase("QUANTITY", boldTableFont));
                cell3.BackgroundColor     = TabelHeaderBackGroundColor;
                cell3.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell3);

                PdfPCell cell4 = new PdfPCell(new Phrase("UNIT AMOUNT", boldTableFont));
                cell4.BackgroundColor     = TabelHeaderBackGroundColor;
                cell4.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell4);

                //PdfPCell cell5 = new PdfPCell(new Phrase("Delivery Cost", boldTableFont));
                //cell5.BackgroundColor = TabelHeaderBackGroundColor;
                //cell5.HorizontalAlignment = Element.ALIGN_CENTER;
                //itemTable.AddCell(cell5);

                PdfPCell cell5 = new PdfPCell(new Phrase("TOTAL", boldTableFont));
                cell5.BackgroundColor     = TabelHeaderBackGroundColor;
                cell5.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell5);

                foreach (Cart cart in lstCart)
                {
                    orderDetail.OrderID     = order.OrderID;
                    orderDetail.ProductName = cart.ItemsHire.ProductName;
                    orderDetail.ProductID   = cart.ItemsHire.ProductID;
                    orderDetail.Quantity    = cart.Quantity;
                    orderDetail.Price       = cart.ItemsHire.Price;
                    orderDetail.SubTotal    = cart.Quantity * cart.ItemsHire.Price;
                    orderDetail.Deposit     = temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2);
                    orderDetail.Total       = orderDetail.SubTotal + orderDetail.Deposit + Convert.ToDecimal(Delivery) /*temp.Sum(x => x.Quantity * cart.ItemsHire.Price)*//* + Convert.ToDecimal(Delivery) + orderDetail.Deposit*/;

                    PdfPCell numberCell = new PdfPCell(new Phrase("" + orderDetail.ProductID, bodyFont));
                    numberCell.HorizontalAlignment = 1;
                    numberCell.PaddingLeft         = 10f;
                    numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(numberCell);

                    var _phrase = new Phrase();
                    _phrase.Add(new Chunk(" " + orderDetail.ProductName, bodyFont));
                    PdfPCell descCell = new PdfPCell(_phrase);
                    descCell.HorizontalAlignment = 0;
                    descCell.PaddingLeft         = 10f;
                    descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(descCell);

                    PdfPCell qtyCell = new PdfPCell(new Phrase(" " + orderDetail.Quantity, bodyFont));
                    qtyCell.HorizontalAlignment = 1;
                    qtyCell.PaddingLeft         = 10f;
                    qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(qtyCell);

                    PdfPCell amountCell = new PdfPCell(new Phrase(" " + orderDetail.Price, bodyFont));
                    amountCell.HorizontalAlignment = 1;
                    amountCell.PaddingLeft         = 10f;
                    amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(amountCell);

                    //PdfPCell deliveryamtCell = new PdfPCell(new Phrase("240 " /*+ Delivery*/, bodyFont));
                    //deliveryamtCell.HorizontalAlignment = 1;
                    //deliveryamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    //itemTable.AddCell(deliveryamtCell);

                    PdfPCell totalamtCell = new PdfPCell(new Phrase(" " + orderDetail.SubTotal, bodyFont));
                    totalamtCell.HorizontalAlignment = 1;
                    totalamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(totalamtCell);
                }
                //Delivery start
                PdfPCell deliveryCell = new PdfPCell(new Phrase(""));
                deliveryCell.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                itemTable.AddCell(deliveryCell);

                PdfPCell deliveryCell2 = new PdfPCell(new Phrase(""));
                deliveryCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(deliveryCell2);

                PdfPCell deliveryCell3 = new PdfPCell(new Phrase(""));
                deliveryCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(deliveryCell3);

                PdfPCell DeliveryCell = new PdfPCell(new Phrase("Delivery", boldTableFont));
                DeliveryCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                DeliveryCell.HorizontalAlignment = 1;
                itemTable.AddCell(DeliveryCell);

                PdfPCell DelCell = new PdfPCell(new Phrase("$" + Delivery, boldTableFont));
                DelCell.HorizontalAlignment = 1;
                itemTable.AddCell(DelCell);

                //Delivery End

                //Deposit start

                PdfPCell depCell = new PdfPCell(new Phrase(""));
                depCell.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                itemTable.AddCell(depCell);

                PdfPCell depCell2 = new PdfPCell(new Phrase(""));
                depCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(depCell2);

                PdfPCell depCell3 = new PdfPCell(new Phrase(""));
                depCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(depCell3);

                PdfPCell depCelll = new PdfPCell(new Phrase("Deposit", boldTableFont));
                depCelll.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                depCelll.HorizontalAlignment = 1;
                itemTable.AddCell(depCelll);

                PdfPCell depCell4 = new PdfPCell(new Phrase("$" + orderDetail.Deposit, boldTableFont));
                depCell4.HorizontalAlignment = 1;
                itemTable.AddCell(depCell4);

                //Deposit End

                // Table footer
                PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));
                totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell1);
                PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));
                totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell2);
                PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));
                totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell3);
                PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total Amount", boldTableFont));
                totalAmtStrCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                totalAmtStrCell.HorizontalAlignment = 1;
                itemTable.AddCell(totalAmtStrCell);
                PdfPCell totalAmtCell = new PdfPCell(new Phrase("$" + orderDetail.Total, boldTableFont));
                totalAmtCell.HorizontalAlignment = 1;
                itemTable.AddCell(totalAmtCell);

                PdfPCell cell = new PdfPCell(new Phrase("Thank You For Your Support", bodyFont));
                cell.Colspan             = 5;
                cell.HorizontalAlignment = 1;
                itemTable.AddCell(cell);
                doc.Add(itemTable);
                #endregion

                PdfContentByte cb = new PdfContentByte(writer);


                BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);
                cb = new PdfContentByte(writer);
                cb = writer.DirectContent;
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(pageSize.GetLeft(120), 20);
                cb.ShowText("Invoice was created on a computer and is valid without the signature and seal. ");
                cb.EndText();

                //Move the pointer and draw line to separate footer section from rest of page
                cb.MoveTo(40, doc.PageSize.GetBottom(50));
                cb.LineTo(doc.PageSize.Width - 40, doc.PageSize.GetBottom(50));
                cb.Stroke();



                //PdfContentByte content = writer.DirectContent;
                //Rectangle rectangle = new Rectangle(doc.PageSize);
                //rectangle.Left += doc.LeftMargin;
                //rectangle.Right -= doc.RightMargin;
                //rectangle.Top -= doc.TopMargin;
                //rectangle.Bottom += doc.BottomMargin;
                //content.SetColorStroke(GrayColor.BLACK);
                //content.Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height);
                //content.Stroke();


                writer.CloseStream = false;
                doc.Close();
                memoryStream.Position = 0;

                QRModel qr = new QRModel();

                QRCodeGenerator ObjQr = new QRCodeGenerator();

                qr.Message = "https://2020grp26.azurewebsites.net/Order/Details/" + order.OrderID;

                QRCodeData qrCodeData = ObjQr.CreateQrCode(qr.Message, QRCodeGenerator.ECCLevel.Q);

                System.Drawing.Bitmap bitMap = new QRCode(qrCodeData).GetGraphic(20);

                using (MemoryStream ms = new MemoryStream())

                {
                    bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    byte[] byteImage = ms.ToArray();

                    ViewBag.Url = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                    ms.Position = 0;



                    // start of working email
                    SmtpClient client = new SmtpClient("smtp.sendgrid.net");
                    client.Port                  = 25;
                    client.Host                  = "smtp.sendgrid.net";
                    client.Timeout               = 10000;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.EnableSsl             = true;
                    client.UseDefaultCredentials = false;

                    var key = Environment.GetEnvironmentVariable("apikey");

                    client.Credentials = new NetworkCredential("apikey", key /*, user, password*/);

                    System.Net.Mail.Attachment attachment;
                    System.Net.Mail.Attachment attach;
                    attachment = new System.Net.Mail.Attachment(memoryStream, "order.pdf");
                    attach     = new System.Net.Mail.Attachment(ms, "order.png");
                    MailMessage msz = new MailMessage(Email, Email)
                    {
                        From    = new MailAddress(ConfigurationManager.AppSettings["Email"].ToString()),
                        Subject = "order Details for " + Name.ToUpper(),

                        IsBodyHtml = true,
                        Body       = " Good Day : " + Name.ToUpper() + ", Please find attached order information for order ID : " + order.OrderID,
                    };
                    msz.Attachments.Add(attachment);
                    msz.Attachments.Add(attach);

                    client.Send(msz);


                    ModelState.Clear();

                    // end

                    //var at = new SendGrid.Helpers.Mail.Attachment(memoryStream, "Order.pdf");
                    //msz.Attachments.Add(new System.Net.Mail.Attachment(memoryStream, "order.pdf"));
                    // msz.AddAttachment(Server.MapPath(""));
                    //SmtpClient smtp = new SmtpClient();

                    // var response = client.SendMailAsync(msz);
                    //client.SendAsync(msz, null);
                    // smtp.SendAsync(msz);
                }
            }

            catch (Exception ex)
            {
                ModelState.Clear();
                ViewBag.Message = $"sorry we are facing a problem{ex.Message}";
            }



            //3. Remove shopping cart session
            Session.Remove(strCart);



            return(RedirectToAction("Index", "Home"));
        }
		/// <summary>
		/// Parses a script from the specified resource.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="rawPhrase">The phrase which to parse.</param>
		/// <returns>Returns the parsed script.</returns>
		/// <exception cref="ParseScriptException">Thrown when an exception occurres while parsing the script.</exception>
		private Phrase ParsePhrase(IMansionContext context, string rawPhrase)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (rawPhrase == null)
				throw new ArgumentNullException("rawPhrase");

			// create a new phrase
			var phrase = new Phrase();

			// tokenize the raw phrase into smaller sections
			foreach (var token in tokenizer.Tokenize(context, rawPhrase))
			{
				// get the interpreter for this input
				var interpreter = Election<ExpressionPartInterpreter, string>.Elect(context, interpreters, token);

				// interpret the token
				phrase.Add(interpreter.Interpret(context, token));
			}

			// return the parsed phrase
			return phrase;
		}
Ejemplo n.º 34
0
        public PdfPCell GetFormattedICNCellSmallFont(string icn)
        {
            int      lengthICN = icn.Length;
            PdfPCell cell      = new PdfPCell();

            cell.Border = 0;
            cell.HorizontalAlignment = (int)Element.ALIGN_LEFT;
            if (lengthICN != 18)
            {
                return(cell);
            }
            string firstFIve         = icn.Substring(0, 5);
            string afterFirstFIve    = icn.Substring(5, 1);
            string nextSix           = icn.Substring(6, 6);
            string nextOne           = icn.Substring(12, 1);
            string threeAfterNextOne = icn.Substring(13, 3);
            string lastTwo           = icn.Substring(icn.Length - 2, 2);

            Phrase Spacing                 = new Phrase(" ", ReportFontSmall);
            Phrase phraseFirstFive         = new Phrase(firstFIve, ReportFontSmall);
            Phrase phraseAfterFirstFIve    = new Phrase(afterFirstFIve, ReportFontSmall);
            Phrase phraseNextSix           = new Phrase(nextSix, ReportFontSmallBold);
            Phrase phraseNextOne           = new Phrase(nextOne, ReportFontSmall);
            Phrase phraseThreeAfterNextOne = new Phrase(threeAfterNextOne, ReportFontSmallBold);
            Phrase phraseLastTwo           = new Phrase(lastTwo, ReportFontSmall);

            phraseFirstFive.Add(Spacing);
            phraseFirstFive.Add(phraseAfterFirstFIve);
            phraseFirstFive.Add(Spacing);
            phraseFirstFive.Add(phraseNextSix);
            phraseFirstFive.Add(Spacing);
            phraseFirstFive.Add(phraseNextOne);
            phraseFirstFive.Add(Spacing);
            phraseFirstFive.Add(phraseThreeAfterNextOne);
            phraseFirstFive.Add(Spacing);
            phraseFirstFive.Add(phraseLastTwo);
            phraseFirstFive.Add(Spacing);
            cell.AddElement(phraseFirstFive);

            return(cell);
        }
Ejemplo n.º 35
0
 public static Phrase GetPhrase(Properties attributes)
 {
     Phrase phrase = new Phrase();
     phrase.Font = FontFactory.GetFont(attributes);
     String value;
     value = attributes[ElementTags.LEADING];
     if (value != null) {
         phrase.Leading = float.Parse(value, NumberFormatInfo.InvariantInfo);
     }
     value = attributes[Markup.CSS_KEY_LINEHEIGHT];
     if (value != null) {
         phrase.Leading = Markup.ParseLength(value, Markup.DEFAULT_FONT_SIZE);
     }
     value = attributes[ElementTags.ITEXT];
     if (value != null) {
         Chunk chunk = new Chunk(value);
         if ((value = attributes[ElementTags.GENERICTAG]) != null) {
             chunk.SetGenericTag(value);
         }
         phrase.Add(chunk);
     }
     return phrase;
 }
Ejemplo n.º 36
0
        public void PrintExportIO(invoiceoutheader ioh, List <invoiceoutdetail> IODetails, string taxStr, string podocID)
        {
            try
            {
                Dictionary <string, string> companyInfo = getCompanyInformation();
                string[] pos        = ioh.TrackingNos.Split(';');
                int      b          = 0;
                int[]    a          = (from s in pos where int.TryParse(s, out b) select b).ToArray();
                int      min        = a.Min();
                string[] dates      = ioh.TrackingDates.Split(';');
                string   poStr      = "";
                string   billingAdd = "";
                //StringBuilder sb = new StringBuilder();
                for (int i = 0; i < pos.Length - 1; i++)
                {
                    string   custPOStr = POPIHeaderDB.getCustomerPOAndDateForInvoiceOut(Convert.ToInt32(pos[i]), Convert.ToDateTime(dates[i]), podocID);
                    string[] custPO    = custPOStr.Split(Main.delimiter1);
                    if (Convert.ToInt32(pos[i]) == min)
                    {
                        billingAdd = custPO[2];
                    }
                    poStr = poStr + custPO[0] + ", Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(custPO[1])) + "\n";
                }
                companybank   cb      = CompanyBankDB.getCompBankDetailForIOPrint(ioh.BankAcReference);
                CompanyDataDB datadb  = new CompanyDataDB();
                string        ieccode = "";
                cmpnydata     cdata   = datadb.getData("1").FirstOrDefault(c => c.DataID == "ImportExportCode");
                if (cdata != null)
                {
                    ieccode = cdata.DataValue;
                }

                customer custDetail        = CustomerDB.getCustomerDetailForPO(ioh.ConsigneeID);
                string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
                string   ConsgAdd          = "Consignee:\n" + custDetail.name + Main.delimiter2 + "\n" + ioh.DeliveryAddress + "\n";
                string   buyer             = "Buyer:\n" + custDetail.name + Main.delimiter2 + "\n" + billingAdd + "\n";
                if (custDetail.StateName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "Sate Name:" + custDetail.StateName;
                    buyer    = buyer + "Sate Name:" + custDetail.StateName;
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + " ,\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + " ,\nState Code:" + custDetail.StateCode;
                    }
                }
                else
                {
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + "\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + "\nState Code:" + custDetail.StateCode;
                    }
                }
                //string buyer =
                if (custDetail.OfficeName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
                    buyer    = buyer + "\nGST:" + custDetail.OfficeName;    // For GST Code
                }
                if (CustomerDB.getCustomerPANForInvoicePrint(ioh.ConsigneeID).Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nPAN:" + custDetail.OfficeName; // For PAN Code
                    buyer    = buyer + "\nPAN:" + custDetail.OfficeName;    // For PAN Code
                }

                string HeaderString = buyer +

                                      Main.delimiter1 + "Invoice No : " + ioh.InvoiceNo + ", Date : " + String.Format("{0:dd MMMM, yyyy}", ioh.InvoiceDate) +
                                      Main.delimiter1 + "Buyer Reference : " + poStr +
                                      Main.delimiter1 + "IE Code : " + ieccode +
                                      Main.delimiter1 + "AD Code : " + ioh.ADCode +
                                      Main.delimiter1 + "Mode of Dispatch : " + ioh.TransportationModeName +
                                      Main.delimiter1 + "Terms of Payment : " + ioh.TermsOfPayment +
                                      Main.delimiter1 + "Country of origin of goods : " + ioh.OriginCountryName +
                                      Main.delimiter1 + "Country of final destination : " + ioh.FinalDestinatoinCountryName + Main.delimiter1 +

                                      ConsgAdd +

                                      //////Main.delimiter1 + "Pre-Carriage by : " + ioh.PreCarriageTransportationName +
                                      //////Main.delimiter1 + "Place of Receipt by pre-carrier : " + ioh.PreCarrierReceiptPlace +
                                      Main.delimiter1 + "Port of Loading : " + ioh.ExitPort +
                                      Main.delimiter1 + "Port of Discharge : " + ioh.EntryPort +
                                      Main.delimiter1 + "Final Destination : " + ioh.FinalDestinationPlace +
                                      Main.delimiter1 + "Terms of Delivery : " + ioh.TermsOfDelivery +
                                      Main.delimiter1 + ioh.SpecialNote;


                string          footer1   = "Amount In Words\n\n";
                string          ColHeader = "SI No.;Description of Goods;HSN;Quantity;Unit;Unit Rate;Amount";
                CompanyDetailDB compDB    = new CompanyDetailDB();
                cmpnydetails    det       = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                string          compName  = "";
                if (det != null)
                {
                    compName = det.companyname;
                }
                string footer2 = "\n\nAccount Name : " + compName + "\nAccount No : " + cb.AccountCode + "\nAccount Type : " + cb.AccountType + "\nBank : " +
                                 cb.BankName + "\nBranch : " + cb.BranchName + "\nSWIFT Code : " + cb.CompanyID;
                string footer3 = "For Cellcomm Solutions Limited;Authorised Signatory";
                //string termsAndCond = getTCString(poh.TermsAndCondition);
                double totQuant        = 0.00;
                double totAmnt         = 0.00;
                int    n               = 1;
                string ColDetailString = "";
                var    count           = IODetails.Count();
                foreach (invoiceoutdetail iod in IODetails)
                {
                    if (n == count)
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price);
                    }
                    else
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price) + Main.delimiter2;
                    }
                    totQuant = totQuant + iod.Quantity;
                    totAmnt  = totAmnt + (iod.Quantity * iod.Price);
                    n++;
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (ioh.status == 0 && ioh.DocumentStatus < 99)
                {
                    sfd.FileName = ioh.DocumentID + "-Temp-" + ioh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = ioh.DocumentID + "-" + ioh.InvoiceNo;
                }

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                rec.Bottom = 10;
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font   font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;

                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell  cellAdd = new PdfPCell();
                Paragraph ourAddr = new Paragraph();
                if (det != null)
                {
                    //string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress, font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                    //ourAddr = new Paragraph(new Phrase(addr, font2));
                    //ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);

                Paragraph paragraph = new Paragraph(new Phrase("Commercial Invoice", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(7);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 3, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 16)
                    {
                    }
                    if (i == 0 || i == 9)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter2);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell = new PdfPCell(phr);
                        if (i == 9)
                        {
                            cell.Rowspan = 7 - 2;
                        }
                        else
                        {
                            cell.Rowspan = 8;
                        }
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan = 5;
                        table.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(7);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 5 || i == 6)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + ioh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 5 || j == 6)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                        }
                        else
                        {
                            if (j == 2)
                            {
                                if (str[j].Trim().Length == 0)
                                {
                                    pcell = new PdfPCell(new Phrase("", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 4)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight = 10;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;
                        table1.AddCell(pcell);
                    }
                }
                //-----------
                PdfPCell Temp = new PdfPCell(new Phrase(""));
                Temp.Border           = 0;
                Temp.BorderWidthLeft  = 0.01f;
                Temp.BorderWidthRight = 0.01f;

                double dd = 0;
                if (ioh.TaxAmount != 0)
                {
                    PdfPCell Temp1 = new PdfPCell(new Phrase(""));
                    Temp1.Border           = 0;
                    Temp1.BorderWidthTop   = 0.01f;
                    Temp1.BorderWidthLeft  = 0.01f;
                    Temp1.BorderWidthRight = 0.01f;
                    table1.AddCell(Temp1); //blank cell
                    table1.AddCell(Temp1);
                    PdfPCell cellCom = new PdfPCell(new Phrase("", font1));
                    cellCom.Colspan             = 4;
                    cellCom.Border              = 0;
                    cellCom.BorderWidthLeft     = 0.01f;
                    cellCom.BorderWidthRight    = 0.01f;
                    cellCom.BorderWidthTop      = 0.01f;
                    cellCom.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellCom);

                    PdfPCell cellTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt)), font2));
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellTot);


                    string[] tax = taxStr.Split(Main.delimiter2);
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        table1.AddCell(Temp); //blank cell
                        table1.AddCell(Temp);

                        string[] subtax     = tax[i].Split(Main.delimiter1);
                        PdfPCell cellinrtax = new PdfPCell(new Phrase(subtax[0], font1));
                        cellinrtax.Colspan             = 4;
                        cellinrtax.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        table1.AddCell(cellinrtax);

                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        pcell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(pcell2);
                    }
                    double taxAmRnd = Math.Round(ioh.TaxAmount, 0);
                    if (taxAmRnd != ioh.TaxAmount)
                    {
                        table1.AddCell(Temp); //blank cell
                        table1.AddCell(Temp);
                        PdfPCell cellTotTax = new PdfPCell(new Phrase("", font1));
                        cellTotTax.Colspan          = 4;
                        cellTotTax.Border           = 0;
                        cellTotTax.BorderWidthLeft  = 0.01f;
                        cellTotTax.BorderWidthRight = 0.01f;
                        //cellCom.BorderWidthTop = 0.01f;
                        cellTotTax.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(cellTotTax);

                        PdfPCell cellTotTaxValue = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt + ioh.TaxAmount)), font2));
                        cellTotTaxValue.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(cellTotTaxValue);
                    }
                }
                //-------------------



                double roundedAmt = Math.Round(ioh.InvoiceAmount, 0);
                double diffAmount = roundedAmt - ioh.InvoiceAmount;

                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 4;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    //table1.AddCell("");
                }


                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellRoundTot = new PdfPCell(new Phrase("Total", font1));
                cellRoundTot.Colspan             = 4;
                cellRoundTot.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                table1.AddCell(cellRoundTot);

                PdfPCell roundTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font2));
                roundTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(roundTot);

                string   total  = footer1 + NumberToString.convertFC(roundedAmt.ToString(), ioh.CurrencyID).Replace("INR", ioh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthBottom   = 0;
                fcell4.BorderWidthLeft     = 0;
                fcell4.BorderWidthTop      = 0;
                table1.AddCell(fcell4);

                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.BorderWidthTop   = 0;
                pcelNo.BorderWidthRight = 0;
                table1.AddCell(pcelNo);

                Phrase phrs = new Phrase();
                phrs.Add(new Chunk("Bank Details for Payment", font2));

                phrs.Add(new Chunk(footer2, font1));
                //PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));

                PdfPCell fcell2 = new PdfPCell(phrs);
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_MIDDLE;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthLeft     = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);

                PdfPCell pcelMid = new PdfPCell(new Phrase("", font1));
                pcelMid.Colspan = 3;
                //pcelMid.Border = 0;
                pcelMid.BorderWidthTop   = 0;
                pcelMid.BorderWidthLeft  = 0;
                pcelMid.BorderWidthRight = 0;
                table1.AddCell(pcelMid);

                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border            = 0;
                fcell3.Colspan           = 3;
                fcell3.BorderWidthTop    = 0f;
                fcell3.BorderWidthLeft   = 0f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));

                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 7;
                table1.AddCell(celSub);

                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);

                doc.Add(tableMain);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                doc.Close();

                if (ioh.status == 0 && ioh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Ejemplo n.º 37
0
    protected void GenerateReport(object sender, EventArgs e)
    {
        DataRow  dr         = GetData("SELECT * FROM User_Master where User_Id = " + ddlEmployees.SelectedItem.Value + "").Rows[0];;
        Document document   = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
        Font     NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL);

        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
            Phrase    phrase = null;
            PdfPCell  cell   = null;
            PdfPTable table  = null;
            // Color color = null;

            document.Open();

            //Header Table
            table             = new PdfPTable(2);
            table.TotalWidth  = 500f;
            table.LockedWidth = true;
            table.SetWidths(new float[] { 0.3f, 0.7f });

            //Company Logo
            cell = ImageCell("~/images/abc.jpg", 30f, PdfPCell.ALIGN_CENTER);
            table.AddCell(cell);

            //Company Name and Address
            phrase = new Phrase();
            phrase.Add(new Chunk("Microsoft Northwind Traders Company\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD)));
            phrase.Add(new Chunk("107, Park site,\n", FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            phrase.Add(new Chunk("Salt Lake Road,\n", FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            phrase.Add(new Chunk("Seattle, USA", FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
            cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
            table.AddCell(cell);

            //Separater Line
            // color = new Color(System.Drawing.ColorTranslator.FromHtml("#A9A9A9"));
            DrawLine(writer, 25f, document.Top - 79f, document.PageSize.Width - 25f, document.Top - 79f);
            DrawLine(writer, 25f, document.Top - 80f, document.PageSize.Width - 25f, document.Top - 80f);
            document.Add(table);

            table = new PdfPTable(2);
            table.HorizontalAlignment = Element.ALIGN_LEFT;
            table.SetWidths(new float[] { 0.3f, 1f });
            table.SpacingBefore = 20f;

            //Employee Details
            cell         = PhraseCell(new Phrase("Employee Record", FontFactory.GetFont("Arial", 12, Font.UNDERLINE)), PdfPCell.ALIGN_CENTER);
            cell.Colspan = 2;
            table.AddCell(cell);
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 30f;
            table.AddCell(cell);

            //Photo
            cell = ImageCell(string.Format("~/images/abc.jpg", dr["User_Id"]), 25f, PdfPCell.ALIGN_CENTER);
            table.AddCell(cell);

            //Name
            phrase = new Phrase();
            phrase.Add(new Chunk(dr["TitleOfCourtesy"] + " " + dr["FirstName"] + " " + dr["LastName"] + "\n", FontFactory.GetFont("Arial", 10, Font.BOLD)));
            phrase.Add(new Chunk("(" + dr["Title"].ToString() + ")", FontFactory.GetFont("Arial", 8, Font.BOLD)));
            cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
            cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(cell);
            document.Add(table);

            DrawLine(writer, 160f, 80f, 160f, 690f);
            DrawLine(writer, 115f, document.Top - 200f, document.PageSize.Width - 100f, document.Top - 200f);

            table = new PdfPTable(2);
            table.SetWidths(new float[] { 0.5f, 2f });
            table.TotalWidth          = 340f;
            table.LockedWidth         = true;
            table.SpacingBefore       = 20f;
            table.HorizontalAlignment = Element.ALIGN_RIGHT;

            //Employee Id
            table.AddCell(PhraseCell(new Phrase("Employee code:", FontFactory.GetFont("Arial", 8, Font.BOLD)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase("000" + dr["EmployeeId"], FontFactory.GetFont("Arial", 8, Font.NORMAL)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);


            //Address
            table.AddCell(PhraseCell(new Phrase("Address:", FontFactory.GetFont("Arial", 8, Font.BOLD)), PdfPCell.ALIGN_LEFT));
            phrase = new Phrase(new Chunk(dr["Address"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            phrase.Add(new Chunk(dr["City"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            phrase.Add(new Chunk(dr["Region"] + " " + dr["Country"] + " " + dr["PostalCode"], FontFactory.GetFont("Arial", 8, Font.NORMAL)));
            table.AddCell(PhraseCell(phrase, PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Date of Birth
            table.AddCell(PhraseCell(new Phrase("Date of Birth:", FontFactory.GetFont("Arial", 8, Font.BOLD)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(Convert.ToDateTime(dr["BirthDate"]).ToString("dd MMMM, yyyy"), FontFactory.GetFont("Arial", 8, Font.NORMAL)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Phone
            table.AddCell(PhraseCell(new Phrase("Phone Number:", FontFactory.GetFont("Arial", 8, Font.BOLD)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(dr["HomePhone"] + " Ext: " + dr["Extension"], FontFactory.GetFont("Arial", 8, Font.NORMAL)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Addtional Information
            table.AddCell(PhraseCell(new Phrase("Addtional Information:", FontFactory.GetFont("Arial", 8, Font.BOLD)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(dr["Notes"].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL)), PdfPCell.ALIGN_JUSTIFIED));
            document.Add(table);
            document.Close();
            byte[] bytes = memoryStream.ToArray();
            memoryStream.Close();
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=Employee.pdf");
            Response.ContentType = "application/pdf";
            Response.Buffer      = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
            Response.Close();
        }
    }
        public void GenerarPDF()
        {
            try
            {
                //instanciamos el documento
                Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
                MemoryStream PDFData = new MemoryStream();
                PdfWriter    writer  = PdfWriter.GetInstance(pdfDoc, PDFData);
                //tipos de fuentes que vamos a utilizar
                var       titleFont     = FontFactory.GetFont("Arial", 12, Font.BOLD);
                var       titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE);
                var       boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
                var       bodyFont      = FontFactory.GetFont("Arial", 8, Font.NORMAL);
                var       EmailFont     = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE);
                BaseColor TabelHeaderBackGroundColor = BaseColor.GRAY;

                Rectangle pageSize = writer.PageSize;
                // abrimos el documento para escribir
                pdfDoc.Open();
                //Agregamos los elementos para el documento

                #region Top table
                // creamos la tabla del encabezado
                PdfPTable headertable = new PdfPTable(3);
                headertable.HorizontalAlignment = 0;
                headertable.WidthPercentage     = 100;
                headertable.SetWidths(new float[] { 100f, 320f, 100f });  // Establecemos las dimensiones de las columnas
                headertable.DefaultCell.Border = Rectangle.NO_BORDER;
                //headertable.DefaultCell.Border = Rectangle.BOX; //para probar el codigo

                //colocamos el logo
                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/ImagenesSistema/logoGym.JPG"));
                logo.ScaleToFit(150, 65);

                {
                    PdfPCell pdfCelllogo = new PdfPCell(logo);
                    pdfCelllogo.Border            = Rectangle.NO_BORDER;
                    pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    pdfCelllogo.BorderWidthBottom = 1f;
                    headertable.AddCell(pdfCelllogo);
                }

                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border            = Rectangle.NO_BORDER;
                    middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    middlecell.BorderWidthBottom = 1f;
                    headertable.AddCell(middlecell);
                }

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("THE GYM", titleFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Salta, Argentina", bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Av. Entre Ríos 865", bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border            = Rectangle.NO_BORDER;
                    nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan           = 5;
                    nesthousing.PaddingBottom     = 10f;
                    headertable.AddCell(nesthousing);
                }


                PdfPTable Invoicetable = new PdfPTable(3);
                Invoicetable.HorizontalAlignment = 0;
                Invoicetable.WidthPercentage     = 100;
                Invoicetable.SetWidths(new float[] { 100f, 320f, 100f });  // establecemos el ancho de las columnas
                Invoicetable.DefaultCell.Border = Rectangle.NO_BORDER;

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Cliente:", bodyFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase(lblnombrecliente.Text, titleFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    //PdfPCell nextPostCell3 = new PdfPCell(new Phrase("DireccionProveedor", bodyFont));
                    //nextPostCell3.Border = Rectangle.NO_BORDER;
                    //nested.AddCell(nextPostCell3);
                    //PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont));
                    //nextPostCell4.Border = Rectangle.NO_BORDER;
                    //nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }

                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border = Rectangle.NO_BORDER;
                    //middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //middlecell.BorderWidthBottom = 1f;
                    Invoicetable.AddCell(middlecell);
                }


                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("COMPROBANTE DE PAGO", titleFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Fecha de Pago: " + DateTime.Now.ToShortDateString(), bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Fecha de Vigencia: " + DateTime.Now.AddDays(30).ToShortDateString(), bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }


                pdfDoc.Add(headertable);
                Invoicetable.PaddingTop = 10f;

                pdfDoc.Add(Invoicetable);
                #endregion

                #region Items Table
                //Create body table
                PdfPTable itemTable = new PdfPTable(3);

                itemTable.HorizontalAlignment = 0;
                itemTable.WidthPercentage     = 100;
                itemTable.SetWidths(new float[] { 5, 50, 10 });  // then set the column's __relative__ widths
                itemTable.SpacingAfter       = 40;
                itemTable.DefaultCell.Border = Rectangle.BOX;
                PdfPCell cell1 = new PdfPCell(new Phrase("Nº", boldTableFont));
                cell1.BackgroundColor     = TabelHeaderBackGroundColor;
                cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell1);
                PdfPCell cell2 = new PdfPCell(new Phrase("Plan", boldTableFont));
                cell2.BackgroundColor     = TabelHeaderBackGroundColor;
                cell2.HorizontalAlignment = 1;
                itemTable.AddCell(cell2);
                PdfPCell cell3 = new PdfPCell(new Phrase("Precio", boldTableFont));
                cell3.BackgroundColor     = TabelHeaderBackGroundColor;
                cell3.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell3);
                //PdfPCell cell4 = new PdfPCell(new Phrase("Precio por unidad", boldTableFont));
                //cell4.BackgroundColor = TabelHeaderBackGroundColor;
                //cell4.HorizontalAlignment = Element.ALIGN_CENTER;
                //itemTable.AddCell(cell4);
                //PdfPCell cell5 = new PdfPCell(new Phrase("TOTAL", boldTableFont));
                //cell5.BackgroundColor = TabelHeaderBackGroundColor;
                //cell5.HorizontalAlignment = Element.ALIGN_CENTER;
                //itemTable.AddCell(cell5);
                //foreach (DataRow row in dt.Rows)
                {
                    PdfPCell numberCell = new PdfPCell(new Phrase("1", bodyFont));
                    numberCell.HorizontalAlignment = 1;
                    numberCell.PaddingLeft         = 10f;
                    numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(numberCell);

                    var _phrase = new Phrase();
                    _phrase.Add(new Chunk(lblplan.Text, EmailFont));
                    PdfPCell descCell = new PdfPCell(_phrase);
                    descCell.HorizontalAlignment = 0;
                    descCell.PaddingLeft         = 10f;
                    descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(descCell);

                    PdfPCell qtyCell = new PdfPCell(new Phrase(lblmonto.Text, bodyFont));
                    qtyCell.HorizontalAlignment = 1;
                    qtyCell.PaddingLeft         = 10f;
                    qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(qtyCell);
                }
                //footer tabla
                PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));
                totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell1);
                PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));
                totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell2);
                PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));
                totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell3);
                //PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total", boldTableFont));
                //totalAmtStrCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                //totalAmtStrCell.HorizontalAlignment = 1;
                //itemTable.AddCell(totalAmtStrCell);
                //PdfPCell totalAmtCell = new PdfPCell(new Phrase(lblmonto.Text, boldTableFont));
                //totalAmtCell.HorizontalAlignment = 1;
                //itemTable.AddCell(totalAmtCell);

                PdfPCell cell = new PdfPCell(new Phrase("***NOTA: El plan tiene vigencia únicamente por el tiempo estipulado en este comprobante", bodyFont));
                cell.Colspan             = 5;
                cell.HorizontalAlignment = 1;
                itemTable.AddCell(cell);
                pdfDoc.Add(itemTable);
                #endregion

                PdfContentByte cb = new PdfContentByte(writer);


                BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);
                cb = new PdfContentByte(writer);
                cb = writer.DirectContent;
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(pageSize.GetLeft(120), 20);
                cb.ShowText("@TheGym todos los derechos reservados");
                cb.EndText();

                //Movemos el puntero y dibujamos una linea para separa el resto del documento del footer
                cb.MoveTo(40, pdfDoc.PageSize.GetBottom(50));
                cb.LineTo(pdfDoc.PageSize.Width - 40, pdfDoc.PageSize.GetBottom(50));
                cb.Stroke();

                //cerramos el PDF
                pdfDoc.Close();
                DownloadPDF(PDFData);
            }
            catch (Exception ex)
            {
                lblerrorimpresion.Text = ex.Message.ToString();
            }
        }