Esempio n. 1
0
 public static void CreateHardwareReport(string fileName, IEnumerable <HardwareCountReport> hardwares)
 {
     try
     {
         Document document = new Document(PageSize.A4, 72, 72, 72, 72);
         PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None));
         document.Open();
         document.Add(new Paragraph(Element.ALIGN_CENTER, "Hardware Report", new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)));
         document.Add(new Chunk(Chunk.NEWLINE));
         var table = new PdfPTable(3);
         table.SetTotalWidth(new float[] { 25f, 50f, 25f });
         table.WidthPercentage = 100;
         table.AddCell(new Phrase("Category"));
         table.AddCell(new Phrase("Hardware Model/Type"));
         table.AddCell(new Phrase("Total"));
         foreach (var hw in hardwares)
         {
             table.AddCell(new Phrase(hw.Category));
             table.AddCell(new Phrase(hw.Model));
             table.AddCell(new Phrase(hw.Count));
         }
         document.Add(table);
         document.Close();
     }
     catch (Exception x)
     {
         Log.Error("Error when creating report.", x);
     }
 }
Esempio n. 2
0
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            float[] width = { 20, 80 };

            PdfPTable table = new PdfPTable(2)
            {
                WidthPercentage = 100
            };

            table.SetTotalWidth(width);

            var img = Image.GetInstance(ReportCreator.GetDestinationFolder("social_services.jpg"));

            img.ScaleAbsolute(150, 97);

            table.AddCell(new PdfPCell(img)
            {
                BorderWidth = 0
            });

            var header = new Paragraph(
                16,
                "Social Service Manager",
                new Font(Font.FontFamily.TIMES_ROMAN, 38));

            table.AddCell(new PdfPCell(header)
            {
                BorderWidth         = 0,
                HorizontalAlignment = 1,
                VerticalAlignment   = Element.ALIGN_MIDDLE
            });

            document.Add(table);
        }
        /// <summary>
        /// Cria o cabeçalho de uma tabela no documento pdf
        /// </summary>
        /// <param name="document">objeto document</param>
        /// <param name="headerFields">lista de campos do cabeçalho</param>
        /// <param name="totalWidths">lista da largura de cada campo do cabeçalho</param>
        public static void AddTableHeader(Document document, string[] headerFields, float[] totalWidths)
        {
            int qtdeCells = headerFields.Count();

            PdfPTable table = new PdfPTable(qtdeCells);

            table.SetTotalWidth(totalWidths);

            PdfPCell[] cells = new PdfPCell[qtdeCells];

            string texto = "";

            for (int i = 0; i < qtdeCells; i++)
            {
                texto = headerFields[i].ToString();

                cells[i] = new PdfPCell(new Phrase(new Chunk(texto, FontFactory.GetFont("Arial", 8f, BaseColor.BLACK))));
                cells[i].BackgroundColor     = WebColors.GetRGBColor("#B5B5B5");
                cells[i].HorizontalAlignment = Element.ALIGN_LEFT;
                cells[i].Border = PdfPCell.NO_BORDER;

                table.AddCell(cells[i]);
            }

            table.WidthPercentage         = 96.7f;
            table.DefaultCell.FixedHeight = 15f;
            document.Add(table);

            //return table;
        }
Esempio n. 4
0
        private void Pdf_Header()
        {
            pdfDoc.Open();
            PdfPTable pdfHeader = new PdfPTable(2);

            pdfHeader.SetTotalWidth(new float[] { (pdfDoc.PageSize.Width * 0.5f), (pdfDoc.PageSize.Width * 0.5f) });
            pdfHeader.LockedWidth = true;

            PdfPCell _cell = new PdfPCell(new Paragraph("Company Name \nstreet. xyz 1\n00-901 Warsaw"));

            _cell.Border              = 0;
            _cell.PaddingLeft         = 10f;
            _cell.HorizontalAlignment = Element.ALIGN_LEFT;
            pdfHeader.AddCell(_cell);

            System.Drawing.Image logo = System.Drawing.Image.FromFile("./image/tire.png");
            Image iLogo = Image.GetInstance(logo, ImageFormat.Png);

            iLogo.ScaleAbsolute(75f, 75f);
            PdfPCell _cell_logo = new PdfPCell(iLogo);

            _cell_logo.Border = 0;
            _cell_logo.HorizontalAlignment = Element.ALIGN_RIGHT;
            pdfHeader.AddCell(_cell_logo);

            pdfDoc.Add(pdfHeader);
        }
