Example #1
0
        public virtual void PrecisionTest01()
        {
            String      outFileName      = destinationFolder + "precisionTest01.pdf";
            String      cmpFileName      = sourceFolder + "cmp_precisionTest01.pdf";
            String      imageFileName    = sourceFolder + "LOGO_PDF_77.jpg";
            PdfDocument pdfDoc           = new PdfDocument(new PdfWriter(outFileName));
            PdfPage     page             = pdfDoc.AddNewPage();
            PdfCanvas   currentPdfCanvas = new PdfCanvas(page);
            Rectangle   rc = new Rectangle(56.6929131f, 649.13385f, 481.889771f, 136.062988f);

            iText.Layout.Canvas canvas = new iText.Layout.Canvas(currentPdfCanvas, rc);
            Table table = new Table(UnitValue.CreatePointArray(new float[] { 158f }));

            table.SetTextAlignment(TextAlignment.LEFT);
            iText.Layout.Element.Image logoImage = new iText.Layout.Element.Image(ImageDataFactory.Create(imageFileName
                                                                                                          ));
            Paragraph p    = new Paragraph().Add(logoImage.SetAutoScale(true));
            Cell      cell = new Cell();

            cell.SetKeepTogether(true);
            cell.Add(p);
            table.AddCell(cell.SetHeight(85.03937f).SetVerticalAlignment(VerticalAlignment.TOP).SetPadding(0));
            canvas.Add(table);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #2
0
        static void imgStyle(Image img, ImageSelection image)
        {
            var directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(image.getPath());


            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                {
                    if (tag.Name == "Orientation" && directory.Name == "Exif IFD0")
                    {
                        OrientationChecking.rotateChecking(ref img, tag.Description, ref image, setOrientation);
                        break;
                    }
                }
                if (directory.HasError)
                {
                    foreach (var error in directory.Errors)
                    {
                        Console.WriteLine($"ERROR: {error}");
                    }
                }
            }



            //img.SetHorizontalAlignment(HorizontalAlignment.CENTER);
            //img.SetAutoScale(true);
        }
Example #3
0
        public virtual void ImageInTableTest02()
        {
            String      outFileName = destinationFolder + "imageInTableTest02.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageInTableTest02.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDoc);

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
                                                                                                    ));
            Table table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetWidth(UnitValue.CreatePercentValue
                                                                                                         (100)).SetFixedLayout();

            table.SetMaxHeight(300);
            table.SetBorder(new SolidBorder(ColorConstants.BLUE, 10));
            Cell c = new Cell().Add(img.SetHeight(500));

            table.AddCell("First cell");
            table.AddCell(c);
            document.Add(table);
            document.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().AddCell("Is my occupied area right?"
                                                                                                   ));
            document.Add(new AreaBreak());
            table.SetMinHeight(150);
            document.Add(table);
            document.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().AddCell("Is my occupied area right?"
                                                                                                   ));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #4
0
        public virtual void ImageWithMinMaxHeightTest01()
        {
            String          outFileName = destinationFolder + "imageWithMinMaxHeightTest01.pdf";
            String          cmpFileName = sourceFolder + "cmp_imageWithMinMaxHeightTest01.pdf";
            PdfWriter       writer      = new PdfWriter(outFileName);
            PdfDocument     pdfDoc      = new PdfDocument(writer);
            Document        doc         = new Document(pdfDoc);
            PdfImageXObject xObject     = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "itis.jpg"));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100);
            doc.Add(new Paragraph(new Text("Default height")));
            doc.Add(image);
            doc.Add(new Paragraph(new Text("Min height bigger than default")));
            doc.Add(image.SetMinHeight(200));
            doc.Add(new Paragraph(new Text("Min height smaller than default")));
            image.DeleteOwnProperty(Property.MIN_HEIGHT);
            doc.Add(image.SetMinHeight(10));
            doc.Add(new Paragraph(new Text("Max height bigger than default")));
            image.DeleteOwnProperty(Property.MIN_HEIGHT);
            doc.Add(image.SetMaxHeight(250));
            doc.Add(new Paragraph(new Text("Max height smaller than default")));
            image.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(image.SetMaxHeight(30));
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #5
0
        public virtual void ImageTest21()
        {
            String      outFileName = destinationFolder + "imageTest21.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest21.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
                                                                                                      ));
            image.SetAutoScaleHeight(true);
            float[] colWidths = new float[] { 1f, 1f };
            Table   container = new Table(UnitValue.CreatePercentArray(colWidths));

            container.AddCell("Text");
            container.AddCell("autoscaling image, height only");
            int       textIterations = 50;
            Paragraph p = new Paragraph();

            for (int i = 0; i < textIterations; i++)
            {
                p.Add("Text will wrap");
            }
            container.AddCell(p);
            container.AddCell(image);
            doc.Add(container);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #6
