Exemplo n.º 1
0
        public virtual void HyphenSymbolTest01()
        {
            String      outFileName = destinationFolder + "hyphenSymbolTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_hyphenSymbolTest01.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);
            PdfFont     font        = PdfFontFactory.CreateFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, true);
            Style       style       = new Style();

            style.SetBorder(new SolidBorder(ColorConstants.BLACK, 1));
            style.SetHyphenation(new HyphenationConfig("en", "EN", 2, 2));
            style.SetFont(font);
            style.SetBackgroundColor(ColorConstants.RED);
            doc.Add(new Paragraph("tre\u2011").SetWidth(19).AddStyle(style));
            doc.Add(new Paragraph("tre\u2011\u2011").SetWidth(19).AddStyle(style));
            doc.Add(new Paragraph("r\u2011\u2011m").SetWidth(19).AddStyle(style));
            doc.Add(new Paragraph("r\u2011\u2011\u2011\u2011\u2011\u2011mmma").SetWidth(19).AddStyle(style));
            style.SetBackgroundColor(ColorConstants.BLUE);
            doc.Add(new Paragraph("tre\u2011\u2011").SetWidth(22).AddStyle(style));
            doc.Add(new Paragraph("tre\u2011\u2011m").SetWidth(22).AddStyle(style));
            doc.Add(new Paragraph("\n\n\n"));
            style.SetBackgroundColor(ColorConstants.GREEN);
            doc.Add(new Paragraph("e\u2011\u2011m\u2011ma").SetWidth(20).AddStyle(style));
            doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(20).AddStyle(style));
            doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(35).AddStyle(style));
            doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(40).AddStyle(style));
            style.SetBackgroundColor(ColorConstants.YELLOW);
            doc.Add(new Paragraph("ar\u2011ma").SetWidth(22).AddStyle(style));
            doc.Add(new Paragraph("ar\u2011ma").SetWidth(15).AddStyle(style));
            doc.Add(new Paragraph("ar\u2011").SetWidth(14).AddStyle(style));
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemplo n.º 2
0
        private Table CreateHeaders(Document document, Style headerStyle, string title)
        {
            Bitmap         bmpImage  = Properties.Resources.SICE;
            ImageConverter converter = new ImageConverter();

            Byte[]    byteImage = (byte[])converter.ConvertTo(bmpImage, typeof(byte[]));
            ImageData imageData = ImageDataFactory.Create(byteImage);

            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
            pdfImg.SetHeight(150);
            pdfImg.SetWidth(200);
            pdfImg.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
            document.Add(pdfImg);


            PdfFont font = PdfFontFactory.CreateFont(FontConstants.TIMES_BOLD);

            Style titleStyle = new Style();

            titleStyle.SetFont(font).SetFontSize(24);
            titleStyle.SetBold();
            document.Add(new Paragraph(title).AddStyle(titleStyle));


            Table table = new Table(37);

            table.AddHeaderCell("Document");
            table.AddHeaderCell("I 1").AddStyle(headerStyle);
            table.AddHeaderCell("I 3").AddStyle(headerStyle);
            table.AddHeaderCell("I 2").AddStyle(headerStyle);
            table.AddHeaderCell("I 4").AddStyle(headerStyle);
            table.AddHeaderCell("I 5").AddStyle(headerStyle);
            table.AddHeaderCell("I 6").AddStyle(headerStyle);
            table.AddHeaderCell("I 7").AddStyle(headerStyle);
            table.AddHeaderCell("I 8").AddStyle(headerStyle);
            table.AddHeaderCell("I 9").AddStyle(headerStyle);
            table.AddHeaderCell("I 10").AddStyle(headerStyle);
            table.AddHeaderCell("I 11").AddStyle(headerStyle);
            table.AddHeaderCell("I 12").AddStyle(headerStyle);
            table.AddHeaderCell("I 13").AddStyle(headerStyle);
            table.AddHeaderCell("I 14").AddStyle(headerStyle);
            table.AddHeaderCell("I 15").AddStyle(headerStyle);
            table.AddHeaderCell("I 16").AddStyle(headerStyle);
            table.AddHeaderCell("I 17").AddStyle(headerStyle);
            table.AddHeaderCell("Database").AddStyle(headerStyle);
            table.AddHeaderCell("I 1").AddStyle(headerStyle);
            table.AddHeaderCell("I 3").AddStyle(headerStyle);
            table.AddHeaderCell("I 2").AddStyle(headerStyle);
            table.AddHeaderCell("I 4").AddStyle(headerStyle);
            table.AddHeaderCell("I 5").AddStyle(headerStyle);
            table.AddHeaderCell("I 6").AddStyle(headerStyle);
            table.AddHeaderCell("I 7").AddStyle(headerStyle);
            table.AddHeaderCell("I 8").AddStyle(headerStyle);
            table.AddHeaderCell("I 9").AddStyle(headerStyle);
            table.AddHeaderCell("I 10").AddStyle(headerStyle);
            table.AddHeaderCell("I 11").AddStyle(headerStyle);
            table.AddHeaderCell("I 12").AddStyle(headerStyle);
            table.AddHeaderCell("I 13").AddStyle(headerStyle);
            table.AddHeaderCell("I 14").AddStyle(headerStyle);
            table.AddHeaderCell("I 15").AddStyle(headerStyle);
            table.AddHeaderCell("I 16").AddStyle(headerStyle);
            table.AddHeaderCell("I 17").AddStyle(headerStyle);
            table.AddHeaderCell("Result").AddStyle(headerStyle);
            return(table);
        }