Esempio n. 5
0
        public static PdfPTable CreateTable(float[] columnWidths, int border)
        {
            const string METHOD_NAME = "CreateTable";

            try {
                float sumWidths = 0;
                foreach (float w in columnWidths)
                {
                    sumWidths += w;
                }

                PdfPTable table = new PdfPTable(columnWidths.Length);
                table.DefaultCell.Border = border;

                if (Math.Round(sumWidths, 0) != 100)
                {
                    table.SetTotalWidth(columnWidths);
                    table.LockedWidth = true;
                }
                else
                {
                    table.SetWidths(columnWidths);
                    table.WidthPercentage = 100;
                }

                return(table);
            }
            catch (Exception ex) {
                ApplicationException aex = new ApplicationException(MOD_NAME + METHOD_NAME, ex);
                throw (aex);
            }
        }
        //set student table
        public void SetStudentTable(Students[] table)
        {
            doc.Open();
            PdfPTable myTable = new PdfPTable(2); //number of columns

            myTable.HorizontalAlignment = Element.ALIGN_CENTER;
            float[] widthCell = new float[2];
            widthCell[0] = 40;
            widthCell[1] = 60;
            myTable.SetTotalWidth(widthCell);
            PdfPCell myCell = new PdfPCell();

            for (int i = 0; i < table.Length; i++)
            {
                myCell.Phrase = new Phrase(table[i].FirstName.ToString());
                myTable.AddCell(myCell);
                myCell.Phrase = new Phrase(table[i].CityName.ToString());
                myTable.AddCell(myCell);
            }
            Paragraph pargraghTable = new Paragraph();

            pargraghTable.Add(myTable);
            pargraghTable.SpacingAfter = 15f;
            doc.Add(pargraghTable);
        }
        /// <summary>
        /// Add a card using name, organization and persontype provided
        /// meant to be used to add users not in the database
        /// will leave the sessions cell at the bottom of the badge empty
        /// </summary>
        private void AddCard(float absoluteX, float absoluteY, BadgeContentModel badge)
        {
            /* create a table to put the info in */
            PdfPTable table = new PdfPTable(6);

            table.SetTotalWidth(new float[] { CardWidth / 6, CardWidth / 6, CardWidth / 6, CardWidth / 6, CardWidth / 6, CardWidth / 6 });
            table.LockedWidth = true;

            AddPersonCell(table, badge.PersonType, badge.name);
            if (badge.PersonType == BadgePersonType.organizer)
            {
                AddOrganizatonCell(table, "Techday Organisatie");
            }
            else
            {
                AddOrganizatonCell(table, badge.organisation);
            }
            AddPhotoCell(table);
            AddEmptySessionsCells(table);
            /* write table at specified coordinates */
            table.WriteSelectedRows(0, -1, absoluteX, absoluteY + CardHeight, _contentByte);

            /* position image in the cell for them image and event name */
            Image image = Image.GetInstance(_referenceImage);

            image.SetAbsolutePosition(absoluteX, absoluteY + 22.0f);
            _document.Add(image);
        }
        public static PdfPTable RodapeRelatorioFrequencia(Document document, string periodoTotal, int qtdeCells, float[] totalWidths)
        {
            PdfPTable table = new PdfPTable(qtdeCells);

            table.SetTotalWidth(totalWidths);

            PdfPCell[] cells = new PdfPCell[qtdeCells];

            for (int i = 0; i < qtdeCells; i++)
            {
                string texto = "";

                if (i == 0)
                {
                    texto = "Total Mês";
                }
                else if (i == 3)
                {
                    texto = periodoTotal;
                }

                cells[i] = new PdfPCell(new Phrase(new Chunk(texto, FontFactory.GetFont("Arial", 8f, BaseColor.BLACK))));
                cells[i].BackgroundColor     = WebColors.GetRGBColor("#B5B5B5");
                cells[i].HorizontalAlignment = i == 0 ? Element.ALIGN_CENTER : Element.ALIGN_LEFT;
                cells[i].Border = PdfPCell.NO_BORDER;

                table.AddCell(cells[i]);
            }

            table.WidthPercentage         = 96.7f;
            table.DefaultCell.FixedHeight = 15f;
            document.Add(table);

            return(table);
        }
        //adding table to PDF file
        public void SetIntTable(int[,] table)
        {
            doc.Open();
            PdfPTable myTable = new PdfPTable(table.GetLength(0)); //number of columns

            myTable.HorizontalAlignment = Element.ALIGN_CENTER;
            float[] widthCell = new float[table.GetLength(0)];
            for (int i = 0; i < table.GetLength(0); i++)
            {
                widthCell[i] = (float)100 / table.GetLength(0); //getting equal % for any cell
            }
            myTable.SetTotalWidth(widthCell);
            PdfPCell myCell = new PdfPCell();

            for (int i = 0; i < table.GetLength(0); i++)
            {
                for (int j = 0; j < table.Length / table.GetLength(0); j++)
                {
                    myCell.Phrase = new Phrase(table[i, j].ToString());
                    myTable.AddCell(myCell);
                }
            }
            Paragraph pargraghTable = new Paragraph();

            pargraghTable.Add(myTable);
            pargraghTable.SpacingAfter = 15f;
            doc.Add(pargraghTable);
        }