0
        public virtual void FlushOnDrawTest()
        {
            String      outFileName = destinationFolder + "flushOnDrawTest.pdf";
            String      cmpFileName = sourceFolder + "cmp_flushOnDrawTest.pdf";
            int         rowCount    = 60;
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    document    = new Document(pdfDoc);

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
                                                                                                    ));
            Table table = new Table(UnitValue.CreatePercentArray(8)).UseAllAvailableWidth();

            for (int k = 0; k < rowCount; k++)
            {
                for (int j = 0; j < 7; j++)
                {
                    table.AddCell("Hello");
                }
                Cell c = new Cell().Add(img.SetWidth(UnitValue.CreatePercentValue(50)));
                table.AddCell(c);
            }
            document.Add(table);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #7
0
        private void ManipulatePdf(PdfDocument pdfDocument, bool setTagged)
        {
            Document document = new Document(pdfDocument);

            if (setTagged)
            {
                pdfDocument.SetTagged();
            }
            pdfDocument.GetCatalog().SetLang(new PdfString("en-US"));
            pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
            PdfDocumentInfo info = pdfDocument.GetDocumentInfo();

            info.SetTitle("iText7 PDF/UA test");
            PdfFont   font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
            Paragraph p    = new Paragraph();

            p.SetFont(font);
            p.Add(new Text("The quick brown "));
            iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX));
            foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox");
            p.Add(foxImage);
            p.Add(" jumps over the lazy ");
            iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
            dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog");
            p.Add(dogImage);
            document.Add(p);
            document.Close();
        }
Example #8
0
        public virtual void ImageTest17()
        {
            String      outFileName = destinationFolder + "imageTest17.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest17.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);

            iText.Layout.Element.Image image1 = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder +
                                                                                                       "Desert.jpg"));
            image1.SetBorder(new SolidBorder(ColorConstants.BLUE, 5));
            iText.Layout.Element.Image image2 = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder +
                                                                                                       "scarf.jpg"));
            image2.SetBorder(new SolidBorder(ColorConstants.BLUE, 5));
            for (int i = 0; i <= 24; i++)
            {
                image1.SetRotationAngle(i * Math.PI / 12);
                image2.SetRotationAngle(i * Math.PI / 12);
                doc.Add(image1);
                doc.Add(image2);
            }
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #9
0
        public virtual void ImageWidthTest02()
        {
            PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(imageFolder + "Desert.jpg"));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject);
            ImageRenderer renderer           = new ImageRenderer(image);

            image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePointValue(50));
            MinMaxWidth minMaxWidth = renderer.GetMinMaxWidth();

            NUnit.Framework.Assert.AreEqual(50.0, minMaxWidth.GetMaxWidth(), EPSILON);
            NUnit.Framework.Assert.AreEqual(0.0, minMaxWidth.GetMaxWidth() - minMaxWidth.GetMinWidth(), EPSILON);
            image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePercentValue(50));
            minMaxWidth = renderer.GetMinMaxWidth();
            NUnit.Framework.Assert.AreEqual(1024.0, minMaxWidth.GetMaxWidth(), EPSILON);
            image.SetProperty(Property.MAX_HEIGHT, UnitValue.CreatePointValue(100f));
            minMaxWidth = renderer.GetMinMaxWidth();
            NUnit.Framework.Assert.AreEqual(100.0 * 1024.0 / 768.0, minMaxWidth.GetMaxWidth(), EPSILON);
            image    = new iText.Layout.Element.Image(xObject);
            renderer = new ImageRenderer(image);
            image.SetProperty(Property.MIN_WIDTH, UnitValue.CreatePointValue(2000));
            image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePointValue(3000));
            minMaxWidth = renderer.GetMinMaxWidth();
            NUnit.Framework.Assert.AreEqual(2000.0, minMaxWidth.GetMaxWidth(), EPSILON);
            NUnit.Framework.Assert.AreEqual(0.0, minMaxWidth.GetMaxWidth() - minMaxWidth.GetMinWidth(), EPSILON);
            image.SetProperty(Property.MIN_HEIGHT, UnitValue.CreatePointValue(100f));
            image.SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(100f));
            minMaxWidth = renderer.GetMinMaxWidth();
            NUnit.Framework.Assert.AreEqual(100.0 * 1024.0 / 768.0, minMaxWidth.GetMaxWidth(), EPSILON);
        }
