예제 #1
0
        private void GenerateReportTableHeaders(ref Document doc, out PdfPTable stTable)
        {
            // Table creation
            stTable = new PdfPTable(6);
            stTable.DefaultCell.Border = 1;
            stTable.WidthPercentage    = 100;
            stTable.SpacingBefore      = 70f;
            stTable.TotalWidth         = 500f;
            stTable.SetWidths(new float[] { 5f, 60f, 20f, 20f, 15f, 15f });
            stTable.LockedWidth = true;
            // End of table creation

            // Header
            Font           thFont     = new Font(bFont, 13, Font.BOLD, BaseColor.BLACK);
            PdfPHeaderCell headerCell = new PdfPHeaderCell();

            headerCell.AddElement(new Paragraph("№", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            headerCell = new PdfPHeaderCell();
            headerCell.AddElement(new Paragraph("ФИО", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            headerCell = new PdfPHeaderCell();
            headerCell.AddElement(new Paragraph("Получено баллов за семестр", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            headerCell = new PdfPHeaderCell();
            headerCell.AddElement(new Paragraph("Получено баллов за экзамен", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            headerCell = new PdfPHeaderCell();
            headerCell.AddElement(new Paragraph("Всего баллов", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            headerCell = new PdfPHeaderCell();
            headerCell.AddElement(new Paragraph("Итоговая оценка", thFont)
            {
                Alignment = Element.ALIGN_CENTER
            });
            stTable.AddCell(headerCell);
            // Header end
        }
예제 #2
0
        public static void CreatePdfTable()
        {
            //first column is 3 times longer than the others
            var widths = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
            var table  = new PdfPTable(widths);

            table.DefaultCell.Border            = PdfPCell.NO_BORDER;
            table.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER;

            var hdr = new PdfPHeaderCell();

            hdr.Colspan = widths.Length;
            hdr.AddElement(new Paragraph("SUMMARY REPORT"));
            table.AddCell(hdr);

            table.AddCell("");

            var cell = new PdfPCell();

            cell.Border = PdfPCell.NO_BORDER;

            var p1 = new Paragraph("Mar");

            p1.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(p1);

            var p2 = new Paragraph("2018");

            p1.Alignment = Element.ALIGN_CENTER;
            cell.AddElement(p2);

            table.AddCell(cell);

            table.AddCell("Apr 2017");
            table.AddCell("May 2016");
            table.AddCell("Mar 2015");
            table.AddCell("Jul 2014");

            table.AddCell("Some row name");
            table.AddCell("1.1");
            table.AddCell("1.2");
            table.AddCell("1.3");
            table.AddCell("1.4");
            table.AddCell("1.5");

            var document  = new Document(PageSize.LETTER);
            var pdfWriter = PdfWriter.GetInstance(document, new FileStream(@"C:\Projects\31g\trunk\temp\pdf\myPdfTable.pdf", FileMode.OpenOrCreate));

            document.Open();
            document.Add(table);
            document.Close();
            pdfWriter.Close();
        }
예제 #3
0
        /// <summary>
        /// 表格写入
        /// </summary>
        /// <param name="document">itext Document对象</param>
        /// <param name="content">表格</param>
        /// <returns>itext Document对象</returns>
        public static iTextSharp.text.Document Write(this iTextSharp.text.Document document, TableContent content)
        {
            if (content == null || content.Content == null)
            {
                return(document);
            }

            var     table = new PdfPTable(content.RelativeWidths.ToArray());
            PdfPRow row;
            var     cells = new List <PdfPCell>();

            if (content.ShowHeader)
            {
                var headcells = new List <PdfPHeaderCell>();
                foreach (DataColumn column in content.Content.Columns)
                {
                    var cell = new PdfPHeaderCell();
                    cell.AddElement(new Phrase(column.Caption, content.HeaderFont));
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                    cell.Padding             = content.HeaderFont.Size * 0.4f;
                    headcells.Add(cell);
                }

                row = new PdfPRow(headcells.ConvertAll(p => (PdfPCell)p).ToArray());
                table.Rows.Add(row);
            }

            foreach (DataRow dr in content.Content.Rows)
            {
                cells.Clear();
                cells.AddRange(from DataColumn column in content.Content.Columns
                               select new PdfPCell(new Phrase(dr[column.ColumnName] == null ? "" : dr[column.ColumnName].ToString(), content.ContentFont))
                {
                    HorizontalAlignment = Element.ALIGN_CENTER,
                    VerticalAlignment   = Element.ALIGN_MIDDLE,
                    Padding             = content.ContentFont.Size * 0.3f,
                });

                row = new PdfPRow(cells.ToArray());
                table.Rows.Add(row);
            }

            document.Add(table);
            return(document);
        }
예제 #4
0
        public byte[] GetPDFDocument()
        {
            byte[] stream;
            using (MemoryStream output = new MemoryStream())
            {
                BaseFont baseFont    = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                Font     font        = new iTextSharp.text.Font(baseFont, 12);
                Font     fontCapital = new iTextSharp.text.Font(baseFont, 16, Font.BOLD);

                Document  doc    = new Document();
                PdfWriter writer = PdfWriter.GetInstance(doc, output);
                doc.Open();
                doc.Add(new Paragraph("\n", font));
                PdfPTable table = new PdfPTable(1);
                table.DefaultCell.Border = PdfPCell.NO_BORDER;
                //table.DefaultCell.VerticalAlignment = Element.ALIGN_RIGHT;
                table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(new Phrase("АКТ № " + _NumberExp.ToString(), fontCapital));
                table.AddCell(new Phrase("ТЕХНИЧЕСКОЙ ЭКСПЕРТИЗЫ", fontCapital));
                table.AddCell(new Phrase("к обращению ID " + _RequestId, fontCapital));

                doc.Add(table);
                doc.Add(new Chunk("\n"));
                //doc.Add(new Chunk("Настоящий акт составил - ",font));
                doc.Add(new Chunk("\n"));
                PdfPTable tableDate = new PdfPTable(1);
                tableDate.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                tableDate.DefaultCell.Border = PdfPCell.NO_BORDER;
                tableDate.AddCell(new Phrase("Дата: " + _DateExp, font));
                doc.Add(tableDate);

                doc.Add(new Chunk("\n"));
                doc.Add(new Chunk("Представителем ООО «Сбербанк-Сервис» прозведены работы по технической экспертизе следующего технического средства:", font));
                doc.Add(new Chunk("\n"));


                // Таблица с данными по оборудованию
                PdfPTable mainTable = new PdfPTable(5);
                mainTable.WidthPercentage = 100;
                mainTable.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                mainTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;



                PdfPHeaderCell headerCell0 = new PdfPHeaderCell();
                headerCell0.AddElement(new Phrase("Наименование", font));
                mainTable.AddCell(headerCell0);

                PdfPHeaderCell headerCell1 = new PdfPHeaderCell();
                headerCell1.AddElement(new Phrase("Инвентарный номер", font));
                mainTable.AddCell(headerCell1);

                PdfPHeaderCell headerCell2 = new PdfPHeaderCell();
                headerCell2.AddElement(new Phrase("Серийный номер", font));
                mainTable.AddCell(headerCell2);

                PdfPHeaderCell headerCell3 = new PdfPHeaderCell();
                headerCell3.AddElement(new Phrase("Год ввода в экспл.", font));
                mainTable.AddCell(headerCell3);

                PdfPHeaderCell headerCell4 = new PdfPHeaderCell();
                headerCell4.AddElement(new Phrase("Техническое состояние устройства (описание неисправности)", font));

                mainTable.AddCell(headerCell4);

                mainTable.AddCell(new Phrase(_Name, font));
                mainTable.AddCell(new Phrase(_InventoryNumber, font));
                mainTable.AddCell(new Phrase(_SerialNumber, font));
                mainTable.AddCell(new Phrase(_StartupDate, font));
                mainTable.AddCell(new Phrase(_Reason, font));

                doc.Add(mainTable);

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

                // Таблица о результате с решением
                PdfPTable conclusionTable = new PdfPTable(3);
                conclusionTable.WidthPercentage = 100;
                conclusionTable.DefaultCell.VerticalAlignment   = Element.ALIGN_CENTER;
                conclusionTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;

                PdfPCell headerCell10 = new PdfPCell();
                headerCell10.AddElement(new Phrase("Заключение:", font));
                conclusionTable.AddCell(headerCell10);

                PdfPCell headerCell11 = new PdfPCell(new Phrase("Да", font));
                headerCell11.HorizontalAlignment = Element.ALIGN_CENTER;
                conclusionTable.AddCell(headerCell11);

                PdfPCell headerCell12 = new PdfPCell(new Phrase("Нет", font));
                headerCell12.HorizontalAlignment = Element.ALIGN_CENTER;
                conclusionTable.AddCell(headerCell12);

                conclusionTable.AddCell(new Phrase("Оборудование исправно", font));

                PdfPCell cellYesNo = new PdfPCell(new Phrase("+", font));
                cellYesNo.HorizontalAlignment = Element.ALIGN_CENTER;

                if ((_IsServiceableEquipment ?? false))
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }

                conclusionTable.AddCell(new Phrase("Необходим ремонт по гарантии", font));
                if (_IsWarrantyRepair ?? false)
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }

                conclusionTable.AddCell(new Phrase("Возможен ремонт ООО «Сбербанк-Сервис»", font));
                if (_IsOrganizationRepair ?? false)
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }

                conclusionTable.AddCell(new Phrase("Требуется поставка запчастей", font));
                if (_IsPartsSupply ?? false)
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }

                conclusionTable.AddCell(new Phrase("Пригодно к эксплуатации", font));
                if (_IsServiceable ?? false)
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }

                conclusionTable.AddCell(new Phrase("Рекомендуется к списанию", font));
                if (_IsForWriteoff ?? false)
                {
                    conclusionTable.AddCell(cellYesNo);
                    conclusionTable.AddCell(new Phrase("", font));
                }
                else
                {
                    conclusionTable.AddCell(new Phrase("", font));
                    conclusionTable.AddCell(cellYesNo);
                }


                doc.Add(conclusionTable);

                //picture.ScaleToFit(50f, 50f);
                //picture.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP;
                //picture.IndentationLeft = 3f;
                //picture.SpacingAfter = 3f;
                //picture.BorderWidthTop = 6f;
                //doc.Add(picture);

                doc.Add(new Chunk("\n"));
                doc.Add(new Paragraph("Дополнительные рекомендации: " + _Conclusion, font));


                doc.Add(new Paragraph("Представитель ООО «Сбербанк-Сервис»:", font));
                //doc.Add(new Chunk("\n"));

                // Таблица для выполнившего акт и его подписи
                // Ячейка для подписи
                PdfPTable tableSign = new PdfPTable(2);
                tableSign.WidthPercentage                 = 100;
                tableSign.DefaultCell.Border              = PdfPCell.NO_BORDER;
                tableSign.DefaultCell.VerticalAlignment   = Element.ALIGN_BOTTOM;
                tableSign.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                // Ячейка для ФИО и должности
                PdfPCell cellText = new PdfPCell(new Phrase(_Staff, font));
                cellText.NoWrap              = true;
                cellText.BorderColor         = BaseColor.WHITE;
                cellText.HorizontalAlignment = Element.ALIGN_LEFT;
                cellText.VerticalAlignment   = Element.ALIGN_BOTTOM;
                tableSign.AddCell(cellText);
                PdfPCell cellSign;
                if (_ImgData != null)
                {
                    Image picture = Image.GetInstance(_ImgData);
                    picture.ScaleToFit(100f, 100f);
                    picture.BorderWidthTop = 0f;
                    //picture.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP;
                    cellSign = new PdfPCell(picture);
                }
                else
                {
                    cellSign = new PdfPCell();
                }


                cellSign.BorderColor         = BaseColor.WHITE;
                cellSign.HorizontalAlignment = Element.ALIGN_CENTER;
                tableSign.AddCell(new PdfPCell(cellSign));
                doc.Add(tableSign);

                doc.Add(new Paragraph("Управления по сервису Уральского Банка ООО «Сбербанк-Сервис»", font));
                doc.Add(new Paragraph("Работы приняты:", font));
                if (!string.IsNullOrWhiteSpace(_Staff2))
                {
                    doc.Add(new Paragraph(_Staff2, font));
                }
                else
                {
                    doc.Add(new Paragraph("_____________________________________________________________________ "));
                }



                doc.Close();
                stream = output.ToArray();
            }

            return(stream);
        }
        protected PdfPTable GetDailyEventsFor(DayOfWeek dayOfWeek)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                PdfPTable table = new PdfPTable(3);

                PdfPHeaderCell headerCell = new PdfPHeaderCell()
                {
                    Colspan = 3,
                    Border  = 0,
                    Padding = 1f
                };
                Paragraph hp = new Paragraph(WeekendDates.GetDayOfWeek(dayOfWeek).ToLongDateString(), HeaderFont);
                headerCell.AddElement(hp);
                table.AddCell(headerCell);

                Weekend weekend = db.Weekends.Where(w => w.id == WeekendId).Single();

                List <WeekendTableItem> things = new List <WeekendTableItem>();
                foreach (WeekendActivity activity in weekend.WeekendActivities.Where(act => !act.IsDeleted && act.DateAndTime.DayOfWeek == dayOfWeek).OrderBy(act => act.DateAndTime).ToList())
                {
                    things.Add(new WeekendTableItem(activity));
                }

                foreach (WeekendDuty duty in weekend.WeekendDuties.Where(d => !d.IsDeleted && d.DateAndTime.DayOfWeek == dayOfWeek).OrderBy(d => d.DateAndTime).ToList())
                {
                    things.Add(new WeekendTableItem(duty));
                }


                foreach (WeekendTableItem activity in things.OrderBy(act => act.DateAndTime))
                {
                    PdfPCell timeCell = new PdfPCell()
                    {
                        Border = 0, Padding = 1f
                    };;
                    PdfPCell actCell = new PdfPCell()
                    {
                        Border = 0, Padding = 1f
                    };;
                    PdfPCell adsCell = new PdfPCell()
                    {
                        Border = 0, Padding = 1f
                    };;

                    Paragraph time = new Paragraph(String.Format("{0}{1}", activity.DateAndTime.Hour == 0 ? "All Day" : activity.DateAndTime.ToShortTimeString(),
                                                                 activity.Duration == 0 ? "" : " ~ " + activity.DateAndTime.AddMinutes(activity.Duration).ToShortTimeString()), PageFont);
                    timeCell.AddElement(time);
                    table.AddCell(timeCell);

                    Paragraph actP = new Paragraph(String.Format("{0}{1}", activity.Name,
                                                                 activity.Notes.Equals("") ? "" : String.Format(" ({0})", activity.Notes)), PageFont);
                    actCell.AddElement(actP);
                    table.AddCell(actCell);

                    if (activity.Adults.Count < 4)
                    {
                        foreach (Faculty adult in activity.Adults)
                        {
                            Paragraph adp = new Paragraph(String.Format("{0} {1}", adult.FirstName, adult.LastName), PageFont);
                            adsCell.AddElement(adp);
                        }
                    }

                    else
                    {
                        Paragraph adp = new Paragraph("All Team", PageFont);
                        adsCell.AddElement(adp);
                    }
                    table.AddCell(adsCell);
                }

                return(table);
            }
        }