Esempio n. 10
0
        public void CreateReasonPdf()
        {
            int   xDistance    = 72;
            int   yDistance    = 745;
            float rowMinHeight = 15f;
            float currentPos;

            //Laden der PDF-Vorlage in ein ByteArray. "Vorlagenordner" gibt die Bibliothek an und "vorlage" gibt den zu Namen der zu ladenden Datei an.
            reasonPdf = web.Folders[templateFolder].Files[templateReason].OpenBinary();
            //Initialisieren eines PDF-Readers von itextsharp (zum Lesen)
            using (PdfReader pdfReader = new PdfReader(reasonPdf))
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (PdfStamper pdfStamper = new PdfStamper(pdfReader, memoryStream, '\0', true))
                    {
                        //Mit pdfstamper.AcroFields werden alle Formularfelder des PDFs geladen
                        PdfContentByte canvas = pdfStamper.GetOverContent(1);
                        ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Begründung #" + requirementId), xDistance, yDistance - 30, 0);
                        PdfPTable pdfTable = new PdfPTable(1);
                        pdfTable.SetTotalWidth(new float[] { 450 });
                        pdfTable.DefaultCell.Border = Rectangle.NO_BORDER;
                        AddPDFCell(root.SelectSingleNode(xReason, nsmgr).ToString(), 0, 0, 0, 0, rowMinHeight, pdfTable);
                        currentPos = pdfTable.WriteSelectedRows(0, 2, 0, 2, xDistance, yDistance - 50, pdfStamper.GetOverContent(1));
                    }
                    //Bis zu dieser Stelle sind alle Editierungen des PDFS nur in einem MemoryStream vorhanden. Durch "ToArray()" wird dieser MemoryStream in ein ByteArray umgewandelt.
                    reasonPdf = memoryStream.ToArray();
                }
            }
        }
Esempio n. 11
0
        private static PdfPTable GetHeader(IStoreOrder order)
        {
            PdfPTable container = new PdfPTable(1)
            {
                SpacingBefore = 20
            };

            container.SetTotalWidth(new float[] { 420 });
            container.LockedWidth = true;

            PdfPTable info = new PdfPTable(2);

            info.AddCell(GetOrderInfo(order));
            info.AddCell(GetCustomerInfo(order));

            PdfPCell containerCell = new PdfPCell(info)
            {
                Border  = AllBorders(),
                Padding = 1
            };

            container.AddCell(containerCell);

            return(container);
        }
Esempio n. 12
0
        public byte[] GetPdfReport(int taxFormId)
        {
            #region doc setup
            _document = new Document();
            _document.SetPageSize(PageSize.Letter);
            _document.SetMargins(5f, 5f, 5f, 5f);
            _pdfTable.WidthPercentage     = 100;
            _pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
            _fontStyle = FontFactory.GetFont("Thomas", 8f, 1);
            PdfWriter docWriter = PdfWriter.GetInstance(_document, _memoryStream);
            _document.Open();
            float[] sizes = new float[_maxColumn];
            for (var i = 0; i < _maxColumn; i++)
            {
                if (i == 0)
                {
                    sizes[i] = 20;
                }
                else
                {
                    sizes[i] = 100;
                }
            }
            _pdfTable.SetTotalWidth(sizes);
            var t = _db.TaxForms.Find(taxFormId);
            #endregion
            this.ReportHeader(t.TaxYear, t.FilingStatus);
            this.EmptyRow(2);
            this.ReportBody(t);

            _pdfTable.HeaderRows = 2;
            _document.Add(_pdfTable);
            _document.Close();
            return(_memoryStream.ToArray());
        }