Example #10
0
        public virtual void TabsInParagraphTest01()
        {
            String      outFileName = destinationFolder + "tabsInParagraphTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_tabsInParagraphTest01.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);
            float       tabWidth    = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin();
            Paragraph   p           = new Paragraph();

            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Text2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Long Long Long Long Long Long Long Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg"
                                                                                                    )));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then texts and an image."
                                                                         ).Add(new Tab()).Add("Text1").Add(image).Add("Text3");
            doc.Add(p);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddXmpMetadata()));
            Document    document = new Document(pdf);

            //Setting some required parameters
            pdf.SetTagged();
            pdf.GetCatalog().SetLang(new PdfString("en-US"));
            pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
            PdfDocumentInfo info = pdf.GetDocumentInfo();

            info.SetTitle("iText7 PDF/UA example");
            //Fonts need to be embedded
            PdfFont   font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
            Paragraph p    = new Paragraph();

            p.SetFont(font);
            p.Add(new Text("The quick brown "));
            iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX));
            //PDF/UA: Set alt text
            foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox");
            p.Add(foxImage);
            p.Add(" jumps over the lazy ");
            iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
            //PDF/UA: Set alt text
            dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog");
            p.Add(dogImage);
            document.Add(p);
            document.Close();
        }
Example #12
0
            public virtual void HandleEvent(Event @event)
            {
                PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
                PdfDocument      pdfDoc   = docEvent.GetDocument();
                PdfPage          page     = docEvent.GetPage();
                int pageNumber            = pdfDoc.GetPageNumber(page);

                iText.Kernel.Geom.Rectangle pageSize = page.GetPageSize();
                PdfCanvas pdfCanvas        = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);
                double    ancho_encabezado = vendedor_nombre.Length * 3.5;

                //Add header and footer
                pdfCanvas
                .BeginText()
                .SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD), 13)
                .MoveText(pageSize.GetWidth() / 2 - ancho_encabezado, pageSize.GetTop() - 60)
                //.ShowText(vendedor_nombre)
                //.MoveText(60, -pageSize.GetTop() + 30)
                //.ShowText(pageNumber.ToString())
                .EndText();

                if (nombre_imagen != "")
                {
                    iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(nombre_imagen));
                    img.Scale(0.50f, 0.50f);
                    img.SetFixedPosition(0, pageSize.GetTop() - (img.GetImageHeight() / 2));
                    iText.Kernel.Geom.Rectangle area = page.GetPageSize();
                    new Canvas(pdfCanvas, pdfDoc, area)
                    .Add(img);
                }
            }