Exemplo n.º 3
0
        private void ExportComparison(object title)
        {
            // Must have write permissions to the path folder
            FileInfo file = new FileInfo(titlePDF.ToString() + ".pdf");

            file.Delete();
            var fileStream = file.Create();

            fileStream.Close();
            PdfDocument pdfdoc      = new PdfDocument(new PdfWriter(file));
            PdfFont     font        = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);
            PdfFont     cellFont    = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     OKFont      = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     NOKFont     = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            Style       headerStyle = new Style();

            headerStyle.SetFont(font).SetFontSize(11);
            headerStyle.SetBold();
            Style cellStyle = new Style();

            cellStyle.SetFont(cellFont).SetFontSize(10);
            Style OKStyle = new Style();

            OKStyle.SetFont(OKFont).SetFontSize(10);
            OKStyle.SetFontColor(ColorConstants.GREEN, 1);
            Style NOKStyle = new Style();

            NOKStyle.SetFont(NOKFont).SetFontSize(10);
            NOKStyle.SetFontColor(ColorConstants.RED, 1);

            pdfdoc.SetDefaultPageSize(PageSize.A2.Rotate());
            pdfdoc.SetTagged();
            using (Document document = new Document(pdfdoc))
            {
                iText.Layout.Element.Cell cell;
                Table table = CreateHeaders(document, headerStyle, title.ToString());
                for (int i = 0; i < documentationImportList.Count; i++)
                {
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(documentationImportList[i].deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);
                    foreach (string iconName in documentationImportList[i].iconNames)
                    {
                        // documentationImportList[i].iconNames;
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }

                    for (int j = documentationImportList[i].iconNames.Count; j < 17; j++)
                    {
                        table.AddCell("");
                    }

                    DeviceIconGroup databaseItem = databaseImportList.Find(x => x.deviceName.Equals(documentationImportList[i].deviceName));
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(databaseItem.deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);//.AddStyle(cellStyle);


                    foreach (string iconName in databaseItem.iconNames)
                    {
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            // documentationImportList[i].iconNames;
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }


                    for (int j = 19 + databaseItem.iconNames.Count; j < 36; j++)
                    {
                        table.AddCell("");
                    }

                    if (documentationImportList[i].IsEqualTo(databaseItem))
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("OK")).AddStyle(OKStyle);
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("NOK")).AddStyle(NOKStyle);
                        table.AddCell(cell);
                    }

                    this.Dispatcher.Invoke(
                        new UpdatePgBar(this.updatePgBar),
                        new object[] { (double.Parse(i.ToString()) / double.Parse(documentationImportList.Count().ToString())) * 100 }
                        );
                }

                //Create table
                document.Add(table);


                this.Dispatcher.Invoke(
                    new FinishReading(EnableWindowOptions),
                    new object[] { }
                    );
            }
        }