Esempio n. 13
0
        public static bool ExportToPDF(this DataTable dt, string fileName)
        {
            try
            {
                float        colWidth = 0;
                List <float> dtWidths = getDataTableWidth(dt);
                foreach (float w in dtWidths)
                {
                    colWidth += w;
                }

                Document pdfDoc = new Document();
                pdfDoc.SetMargins(10, 10, 10, 10);
                //iTextSharp.text.Font font = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 7);
                BaseFont             arial = BaseFont.CreateFont(@"C:\windows\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                iTextSharp.text.Font font  = new iTextSharp.text.Font(arial, 9, iTextSharp.text.Font.NORMAL);

                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(fileName, FileMode.OpenOrCreate));
                pdfDoc.SetPageSize(new iTextSharp.text.Rectangle(colWidth, colWidth));
                pdfDoc.Open();

                PdfPTable table = new PdfPTable(dt.Columns.Count);
                table.HorizontalAlignment = 0;
                table.SetTotalWidth(dtWidths.ToArray());
                table.SpacingBefore = 0;

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    PdfPCell cell = new PdfPCell();

                    cell.AddElement(new Phrase(FormatObject(dt.Columns[i].ColumnName, typeof(string)), font));
                    cell.NoWrap          = true;
                    cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                    table.AddCell(cell);
                }

                BaseColor odd = new BaseColor(249, 249, 249), even = new BaseColor(255, 255, 255);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        object   val  = dt.Rows[i][j];
                        PdfPCell cell = new PdfPCell(new Phrase(FormatObject(val, dt.Columns[j].DataType), font));
                        cell.BackgroundColor = i % 2 == 1 ? odd : even;
                        table.AddCell(cell);
                    }
                }

                pdfDoc.Add(table);
                pdfDoc.Close();
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                return(false);
            }
        }
Esempio n. 14
0
 private static PdfPTable CreatePdfTable(float[] columnWidths, HorizontalAlignment horizontalAlignment)
 {
   var pdfTable = new PdfPTable(columnWidths.Length);
   pdfTable.SetTotalWidth(columnWidths);
   pdfTable.LockedWidth = true;
   pdfTable.HorizontalAlignment = GetPdfElementAlignment(horizontalAlignment);
   return pdfTable;
 }
Esempio n. 15
0
        public void createReport(String FileName, String Title, String[] ColumnNames, List <Obj> data)
        {
            //открываем файл для работы
            FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);

            //создаем документ, задаем границы, связываем документ и поток
            iTextSharp.text.Document doc = new iTextSharp.text.Document();
            doc.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);
            PdfWriter writer = PdfWriter.GetInstance(doc, fs);

            doc.Open();
            BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            //вставляем заголовок
            var phraseTitle = new Phrase(Title,
                                         new iTextSharp.text.Font(baseFont, 16, iTextSharp.text.Font.BOLD));

            iTextSharp.text.Paragraph paragraph = new
                                                  iTextSharp.text.Paragraph(phraseTitle)
            {
                Alignment    = Element.ALIGN_CENTER,
                SpacingAfter = 12
            };
            doc.Add(paragraph);
            //вставляем таблицу, задаем количество столбцов, и ширину колонок
            PdfPTable table = new PdfPTable(2)
            {
                TotalWidth = 800F
            };

            table.SetTotalWidth(new float[] { 160, 140 });
            //вставляем шапку
            PdfPCell cell            = new PdfPCell();
            var      fontForCellBold = new iTextSharp.text.Font(baseFont, 10,
                                                                iTextSharp.text.Font.BOLD);

            table.AddCell(new PdfPCell(new Phrase(ColumnNames[0], fontForCellBold))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            table.AddCell(new PdfPCell(new Phrase(ColumnNames[1], fontForCellBold))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            //заполняем таблицу
            var fontForCells = new iTextSharp.text.Font(baseFont, 10);

            for (int i = 0; i < data.Count; i++)
            {
                cell = new PdfPCell(new Phrase(data[i].Name, fontForCells));
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(data[i].Enum, fontForCells));
                table.AddCell(cell);
            }
            //вставляем таблицу
            doc.Add(table);
            doc.Close();
        }