Example #13
0
        static void Main(string[] args)
        {
            string placa = "FHH670";

            // string Contenido = placa;
            if (placa.Length != 6)
            {
                Console.WriteLine("Debe entrar un numero de placa valido");
                return;
            }
            else
            {
                //Contenido = args[0];
                PdfWriter   pdfwriter = new PdfWriter(@"C:\CapturarFotoWebCam\Codigo.pdf");
                PdfDocument pdf       = new PdfDocument(pdfwriter);
                Document    Documento = new Document(pdf, PageSize.LETTER);
                Documento.SetMargins(20, 20, 20, 20);

                Barcode Codigo = new Barcode();
                Codigo.IncludeLabel = true;
                Codigo.Alignment    = AlignmentPositions.CENTER;
                Codigo.LabelFont    = new Font(FontFamily.GenericMonospace, 14, FontStyle.Regular);

                System.Drawing.Image img = Codigo.Encode(TYPE.CODE128, placa, Color.Black, Color.White, 200, 100);
                //pictureBox.Image = img;

                Codigo.SaveImage(@"C:\CapturarFotoWebCam\" + placa + ".jpg", SaveTypes.JPG);

                System.Drawing.Image imgFinal = (System.Drawing.Image)Codigo.Encode(TYPE.CODE128, placa, Color.Black, Color.White, 200, 100);
                imgFinal.Save(@"C:\CapturarFotoWebCam\" + placa + ".png", ImageFormat.Png);

                imgFinal.Dispose();

                PrintDocument pd = new PrintDocument();
                pd.PrintPage += (sender, e) =>
                {
                    System.Drawing.Image i = System.Drawing.Image.FromFile(@"C:\CapturarFotoWebCam\" + placa + ".jpg");
                    System.Drawing.Point p = new System.Drawing.Point(100, 100);
                    e.Graphics.DrawImage(i, p);
                };
                pd.Print();



                var imagen = new iText.Layout.Element.Image(ImageDataFactory.Create(@"C:\CapturarFotoWebCam\" + placa + ".jpg"));

                var parrafo = new Paragraph().Add(imagen);
                Documento.Add(parrafo);
                //System.Drawing.Bitmap a = img as Bitmap;
                CreaTicket Ticket1 = new CreaTicket();
                Ticket1.ImpresionContinua(placa);
                //Ticket1.SendImageToPrinter(10, 10, "c", 90); //Codigo.Encode(TYPE.CODE128, placa, Color.Black, Color.White, 200, 100));

                //ImpresionReportePDF impresion = new ImpresionReportePDF();
                //impresion.SendToPrinter();
                ////impresion.PrintPDF(@"C:\CapturarFotoWebCam\",1, "Microsoft Print to PDF", "Codigo.pdf");
                ////impresion.ImprimirDocumentoSinAbrirlo(@"C:\CapturarFotoWebCam\Codigo.pdf");
                Documento.Close();
            }
        }
Example #14
0
        public bool Print()
        {
            var   fileName = "Transaction" + _transaction.TransactionNumber + ".pdf";
            var   filePath = Path.Combine(CheckDirectory(), fileName);
            Image logo     = new Image(ImageDataFactory.Create(_settings.LogoUrl))
                             .SetWidth(200)
                             .SetMaxWidth(400)
                             .SetHorizontalAlignment(HorizontalAlignment.LEFT);

            try
            {
                createPdf(filePath, logo);
            }
            catch (Exception e)
            {
                MessageBox.Show("Błąd tworzenia pliku PDF : " + e.Message, "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            try
            {
                PrintFile(filePath);
            }
            catch (Exception e)
            {
                MessageBox.Show("Błąd wydruku : " + e.Message, "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(true);
        }
        private void AddSimpleContentToDoc(Document document, Paragraph p2)
        {
            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + imageName
                                                                                                    )).SetWidth(100);
            Table table = new Table(UnitValue.CreatePercentArray(4)).UseAllAvailableWidth();

            for (int k = 0; k < 5; k++)
            {
                table.AddCell(p2);
                List list = new List().SetListSymbol("-> ");
                list.Add("list item").Add("list item").Add("list item").Add("list item").Add("list item");
                Cell cell = new Cell().Add(list);
                table.AddCell(cell);
                Cell c = new Cell().Add(img);
                table.AddCell(c);
                Table innerTable = new Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth();
                int   j          = 0;
                while (j < 9)
                {
                    innerTable.AddCell("Hi");
                    j++;
                }
                table.AddCell(innerTable);
            }
            document.Add(table);
        }
Example #16
0
        public virtual void DivWithRotatedPercentImage()
        {
            String          outFileName  = destinationFolder + "divRotatedPercentImage.pdf";
            String          cmpFileName  = sourceFolder + "cmp_divRotatedPercentImage.pdf";
            PdfDocument     pdfDocument  = new PdfDocument(new PdfWriter(outFileName));
            Document        doc          = new Document(pdfDocument);
            PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "itis.jpg"));

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(imageXObject).SetRotationAngle(Math.PI * 3
                                                                                                           / 8);
            Div d = new Div().Add(img).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f)).SetMarginBottom(10);

            iText.Layout.Element.Image imgPercent = new iText.Layout.Element.Image(imageXObject).SetWidth(UnitValue.CreatePercentValue
                                                                                                              (50)).SetRotationAngle(Math.PI * 3 / 8);
            Div         dPercent = new Div().Add(imgPercent).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f));
            MinMaxWidth result   = ((AbstractRenderer)d.CreateRendererSubTree().SetParent(doc.GetRenderer())).GetMinMaxWidth
                                       ();

            d.SetWidth(ToEffectiveWidth(d, result.GetMinWidth()));
            MinMaxWidth resultPercent = ((AbstractRenderer)dPercent.CreateRendererSubTree().SetParent(doc.GetRenderer(
                                                                                                          ))).GetMinMaxWidth();

            dPercent.SetWidth(ToEffectiveWidth(dPercent, resultPercent.GetMaxWidth()));
            doc.Add(d);
            doc.Add(dPercent);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #17
0
        //PDF Brief drucken Button
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Abfrage ob man die PDF speichern möchte
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter       = "Files(*.pdf)|*.pdf";
            saveFileDialog.AddExtension = true;
            saveFileDialog.DefaultExt   = ".pdf";

            if (saveFileDialog.ShowDialog() == true)
            {
                string path = saveFileDialog.FileName;


                //writer instanzieren
                PdfWriter writer = new PdfWriter(path);

                //pdfdocument erzeugen
                PdfDocument pdf = new PdfDocument(writer);


                //Document erzeugen
                using (Document document = new Document(pdf, PageSize.A4))
                {
                    //Einfügen in das document

                    Image logo = new Image(ImageDataFactory.CreateJpeg(new Uri($"{Directory.GetCurrentDirectory()}\\logo.jpg", UriKind.Absolute)));
                    logo.ScaleAbsolute(180f, 50f);
                    logo.SetFixedPosition(400f, 750f);
                    document.Add(logo);

                    document.Add(new Paragraph(TB_vname.Text + " " + TB_nname.Text).SetFixedPosition(45f, 780f, 800f));
                    document.Add(new Paragraph(TB_strasse.Text + " " + TB_hsnr.Text).SetFixedPosition(45f, 760f, 800f));
                    document.Add(new Paragraph(TB_plz.Text + " " + TB_ort.Text).SetFixedPosition(45f, 740f, 800));


                    document.Add(new Paragraph(Betreff.Text).SetFixedPosition(45f, 600f, 800f));

                    document.Add(new Paragraph(Anrede.Text).SetFixedPosition(90f, 500f, 800f));

                    Image inhalt = new Image(ImageDataFactory.CreateJpeg(new Uri($"{Directory.GetCurrentDirectory()}\\inhalt.jpg", UriKind.Absolute)));
                    inhalt.ScaleAbsolute(400f, 400f);
                    inhalt.SetFixedPosition(70f, 100f);
                    document.Add(inhalt);
                }

                pdf.Close();

                //writer schliesen
                writer.Close();

                //öffnen des documentes
                Process.Start(path);
            }
            else
            {
            }
        }
Example #18
0
        //Crear PDF y plantilla correspondiente
        public void crearEncabezadoPDF()
        {
            //Variables
            string paciente        = txtNombre.Text;
            string edad            = txtEdad.Text;
            string recomendaciones = txt_Recomendaciones.Text;

            //Concatenaciones
            string datoNombrePaciente  = lb_NombrePaciente.Text + paciente;
            string datoEdadPaciente    = lb_Edad.Text + edad;
            string datoRecomendaciones = lb_Recomendaciones.Text + recomendaciones;

            string      ruta     = string.Format(@"PacientesEjercicios\{0}.pdf", txtNombre.Text);
            PdfWriter   writer   = new PdfWriter(ruta);
            PdfDocument pdf      = new PdfDocument(writer);
            Document    document = new Document(pdf);

            document.SetMargins(20f, 20f, 20f, 20f);
            //Agregamos Logo de la Clinica
            Image img = new Image(ImageDataFactory
                                  .Create(@"Recursos\LogoCraf.jpg"))
                        .SetTextAlignment(TextAlignment.LEFT)
                        .ScaleToFit(250f, 250f);

            document.Add(img);
            //Titulo del documento
            Paragraph header = new Paragraph("Centro de Rehabilitación Acuática y Fisica")
                               .SetTextAlignment(TextAlignment.RIGHT)
                               .SetFontSize(15);

            document.Add(header);

            //Insertamos linea de separacion
            LineSeparator ls = new LineSeparator(new SolidLine());

            document.Add(ls);

            //Agregamos datos del paciente
            Paragraph paciente_dato      = new Paragraph(datoNombrePaciente).SetTextAlignment(TextAlignment.LEFT).SetFontSize(10);
            Paragraph edad_dato          = new Paragraph(datoEdadPaciente).SetTextAlignment(TextAlignment.LEFT).SetFontSize(10);
            Paragraph recomendacion_dato = new Paragraph(datoRecomendaciones).SetTextAlignment(TextAlignment.LEFT).SetFontSize(10);

            document.Add(paciente_dato);
            document.Add(edad_dato);
            document.Add(recomendacion_dato);
            document.Add(ls);

            //Agregamos las imagenes seleccionadas con los textos



            //Cerramos documento
            document.Close();

            //Habilitamos el boton visualizar al momento de crear el Pdf
            btn_Visualizar.Enabled = true;
        }
Example #19
0
 public ImagesContainer(String imageName, iText.Layout.Element.Image img, FloatPropertyValue?floatPropertyValue
                        , HorizontalAlignment?horizontalAlignment, ClearPropertyValue?clearPropertyValue, UnitValue width)
 {
     this.imageName           = imageName;
     this.img                 = img;
     this.floatPropertyValue  = floatPropertyValue;
     this.horizontalAlignment = horizontalAlignment;
     this.clearPropertyValue  = clearPropertyValue;
     this.width               = width;
 }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf);

            // raw
            byte[] data = new byte[256 * 3];
            for (int i = 0; i < 256; i++)
            {
                data[i * 3]     = (byte)(255 - i);
                data[i * 3 + 1] = (byte)(255 - i);
                data[i * 3 + 2] = (byte)i;
            }
            ImageData raw = ImageDataFactory.Create(256, 1, 3, 8, data, null);

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(raw);
            img.ScaleAbsolute(256, 10);
            document.Add(img);
            // JPEG2000
            iText.Layout.Element.Image img1 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST1));
            document.Add(img1);
            document.Add(new AreaBreak());
            // BMP
            iText.Layout.Element.Image img2 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST2));
            img2.SetMarginBottom(10);
            document.Add(img2);
            // PNG
            iText.Layout.Element.Image img3 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST3));
            img3.SetMarginBottom(10);
            document.Add(img3);
            // Transparent PNG
            iText.Layout.Element.Image img4 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST4));
            img4.SetBorderLeft(new SolidBorder(6));
            document.Add(img4);
            // GIF
            iText.Layout.Element.Image img5 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST5));
            img5.SetBackgroundColor(ColorConstants.LIGHT_GRAY);
            document.Add(img5);

            // System.Drawing.Image
            System.Drawing.Image       systemDrawingImage = System.Drawing.Image.FromFile(TEST5);
            iText.Layout.Element.Image awt = new iText.Layout.Element.Image(ImageDataFactory.Create(systemDrawingImage, System.Drawing.Color.Yellow));
            awt.SetMarginTop(10);
            document.Add(awt);

            // JBIG2
            iText.Layout.Element.Image img6 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST6));
            document.Add(img6);
            // TIFF
            iText.Layout.Element.Image img7 = new iText.Layout.Element.Image(ImageDataFactory.Create(TEST7));
            document.Add(img7);
            document.Close();
        }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf);
            Paragraph   p        = new Paragraph("Mary Reilly is a maid in the household of Dr. Jekyll: ");

            document.Add(p);
            iText.Layout.Element.Image img1 = new Image(ImageDataFactory.Create(MARY));
            document.Add(img1);
            iText.Layout.Element.Image img2 = new iText.Layout.Element.Image(ImageDataFactory.Create(MARY));
            document.Add(img2);
            document.Close();
        }
        public static void AddArticle(Document doc, String title, String author, iText.Layout.Element.Image img, String text)
        {
            Paragraph p1 = new Paragraph(title).SetFont(timesNewRomanBold).SetFontSize(14);

            doc.Add(p1);
            doc.Add(img);
            Paragraph p2 = new Paragraph().SetFont(timesNewRoman).SetFontSize(7).SetFontColor(ColorConstants.GRAY).Add(author);

            doc.Add(p2);
            Paragraph p3 = new Paragraph().SetFont(timesNewRoman).SetFontSize(10).Add(text);

            doc.Add(p3);
        }
Example #23
0
 private void GenerateDocumentWithObjectFit(ObjectFit objectFit, String outFileName)
 {
     using (PdfWriter writer = new PdfWriter(outFileName)) {
         using (Document doc = new Document(new PdfDocument(writer))) {
             PdfImageXObject            xObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "Desert.jpg"));
             iText.Layout.Element.Image image   = new iText.Layout.Element.Image(xObject).SetWidth(200).SetHeight(600).SetObjectFit
                                                      (objectFit);
             Paragraph p = new Paragraph();
             p.Add(image);
             doc.Add(p);
         }
     }
 }
Example #24
0
        private static void AddParaWithImgSetOverflowX(iText.Layout.Canvas canvas, OverflowPropertyValue?overflowX
                                                       )
        {
            String imgPath = sourceFolder + "itis.jpg";

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(imgPath));
            Paragraph p = new Paragraph().SetTextAlignment(TextAlignment.CENTER).SetHeight(150f).SetWidth(150f).SetBorder
                              (new SolidBorder(5f));

            p.SetProperty(Property.OVERFLOW_X, overflowX);
            p.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.HIDDEN);
            img.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
            img.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
            canvas.Add(p.Add(img));
        }
Example #25
0
        public virtual void ImageTest23()
        {
            String      outFileName = destinationFolder + "imageTest23.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest23.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "encoded_tiff.tiff"
                                                                                                      ));
            image.ScaleToFit(500, 500);
            doc.Add(image);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #26