Esempio n. 16
0
        public static void InsertLine(PdfWriter writer, Document document, int heightY)
        {
            PdfPTable table = new PdfPTable(1);

            table.SetTotalWidth(new float[] { document.Right - 30 });
            table.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
            table.AddCell("");
            table.WriteSelectedRows(0, -1, 34, heightY, writer.DirectContentUnder);
        }
Esempio n. 17
0
        protected PdfPTable InitializePdfTableDDT()
        {
            float[]   columns = { 150f, 220f, 340f, 100f, 150f, 120f };
            PdfPTable table   = new PdfPTable(grdStampaDDT.Columns.Count)
            {
                WidthPercentage = 100
            };

            table.SetTotalWidth(columns);
            return(table);
        }
        public static PdfPTable InitializePdfTableDDT()
        {
            float[]   columns = { 150f, 380f, 65f, 140f, 85f };
            PdfPTable table   = new PdfPTable(5)
            {
                WidthPercentage = 100
            };

            table.SetTotalWidth(columns);
            return(table);
        }
Esempio n. 19
0
        public void ExportToPdf(DataTable dt, string path)
        {
            Document  document = new Document();
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(path + "\\Swype Pay General Transactions Report.pdf", FileMode.Create));

            document.Open();
            iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 10);
            PdfPTable            table = new PdfPTable(dt.Columns.Count);
            PdfPRow row = null;

            float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f };
            table.SetTotalWidth(widths);
            table.WidthPercentage = 100;
            int      iCol    = 0;
            string   colname = "";
            PdfPCell cell    = new PdfPCell(new Phrase("Products"));

            cell.Colspan = dt.Columns.Count;
            var map = new Dictionary <string, string>();

            map.Add("transactionItemId", "Product Name");
            map.Add("CategoryName", "Category Name");
            map.Add("categoryId", "Reference ID");
            map.Add("productId", "Transaction ID");
            map.Add("productName", "Product Name");
            map.Add("productPrice", "Product Price");
            map.Add("transactionDate", "Transaction Date");

            foreach (DataColumn c in dt.Columns)
            {
                try
                {
                    table.AddCell(new Phrase(map[c.ColumnName], font5));
                }
                catch (Exception notmapped) { table.AddCell(new Phrase(c.ColumnName, font5)); }
            }

            foreach (DataRow r in dt.Rows)
            {
                if (dt.Rows.Count > 0)
                {
                    table.AddCell(new Phrase(r[0].ToString(), font5));
                    table.AddCell(new Phrase(r[1].ToString(), font5));
                    table.AddCell(new Phrase(r[2].ToString(), font5));
                    table.AddCell(new Phrase(r[3].ToString(), font5));
                    table.AddCell(new Phrase(r[4].ToString(), font5));
                    table.AddCell(new Phrase(r[5].ToString(), font5));
                    table.AddCell(new Phrase(r[6].ToString(), font5));
                    table.AddCell(new Phrase(r[7].ToString(), font5));
                }
            }
            document.Add(table);
            document.Close();
        }
Esempio n. 20
0
        protected PdfPTable InitializePdfTableMatCant()
        {
            float[]   columns = { 170f, 130f, 170f, 160f, 140f, 240f, 110f, 150f, 130f };
            PdfPTable table   = new PdfPTable(grdStampaMateCant.Columns.Count)
            {
                WidthPercentage = 100
            };

            table.SetTotalWidth(columns);
            return(table);
        }
Esempio n. 21
0
        protected override void GenerateDataGraph()
        {
            PdfPTable dataGraphTable = PdfElementGenerator.createTable(new float[] { 1f });
            PdfPCell  cell           = dataGraphTable.Rows[0].GetCells()[0];

            cell.Padding     = 0;
            cell.FixedHeight = 310f;
            cell.Image       = this.getImage(this.device.ReportGraph);
            dataGraphTable.SetTotalWidth(new float[] { 475f });
            dataGraphTable.WriteSelectedRows(0, -1, 60f, 360, this.writer.DirectContent);
            //this.document.Add(PdfElementGenerator.createSectionFrameTable(dataGraphTable, false));
        }
Esempio n. 22
0
        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;
            var q        = DbUtil.Db.PeopleQuery(id);
            var q2       = from p in q
                           orderby p.Name2
                           select new
            {
                First = p.PreferredName,
                Last  = p.LastName,
                p.PeopleId,
                dob   = p.DOB,
                Phone = p.CellPhone.Length > 0 ? p.CellPhone : p.HomePhone,
                p.DoNotPublishPhones
            };

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);

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

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

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

            t.SetTotalWidth(cols);

            t.HorizontalAlignment = Element.ALIGN_CENTER;
            t.LockedWidth         = true;
            t.DefaultCell.Border  = PdfPCell.NO_BORDER;

            if (!q2.Any())
            {
                document.Add(new Phrase("no data"));
            }
            else
            {
                foreach (var m in q2)
                {
                    AddCell(t, m.First, m.Last, m.Phone, m.PeopleId, m.DoNotPublishPhones);
                }
            }

            t.CompleteRow();
            document.Add(t);

            document.Close();
        }
Esempio n. 23
0
        private PdfPTable Tabela()
        {
            //Tabela com 3 colunas
            PdfPTable table = new PdfPTable(3);

            table.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
            table.SpacingBefore = 300f;

            Font   f_tr = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 16);
            Phrase p1   = new Phrase("Tabela", f_tr);

            PdfPCell cell = new PdfPCell(p1);

            cell.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell.Colspan             = 4;
            cell.HorizontalAlignment = 1; // 0 = esquerda, 1 = centro, 2 = direita
            cell.Padding             = 10f;
            table.AddCell(cell);

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

            table.AddCell("Texto");
            table.AddCell("Texto");
            table.AddCell("Texto");

            table.AddCell("Texto");
            table.AddCell("Texto");
            table.AddCell("Texto");

            table.AddCell("Texto");
            table.AddCell("Texto");
            table.AddCell("Texto");

            table.AddCell("Texto");
            table.AddCell("Texto");
            table.AddCell("Texto");

            float[] totalWidth = new float[3];

            //1 polegada ou menos é multiplicada por 72 user units
            totalWidth[0] = 10; // 0,14" x 72 user units = 10
            totalWidth[1] = 15; // 0,21" x 72 user units = 15
            totalWidth[2] = 15;

            table.SetTotalWidth(totalWidth);            //Largura das 3 colunas
            table.DefaultCell.FixedHeight         = 30; //Altura das colunas
            table.DefaultCell.HorizontalAlignment = 1;

            return(table);
        }
Esempio n. 24
0
        public void WriteResultTable(Student student, Document doc, Dictionary <string, List <StudentSubjectScore> > data)
        {
            var mainTable = new PdfPTable(1);

            mainTable.SetTotalWidth(new float[] { 1000f });
            mainTable.HorizontalAlignment = Element.ALIGN_CENTER;
            mainTable.LockedWidth         = true;

            AddResultTable(student, doc, data);
            // Will Add Psychomotor here for term results

            // doc.Add(new Paragraph("Grade Scale: " + data.GradeInfo, new Font(Font.FontFamily.TIMES_ROMAN, 7f)));
        }