0
        public virtual void ImageTest15()
        {
            String      outFileName = destinationFolder + "imageTest15.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest15.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
                                                                                                      ));
            image.SetBorder(new SolidBorder(ColorConstants.BLUE, 5));
            doc.Add(image);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #27
0
        public virtual void ImageTest14_HorizontalAlignment_LEFT()
        {
            String      outFileName = destinationFolder + "imageTest14.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest14.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "itis.jpg"
                                                                                                      ));
            image.SetHorizontalAlignment(HorizontalAlignment.LEFT);
            doc.Add(image);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Example #28
0
        public virtual void ImageTest10()
        {
            String      outFileName = destinationFolder + "imageTest10.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageTest10.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc, new PageSize(500, 300));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
                                                                                                      ));
            image.SetAutoScale(true);
            doc.Add(image);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        private void AddMainHeading(Table table, string heading)
        {
            Cell headingCell = new Cell(2, 4);

            headingCell.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
            headingCell.SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.Color.WHITE, 3));
            headingCell.Add(new Paragraph(heading).SetFontSize(22F).SetBackgroundColor(new DeviceRgb(252, 213, 180))
                            // .SetBorder(new iText.Layout.Borders.SolidBorder(new DeviceRgb(247, 150, 70), 3))
                            );
            iText.Layout.Element.Image img = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create("Images/logo.png"));

            table.AddCell(headingCell);
            //  table.AddCell(new Cell().Add(new Paragraph(string.Empty).SetFontSize(22F)).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.Color.WHITE, 3)));
            //table.AddCell(new Cell().Add(new Paragraph(string.Empty).SetFontSize(22F)).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.Color.WHITE, 3)));
            table.AddCell(new Cell().Add(img).SetMarginLeft(60F).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.Color.WHITE, 3)));
        }
Example #30
0
        public static void createDocument(List <ImageSelection> listImages, Appearance appearance, PageSize pageSize, string exportFile)
        {
            checkSameDocuments(ref exportFile);

            using (PdfWriter writer = new PdfWriter(exportFile))
            {
                using (PdfDocument pdf = new PdfDocument(writer))
                {
                    Document pdoc = new Document(pdf, pageSize);

                    pdoc.SetMargins(14.1665f, 14.1665f, 14.1665f, 14.1665f);



                    Table table = tableStyle(appearance, pageSize, pdoc);



                    for (int k = 0, i = 0, j = 0; k < listImages.Count; k++, j++)
                    {
                        if (j == appearance.getDimensions().Length)
                        {
                            j = 0; i++;
                        }
                        if (i == appearance.getHeightRatio())
                        {
                            pdoc.Add(table);
                            table = tableStyle(appearance, pageSize, pdoc);

                            pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                            j = i = 0;
                        }

                        Image img = new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(k).getPath()));

                        imgStyle(ref img, listImages.ElementAt(k));


                        table.GetCell(i, j).Add(img);
                    }
                    pdoc.Add(table);


                    pdoc.Close();
                }
            }
        }