Esempio n. 25
0
        private PdfPTable LeggTilTabell(Paragraph Etikett, Paragraph Innhold, float Innrykk)
        {
            PdfPTable table = new PdfPTable(2);

            table.DefaultCell.Border = Rectangle.NO_BORDER;
            float[] CellWidth = new float[] { Innrykk + 23, 500 - Innrykk };
            table.SetTotalWidth(CellWidth);
            table.LockedWidth = true;
            table.AddCell(Etikett);
            table.AddCell(Innhold);

            return(table);
        }
        public static void Exp_SY3_SY4()
        {
            String tempname = getfilename();

            if (tempname == "")
            {
                return;
            }
            Document  document = new Document();
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(tempname, FileMode.Create));

            document.Open();
            table = new PdfPTable(3);//  设计试验3的表格总共有3列
            table.WidthPercentage = 82;
            table.SetTotalWidth(new float[] { 100f, 200f, 250f });
            ///表頭設計
            //添加段落,第二个参数指定使用fonttitle格式的字体,写入中文必须指定字体否则无法显示中文
            Paragraph Title = new Paragraph("3. 滑板控制装置首板收板时间试验记录", fonttitle);

            Title.SetAlignment("center");                       //设置居中
            document.Add(Title);                                //将标题段加入PDF文档中
                                                                //空一行
            nullb         = new Paragraph(" ", fonttitle2);
            nullb.Leading = 10;                                 //此数值用于调整空白大小0
            document.Add(nullb);
            DataTable dtb = Export_All_SY.DBQuery("SY3_Timer"); //表格3设计单独做一个函数

            table = Export_Table_Design.SY3_Table(table, dtb);
            Export_All_SY.DBDel("SY3_Timer");
            document.Add(table);
            //空一行
            nullb         = new Paragraph(" ", fonttitle2);
            nullb.Leading = 60;       //此数值用于调整空白大小0
            document.Add(nullb);
            table = new PdfPTable(5); //  设计试验4的表格总共有5列
            table.WidthPercentage = 82;
            table.SetTotalWidth(new float[] { 100f, 200f, 200f, 200f, 200f });
            Title = new Paragraph("4. 滑板控制装置连续收板(手动20次)试验记录", fonttitle);
            Title.SetAlignment("center");
            document.Add(Title);
            nullb         = new Paragraph(" ", fonttitle2);
            nullb.Leading = 10;                        //此数值用于调整空白大小0
            document.Add(nullb);
            dtb   = Export_All_SY.DBQuery("SY4_Lxsb"); //表格4设计单独做一个函数
            table = Export_Table_Design.SY4_Table(table, dtb);
            Export_All_SY.DBDel("SY4_Lxsb");
            document.Add(table); //將table放到pdf文件中
            Title = new Paragraph("         注:试验中“√”表示动作正常,“×”表示动作异常", fonttitle3);
            document.Add(Title); //将标题段加入PDF文档中
            document.Close();
        }
Esempio n. 27
0
        //code to create pdf
        private void pdf()
        {
            int       j, k, u;
            Document  doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Order From S.S.B Agencies.pdf", FileMode.Create));

            doc.Open();
            doc.AddAuthor("Gurudas");
            doc.AddCreator("Gurudas");
            Paragraph v = new Paragraph("Date : " + dateTimePicker1.Text + "\nOrder Number : " + bunifuCustomLabel20.Text);

            v.Alignment = 2;
            Paragraph op     = new Paragraph("From,\n  S.S.B Agencies, \n  12/3/62,\n  Skanda Prasad, \n  Convent Road, \n  Udupi-576101");
            Paragraph supadd = new Paragraph("\n\nTo,\n  " + comboBox2.Text + "\n  " + textBox1.Text);
            Paragraph salut  = new Paragraph("\nDear Sir/Madam,");
            Paragraph bod    = new Paragraph("\nPLEASE SEND US THE FOLLOWING ITEMS AS EARLY AS POSSIBLE IN THE FOLLOWING TRANSPORT " + comboBox3.Text + "\n\n");

            doc.Add(v);
            doc.Add(op);
            doc.Add(supadd);
            doc.Add(salut);
            doc.Add(bod);
            //adding table
            PdfPTable tab = new PdfPTable(dataGridView1.Columns.Count);

            tab.SetTotalWidth(new float[] { 50, 180, 80, 80, 80, 50, 80 });
            tab.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(0, 250, 154);
            tab.DefaultCell.BorderColor     = new iTextSharp.text.BaseColor(105, 105, 105);
            //adding header
            for (u = 0; u < dataGridView1.Columns.Count; u++)
            {
                tab.AddCell(new Phrase(dataGridView1.Columns[u].HeaderText));
            }
            //adding table body
            for (j = 0; j < dataGridView1.Rows.Count; j++)
            {
                for (k = 0; k < dataGridView1.Columns.Count; k++)
                {
                    if (dataGridView1[k, j].Value != null)
                    {
                        tab.AddCell(new Phrase(dataGridView1[k, j].Value.ToString()));
                    }
                }
            }
            doc.Add(tab);
            Paragraph reg = new Paragraph("\n\nThanking You,\nGURUDAS G,\nS.S.B Agencies.");

            doc.Add(reg);
            doc.Close();
            MessageBox.Show("PDF Generated Successfully!!!.");
        }
Esempio n. 28
0
        private void PrintOrderCars(OrderCarViewModel orderCar, Document doc, PdfPTable table)
        {
            var fontForCells    = new Font(baseFont, 10);
            var fontForCellBold = new Font(baseFont, 10, Font.BOLD);

            table.AddCell(new PdfPCell(new Phrase(orderCar.CarName, fontForCells))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            table.AddCell(new PdfPCell(new Phrase(orderCar.Amount.ToString(), fontForCells))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            var carDetails = context.CarDetails
                             .Where(rec => rec.CarId == orderCar.CarId)
                             .Select(rec => new CarDetailViewModel
            {
                Amount     = rec.Amount,
                DetailName = rec.Detail.DetailName,
                DetailId   = rec.DetailId
            }).ToList();

            var tableDetail = new PdfPTable(2);
            var cellDet     = new PdfPCell {
                Colspan = 2, HorizontalAlignment = Element.ALIGN_CENTER
            };

            tableDetail.AddCell(cellDet);
            tableDetail.SetTotalWidth(new float[] { 60, 40 });


            tableDetail.AddCell(new PdfPCell(new Phrase("Название", fontForCellBold))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            tableDetail.AddCell(new PdfPCell(new Phrase("Количество", fontForCellBold))
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            foreach (var carDetail in carDetails)
            {
                PrintCarDetails(carDetail, tableDetail);
            }

            table.AddCell(tableDetail);
        }
        public string GeneratePDF(Pedido pedido)
        {
            PedidoItemRepository repo = new PedidoItemRepository();

            listaPedItem = repo.ListPedItem(pedido.id);

            #region DefinirDiretorioEDoc
            var directory = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory, "W Venda - PDFs").ToString();
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var path = Path.Combine(directory, "Pedido " + pedido.id_codigo.ToString() + ", Cliente " + pedido.ds_cliente.ToString() + ".pdf");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var       fs       = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
            Document  document = new Document(PageSize.A4, 25, 25, 30, 30);
            PdfWriter writer   = PdfWriter.GetInstance(document, fs);
            document.Open();
            #endregion DefinirDiretorioEDoc

            document.Add(table0);

            Paragraph ParagrafoCapa = PopularCapaPedido(pedido);
            document.Add(ParagrafoCapa);

            HeaderItens();
            PopularListaPedidoItem();
            table.SetTotalWidth(new float[] { 10, 5, 5, 5, 5, 5 });
            document.Add(table);

            HeaderResumo();
            document.Add(table2);

            Paragraph ParagrafoResumo = PopularResumoPedido(pedido);
            document.Add(ParagrafoResumo);

            document.Close();
            writer.Close();
            fs.Close();

            return(path);
        }
Esempio n. 30
0
        public void SetCustomersTable(Customers[] cTable)  //add customers table
        {
            PdfPTable myTable = new PdfPTable(5);

            myTable.SpacingBefore = 20f;

            float[] widthCell = new float[5];
            for (int i = 0; i < 5; i++)
            {
                widthCell[i] = 33;
            }

            myTable.SetTotalWidth(widthCell);
            PdfPCell myCell = new PdfPCell();

            myCell.GrayFill            = 0.5f;
            myCell.BackgroundColor     = BaseColor.WHITE;
            myCell.FixedHeight         = 20;
            myCell.BorderColor         = BaseColor.DARK_GRAY;
            myCell.HorizontalAlignment = Element.ALIGN_CENTER;
            myCell.VerticalAlignment   = Element.ALIGN_CENTER;

            myCell.Phrase = new Phrase("ID");
            myTable.AddCell(myCell);
            myCell.Phrase = new Phrase("Customer ID");
            myTable.AddCell(myCell);
            myCell.Phrase = new Phrase("First Name");
            myTable.AddCell(myCell);
            myCell.Phrase = new Phrase("Last Name");
            myTable.AddCell(myCell);
            myCell.Phrase = new Phrase("Customer City");
            myTable.AddCell(myCell);

            for (int i = 0; i < cTable.Length; i++)
            {
                myCell.Phrase = new Phrase(cTable[i].Id.ToString());
                myTable.AddCell(myCell);
                myCell.Phrase = new Phrase(cTable[i].Ide.ToString());
                myTable.AddCell(myCell);
                myCell.Phrase = new Phrase(cTable[i].FName.ToString());
                myTable.AddCell(myCell);
                myCell.Phrase = new Phrase(cTable[i].LName.ToString());
                myTable.AddCell(myCell);
                myCell.Phrase = new Phrase(cTable[i].City.ToString());
                myTable.AddCell(myCell);
            }
            doc.Add(myTable);
        }