示例#1
0
        /**
         * Gets the special field appearance for the radio circle.
         * @param on <CODE>true</CODE> for the checked state, <CODE>false</CODE>
         * otherwise
         * @return the appearance
         */
        public PdfAppearance GetAppearanceRadioCircle(bool on)
        {
            PdfAppearance app = new PdfContentByte(writer).CreateAppearance(box.Width, box.Height);

            switch (rotation)
            {
            case 90:
                app.SetMatrix(0, 1, -1, 0, box.Height, 0);
                break;

            case 180:
                app.SetMatrix(-1, 0, 0, -1, box.Width, box.Height);
                break;

            case 270:
                app.SetMatrix(0, -1, 1, 0, 0, box.Width);
                break;
            }
            Rectangle boxc = new Rectangle(app.BoundingBox);
            float     cx   = boxc.Width / 2;
            float     cy   = boxc.Height / 2;
            float     r    = (Math.Min(boxc.Width, boxc.Height) - borderWidth) / 2;

            if (r <= 0)
            {
                return(app);
            }
            if (backgroundColor != null)
            {
                app.SetColorFill(backgroundColor);
                app.Circle(cx, cy, r + borderWidth / 2);
                app.Fill();
            }
            if (borderWidth > 0 && borderColor != null)
            {
                app.SetLineWidth(borderWidth);
                app.SetColorStroke(borderColor);
                app.Circle(cx, cy, r);
                app.Stroke();
            }
            if (on)
            {
                if (textColor == null)
                {
                    app.ResetGrayFill();
                }
                else
                {
                    app.SetColorFill(textColor);
                }
                app.Circle(cx, cy, r / 2);
                app.Fill();
            }
            return(app);
        }
示例#2
0
// ---------------------------------------------------------------------------

        /**
         * Prints 3 circles in different colors that intersect with eachother.
         *
         * @param x
         * @param y
         * @param cb
         * @throws Exception
         */
        public static void PictureCircles(float x, float y, PdfContentByte cb)
        {
            cb.SetColorFill(BaseColor.RED);
            cb.Circle(x + 70, y + 70, 50);
            cb.Fill();
            cb.SetColorFill(BaseColor.YELLOW);
            cb.Circle(x + 100, y + 130, 50);
            cb.Fill();
            cb.SetColorFill(BaseColor.BLUE);
            cb.Circle(x + 130, y + 70, 50);
            cb.Fill();
        }
示例#3
0
// ---------------------------------------------------------------------------

        /**
         * Prints 3 circles in different colors that intersect with eachother.
         *
         * @param x
         * @param y
         * @param cb
         * @throws Exception
         */
        public static void PictureCircles(float x, float y, PdfContentByte cb)
        {
            PdfGState gs = new PdfGState();

            gs.BlendMode   = PdfGState.BM_MULTIPLY;
            gs.FillOpacity = 1f;
            cb.SetGState(gs);
            cb.SetColorFill(new CMYKColor(0f, 0f, 0f, 0.15f));
            cb.Circle(x + 75, y + 75, 70);
            cb.Fill();
            cb.Circle(x + 75, y + 125, 70);
            cb.Fill();
            cb.Circle(x + 125, y + 75, 70);
            cb.Fill();
            cb.Circle(x + 125, y + 125, 70);
            cb.Fill();
        }
示例#4
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte canvas = writer.DirectContent;
                // draw squares
                CreateSquares(canvas, 50, 720, 80, 20);
                ColumnText.ShowTextAligned(
                    canvas, Element.ALIGN_LEFT,
                    new Phrase(
                        "Methods MoveTo(), LineTo(), stroke(), closePathStroke(), Fill(), and closePathFill()"
                        ),
                    50, 700, 0
                    );
                // draw Bezier curves
                createBezierCurves(canvas, 70, 600, 80, 670, 140, 690, 160, 630, 160);
                ColumnText.ShowTextAligned(
                    canvas, Element.ALIGN_LEFT,
                    new Phrase("Different CurveTo() methods, followed by stroke()"),
                    50, 580, 0
                    );
                // draw stars and circles
                CreateStarsAndCircles(canvas, 50, 470, 40, 20);
                ColumnText.ShowTextAligned(
                    canvas, Element.ALIGN_LEFT,
                    new Phrase(
                        "Methods Fill(), eoFill(), NewPath(), FillStroke(), and EoFillStroke()"
                        ),
                    50, 450, 0
                    );
                // draw different shapes using convenience methods
                canvas.SaveState();
                canvas.SetColorStroke(new GrayColor(0.2f));
                canvas.SetColorFill(new GrayColor(0.9f));
                canvas.Arc(50, 270, 150, 330, 45, 270);
                canvas.Ellipse(170, 270, 270, 330);
                canvas.Circle(320, 300, 30);
                canvas.RoundRectangle(370, 270, 80, 60, 20);
                canvas.FillStroke();
                canvas.RestoreState();
                Rectangle rect = new Rectangle(470, 270, 550, 330);
                rect.BorderWidthBottom = 10;
                rect.BorderColorBottom = new GrayColor(0f);
                rect.BorderWidthLeft   = 4;
                rect.BorderColorLeft   = new GrayColor(0.9f);
                rect.BackgroundColor   = new GrayColor(0.4f);
                canvas.Rectangle(rect);
                ColumnText.ShowTextAligned(
                    canvas, Element.ALIGN_LEFT,
                    new Phrase("Convenience methods"), 50, 250, 0
                    );
            }
        }
示例#5
0
        public static void CreateSeatplanPdf(Document doc, string imageFilePath, LocationSeatplan plan, PdfContentByte pdfContentByte, float scaleFactor, float pageBorderLeft = 0)
        {
            var jpg = Image.GetInstance(imageFilePath);

            //Resize image depend upon your need for give the size to image
            jpg.ScaleToFit(jpg.Width * scaleFactor, jpg.Height * scaleFactor);

            //image as background
            jpg.Alignment = Image.UNDERLYING;


            jpg.SetAbsolutePosition(pageBorderLeft, doc.Top - (jpg.GetTop(0) * scaleFactor) - SpaceForHeader);

            doc.Add(jpg);
            var seatCount = 0;

            foreach (var seat in plan.LocationSeats)
            {
                seatCount++;
                var seatRadius = (seat.Width / 2f) * scaleFactor;
                pdfContentByte.Circle(pageBorderLeft + (seat.PositionX * scaleFactor), doc.Top - (seat.PositionY * scaleFactor) - SpaceForHeader, seatRadius);

                pdfContentByte.SetRGBColorFill(51, 204, 0);
                pdfContentByte.SetRGBColorStroke(51, 204, 0);


                pdfContentByte.FillStroke();

                pdfContentByte.SetRGBColorFill(0, 0, 0);

                // add text to seat & set the right font size
                var fontSizeSeat = seatRadius / 1.8;
                pdfContentByte.BeginText();
                pdfContentByte.SetFontAndSize(_fontBase, (float)fontSizeSeat);

                var seatText = string.Empty;

                foreach (var s in seat.SeatIdentification.Split(' '))
                {
                    if ((s.Contains(',') || seat.SeatIdentification.Split(' ').Last() == s) && s.Length < 5)
                    {
                        seatText += s;
                    }
                }

                pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER, seatText, pageBorderLeft + (seat.PositionX * scaleFactor), doc.Top - (seat.PositionY * scaleFactor) - SpaceForHeader - 1, 0);
                pdfContentByte.EndText();
            }


            pdfContentByte.ClosePathFillStroke();

            doc.NewPage();
        }
        public void DrawCircle(EbReportField field, float printingTop)
        {
            float radius = field.Width / 2;
            float xval   = field.Left + radius;
            float yval   = Report.Height - (printingTop + field.Top + radius);

            cb.SetColorStroke(GetColor(field.BorderColor));
            cb.SetColorFill(GetColor(field.BackColor));
            cb.SetLineWidth(field.Border);
            cb.Circle(xval, yval, radius);
            cb.FillStroke();
        }
        public override void draw(PdfContentByte cb, float doc_width, float doc_height, float scaling)
        {
            setScaling(scaling);
            base.draw(cb, doc_width, doc_height, scaling);

            cb.Circle(points[0].X + doc_width / 2, points[0].Y + doc_height / 2, scaled_radius);
            if (filled)
            {
                cb.ClosePathFillStroke();
            }
            else
            {
                cb.ClosePathStroke();
            }
        }
示例#8
0
        public Chap1013()
        {
            Console.WriteLine("Chapter 10 Example 13: Spot Color");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1013.pdf", FileMode.Create));
                BaseFont  bf     = BaseFont.CreateFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED);

                // step 3: we open the document
                document.Open();

                // step 4: we add some content
                PdfContentByte cb = writer.DirectContent;

                // Note: I made up these names unless someone give me a PANTONE swatch as gift ([email protected])
                PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f));
                PdfSpotColor spc_rgb  = new PdfSpotColor("PANTONE 147", 0.9f, new Color(114, 94, 38));
                PdfSpotColor spc_g    = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f));

                // Stroke a rectangle with CMYK alternate
                cb.SetColorStroke(spc_cmyk, .5f);
                cb.SetLineWidth(10f);
                // draw a rectangle
                cb.Rectangle(100, 700, 100, 100);
                // add the diagonal
                cb.MoveTo(100, 700);
                cb.LineTo(200, 800);
                // stroke the lines
                cb.Stroke();

                // Fill a rectangle with CMYK alternate
                cb.SetColorFill(spc_cmyk, spc_cmyk.Tint);
                cb.Rectangle(250, 700, 100, 100);
                cb.Fill();

                // Stroke a circle with RGB alternate
                cb.SetColorStroke(spc_rgb, spc_rgb.Tint);
                cb.SetLineWidth(5f);
                cb.Circle(150f, 500f, 100f);
                cb.Stroke();

                // Fill the circle with RGB alternate
                cb.SetColorFill(spc_rgb, spc_rgb.Tint);
                cb.Circle(150f, 500f, 50f);
                cb.Fill();

                // example with colorfill
                cb.SetColorFill(spc_g, spc_g.Tint);
                cb.MoveTo(100f, 200f);
                cb.LineTo(200f, 250f);
                cb.LineTo(400f, 150f);
                cb.Fill();
                document.NewPage();
                String text = "Some text to show";
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f))));

                // example with template
                PdfTemplate t = cb.CreateTemplate(500f, 500f);
                // Stroke a rectangle with CMYK alternate
                t.SetColorStroke(new SpotColor(spc_cmyk, .5f));
                t.SetLineWidth(10f);
                // draw a rectangle
                t.Rectangle(100, 10, 100, 100);
                // add the diagonal
                t.MoveTo(100, 10);
                t.LineTo(200, 100);
                // stroke the lines
                t.Stroke();

                // Fill a rectangle with CMYK alternate
                t.SetColorFill(spc_g, spc_g.Tint);
                t.Rectangle(100, 125, 100, 100);
                t.Fill();
                t.BeginText();
                t.SetFontAndSize(bf, 20f);
                t.SetTextMatrix(1f, 0f, 0f, 1f, 10f, 10f);
                t.ShowText("Template text upside down");
                t.EndText();
                t.Rectangle(0, 0, 499, 499);
                t.Stroke();
                cb.AddTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f);
            }
            catch (Exception de)
            {
                Console.Error.WriteLine(de.Message);
                Console.Error.WriteLine(de.StackTrace);
            }

            // step 5: we close the document
            document.Close();
        }
示例#9
0
 protected override void Draw(PdfContentByte cb)
 {
     cb.Circle(x, y, radius);
 }
示例#10
0
        public Chap1001()
        {
            Console.WriteLine("Chapter 10 example 1: Simple Graphic");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1001.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4: we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                // an example of a rectangle with a diagonal in very thick lines
                //cb.SetLineWidth(10f;
                cb.SetLineWidth(10f);
                // draw a rectangle
                cb.Rectangle(100, 700, 100, 100);
                // add the diagonal
                cb.MoveTo(100, 700);
                cb.LineTo(200, 800);
                // stroke the lines
                cb.Stroke();

                // an example of some circles
                cb.SetLineDash(3, 3, 0);
                cb.SetRGBColorStrokeF(0f, 255f, 0f);
                cb.Circle(150f, 500f, 100f);
                cb.Stroke();

                cb.SetLineWidth(5f);
                cb.ResetRGBColorStroke();
                cb.Circle(150f, 500f, 50f);
                cb.Stroke();

                // example with colorfill
                cb.SetRGBColorFillF(0f, 255f, 0f);
                cb.MoveTo(100f, 200f);
                cb.LineTo(200f, 250f);
                cb.LineTo(400f, 150f);
                // because we change the fill color BEFORE we stroke the triangle
                // the color of the triangle will be red instead of green
                cb.SetRGBColorFillF(255f, 0f, 0f);
                cb.ClosePathFillStroke();
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
示例#11
0
        public static void PageShapes(Document pdf, PdfWriter writer)
        {
            PdfContentByte cb = writer.DirectContent;


            // LINES
            var title = new Paragraph("Lines", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE));

            pdf.Add(title);


            cb.SetLineWidth(5);
            cb.SetColorStroke(new BaseColor(0, 140, 180));

            cb.MoveTo(40f, InverseY(120f));
            cb.LineTo(200f, InverseY(120f));
            cb.Stroke();

            cb.SetColorStroke(new BaseColor(10, 180, 80));
            cb.SetLineDash(20f, 10f);
            cb.MoveTo(40f, InverseY(140f));
            cb.LineTo(200f, InverseY(140f));

            cb.Stroke();

            // Reset
            cb.SetLineWidth(1);
            cb.SetLineDash(0);
            cb.SetColorStroke(new BaseColor(0, 0, 0));

            // SHAPES
            ColumnText ct     = new ColumnText(cb);
            Phrase     ctitle = new Phrase("Shapes", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE));

            ct.SetSimpleColumn(ctitle, 40f, 0, 580, InverseY(170f), 15, Element.ALIGN_LEFT);
            //lower-left-x
            //lower-left-y
            //upper-right-x(llx + width)
            //upper-right-y(lly + height)
            //leading(The amount of blank space between lines of print)
            ct.Go();

            //title = new Paragraph("Shapes", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE));
            //pdf.Add(title);


            cb.Rectangle(40f, InverseY(200f), 120f, -50f);
            cb.Stroke();

            cb.SetColorStroke(BaseColor.Red);
            cb.Circle(200f, InverseY(230f), 30f);
            cb.Stroke();

            cb.SaveState();
            {
                PdfGState gs = new PdfGState();
                gs.FillOpacity = 0.5f;
                cb.SetGState(gs);
                cb.SetColorFill(BaseColor.Green);
                cb.Circle(220f, InverseY(240f), 30f);
                cb.Fill();
            }
            cb.RestoreState();

            cb.SetColorStroke(BaseColor.Blue);
            cb.Arc(300f, InverseY(220f), 360f, InverseY(280f), 45, 270);
            cb.Stroke();
            //
        }
示例#12
0
        public static Document CreateReport(Box[] boxInfo, string fileName)
        {
            var pdfdoc      = new Document(PageSize.Letter);
            var pdfFilePath = fileName;
            var fileStream  = new FileStream(pdfFilePath, FileMode.Create);

            PdfWriter  writer  = PdfWriter.GetInstance(pdfdoc, fileStream);
            Barcode128 barcode = new Barcode128();

            BaseFont bf_helvBold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false);

            pdfdoc.Open();

            PdfContentByte under  = writer.DirectContentUnder;
            PdfContentByte canvas = writer.DirectContent;


            for (int i = 0; i < boxInfo.Length; i++)
            {
                if (boxInfo[i].IsSelected)
                {
                    under.Rectangle(boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BoundingLocation.Y, box_bounding_width, box_bounding_height);
                    under.Rectangle(boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BoundingLocation.Y - box_small_height, box_small_width, box_small_height);
                    under.SetLineWidth(1);
                    under.Stroke();

                    under.Circle(boundingBoxLocations[i].SphereColorLocation.X, boundingBoxLocations[i].SphereColorLocation.Y, circleRadius);
                    if (boxInfo[i].LensInfo.Sphere >= 0)
                    {
                        under.SetRgbColorFill(230, 50, 0);
                    }
                    else
                    {
                        under.SetRgbColorFill(138, 182, 252);
                    }
                    under.FillStroke();

                    if (boxInfo[i].LensInfo.AntiReflectiveCoating)
                    {
                        canvas.BeginText();
                        canvas.SetFontAndSize(bf_helvBold, 12);
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "AR", boundingBoxLocations[i].AntiReflectiveLocation.X, boundingBoxLocations[i].AntiReflectiveLocation.Y, 0);
                        canvas.EndText();
                    }

                    if (boxInfo[i].LensInfo.Transitions)
                    {
                        canvas.BeginText();
                        canvas.SetFontAndSize(bf_helvBold, 16);
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "T", boundingBoxLocations[i].TransitionsLocation.X, boundingBoxLocations[i].TransitionsLocation.Y, 0);
                        canvas.EndText();
                    }

                    //MATERIAL
                    canvas.BeginText();
                    canvas.SetFontAndSize(bf_helvBold, 12);
                    canvas.ShowTextAligned(Element.ALIGN_CENTER, boxInfo[i].LensInfo.Material.Name.ToString().ToUpper(), boundingBoxLocations[i].MaterialLocation.X, boundingBoxLocations[i].MaterialLocation.Y, 0);
                    canvas.EndText();


                    //POWER SPHERE
                    canvas.BeginText();
                    canvas.SetFontAndSize(bf_helvBold, 34);
                    if (boxInfo[i].LensInfo.Sphere > 0.00m)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "+" + boxInfo[i].LensInfo.Sphere.ToString().ToUpper() + " / " + boxInfo[i].LensInfo.Cylinder.ToString().ToUpper(), boundingBoxLocations[i].SphereLocation.X, boundingBoxLocations[i].SphereLocation.Y, 0);
                    }
                    else
                    {
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, boxInfo[i].LensInfo.Sphere.ToString().ToUpper() + " / " + boxInfo[i].LensInfo.Cylinder.ToString().ToUpper(), boundingBoxLocations[i].SphereLocation.X, boundingBoxLocations[i].SphereLocation.Y, 0);
                    }
                    canvas.EndText();

                    //Barcode
                    barcode.Code = boxInfo[i].LensInfo.ProductLabel;
                    barcode.Size = 10;

                    Image code128Image = barcode.CreateImageWithBarcode(canvas, BaseColor.Black, BaseColor.Black);
                    code128Image.ScalePercent(110);
                    code128Image.Alignment = Element.ALIGN_CENTER;
                    code128Image.SetAbsolutePosition(((box_bounding_width - code128Image.ScaledWidth) / 2) + boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BarcodeLocation.Y);
                    pdfdoc.Add(code128Image);
                }
            }

            pdfdoc.Close();
            fileStream.Dispose();

            return(pdfdoc);
        }
示例#13
0
        private void CreatePDF(object sender, DoWorkEventArgs e)
        {
            int       progressValue = 0;
            string    filename;
            PdfWriter pdfWriter = null;
            Bitmap    bmpCrop;

            Bitmap[]         bitmaps;
            RectangleF[]     srcRects;
            BackgroundWorker worker = sender as BackgroundWorker;


            // Get the bitmaps from the slots panel
            bitmaps = new Bitmap[m_cropperForm.m_slotsPanel.Bitmaps.Length];
            for (int i = 0; i < bitmaps.Length; i++)
            {
                bitmaps[i] = new Bitmap(m_cropperForm.m_slotsPanel.Bitmaps[i]);
            }

            // Get the rectangles from the slots panel
            srcRects = new RectangleF[m_cropperForm.m_slotsPanel.SourceRectangles.Length];
            for (int i = 0; i < bitmaps.Length; i++)
            {
                srcRects[i] = new RectangleF(
                    m_cropperForm.m_slotsPanel.SourceRectangles[i].X,
                    m_cropperForm.m_slotsPanel.SourceRectangles[i].Y,
                    m_cropperForm.m_slotsPanel.SourceRectangles[i].Width,
                    m_cropperForm.m_slotsPanel.SourceRectangles[i].Height);
            }

            // Get the filename
            filename = (string)e.Argument;

            // Save all cropped images
            try
            {
                for (int i = 0; i < m_cropperForm.m_slotsPanel.SlotCount; i++)
                {
                    bmpCrop = bitmaps[i].Clone(srcRects[i], bitmaps[i].PixelFormat);
                    bmpCrop.Save(Application.StartupPath + "//Data//PDF//Domino_PDF//Slot" + (i + 1) + ".jpg");

                    // Calculate the progress bar value
                    progressValue = (int)(((i + 1) / 7.0f) * 33);
                    worker.ReportProgress(progressValue);
                }

                // If the pdf creation is cancelled
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, m_cropperForm.m_langDictionary["Create PDF"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }

            // Create the PDF document
            try
            {
                // Initialize the PDF document
                m_document = new iTextSharp.text.Document(m_pageSize);
                m_document.SetMargins(0f, 0f, 0f, 0f);

                // Create the pdf writer
                pdfWriter = PdfWriter.GetInstance(m_document, new FileStream(filename, FileMode.Create));

                // Open the pdf document
                m_document.Open();

                // Draw the corner dots
                m_cb = pdfWriter.DirectContent;
                m_cb.SetCMYKColorFill(0, 0, 0, 255);

                // BOTTOM LEFT
                float radius = 3.8f / 2.0f;
                m_cb.Circle(18f + radius, 165.1f + radius, radius);
                m_cb.Fill();

                // TOP LEFT
                m_cb.Circle(16.8f + radius, 622.3f + radius, radius);
                m_cb.Fill();

                // TOP RIGHT
                m_cb.Circle(572.2f + radius, 678f + radius, radius);
                m_cb.Fill();

                // BOTTOM RIGHT
                m_cb.Circle(574.6f + radius, 109.4f + radius, radius);
                m_cb.Fill();

                // Fill the images array
                m_images = new iTextSharp.text.Image[m_cropperForm.m_slotsPanel.SlotCount];
                for (int i = 0; i < m_images.Length; i++)
                {
                    // If the pdf creation is cancelled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    m_images[i] = iTextSharp.text.Image.GetInstance(Application.StartupPath + "//Data//PDF//Domino_PDF//Slot" + (i + 1) + ".jpg");

                    float prec = imgWidth / m_images[i].Width;
                    m_images[i].ScalePercent(prec * 100);
                    m_images[i].RotationDegrees = 90;
                    m_images[i].Rotate();

                    // Calculate the progress bar value
                    progressValue = 33 + (int)(((i + 1) / (float)m_images.Length) * 12);
                    worker.ReportProgress(progressValue);
                }

                // Draw the slots to te pdf
                for (int i = 0; i < m_cropperForm.m_slotsPanel.SlotCount; i++)
                {
                    // If the pdf creation is cancelled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    InvokeFunction("Slot" + (i + 1));

                    // Calculate the progress bar value
                    progressValue += 3;
                    worker.ReportProgress(progressValue);
                }

                // Tiles 1-20 Lines
                for (int i = 0; i < 20; i++)
                {
                    // If the pdf creation is cancelled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    m_cb.Rectangle(
                        vertTilesMarginLeft + (i % 4) * (imgHeight + vertTilesHorizGap),
                        vertTilesMarginBottom - ((2 * (i / 4) + 1) * imgWidth) - ((i / 4) * vertTilesVertGap) - (m_lineWidth / 2.0f),
                        imgHeight + 0.5f, m_lineWidth);
                    m_cb.Fill();

                    // Calculate the progress bar value
                    progressValue = 66 + (int)(((i + 1) / 20.0f) * 12);
                    worker.ReportProgress(progressValue);
                }

                // Tiles 20-28 Lines
                for (int i = 0; i < 8; i++)
                {
                    // If the pdf creation is cancelled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    m_cb.Rectangle(
                        horizTilesMarginLeft + imgWidth - (m_lineWidth / 2.0f),
                        horizTilesMarginBottom - ((i + 1) * imgHeight) - (i * horizTilesVertGap),
                        m_lineWidth, imgHeight + 0.5f);
                    m_cb.Fill();

                    // Calculate the progress bar value
                    progressValue = 78 + (int)(((i + 1) / 8.0f) * 12);
                    worker.ReportProgress(progressValue);
                }
            }
            catch (iTextSharp.text.DocumentException err)
            {
                MessageBox.Show(err.Message, m_cropperForm.m_langDictionary["Create PDF"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, m_cropperForm.m_langDictionary["Create PDF"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            finally
            {
                // Clean up
                m_document.Close();
                m_document = null;
            }

            // Delete all cropped images
            try
            {
                for (int i = 0; i < m_cropperForm.m_slotsPanel.SlotCount; i++)
                {
                    string filePath = Application.StartupPath + "//Data//PDF//Domino_PDF//Slot" + (i + 1) + ".jpg";
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    // Calculate the progress bar value
                    progressValue = 90 + (int)(((i + 1) / 7.0f) * 10);
                    worker.ReportProgress(progressValue);
                }

                // If the pdf creation is cancelled
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, m_cropperForm.m_langDictionary["Create PDF"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
        }
示例#14
0
        /* Draw one note, do = 1.
         * content: Drawing content container.
         * left: Beginning position.
         * up: Beginning position.
         * number: Tone.
         * length: Length of the note, currently support 1, 0.75, 0.5, 0.25.
         */
        private void DrawOneScore(PdfContentByte content, float left, float up, double number, double length = 1)
        {
            // TODO(allenxie): Deal with flag == false.
            up = PageSize.A4.Height - up;
            float position = up - 5 * lineSpace + ((float)number - 1) * lineSpace / 2;

            // Circle
            content.SetColorFill(BaseColor.BLACK);
            // content.Circle(left, position, scoreRadius);
            content.Ellipse(left - 4, position - 3, left + 4, position + 3);
            content.Fill();
            // Vertical line (0.5 is for good-looking)
            if (number < 8)
            {
                content.MoveTo(left + scoreRadius + 0.5, position);
                content.LineTo(left + scoreRadius + 0.5, position + 3.5 * lineSpace);
                content.Stroke();
                if (length == 0.5 || length == 0.75)
                {
                    double left_start = left + scoreRadius + 0.5;
                    double up_start   = position + 3.5 * lineSpace - 0.5;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start - 4, left_start + 7, up_start - 7, left_start + 4, up_start - 12);
                    content.Stroke();
                    if (length == 0.75)
                    {
                        double dot_position = (number % 2 == 0) ? position : position + 0.5 * lineSpace;
                        content.Circle(left_start + 3, dot_position, 1);
                        content.Fill();
                    }
                }
                if (length == 0.25)
                {
                    double left_start = left + scoreRadius + 0.5;
                    double up_start   = position + 3.5 * lineSpace - 0.5;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start - 3, left_start + 6, up_start - 6, left_start + 3, up_start - 9);
                    content.Stroke();
                    up_start = up_start - 4;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start - 3, left_start + 6, up_start - 6, left_start + 3, up_start - 9);
                    content.Stroke();
                }
            }
            else
            {
                content.MoveTo(left - scoreRadius - 0.5, position);
                content.LineTo(left - scoreRadius - 0.5, position - 3.5 * lineSpace);
                content.Stroke();
                if (length == 0.5 || length == 0.75)
                {
                    double left_start = left - scoreRadius - 0.5;
                    double up_start   = position - 3.5 * lineSpace + 0.5;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start + 4, left_start + 7, up_start + 7, left_start + 4, up_start + 12);
                    content.Stroke();
                    if (length == 0.75)
                    {
                        double dot_position = (number % 2 == 0) ? position : position + 0.5 * lineSpace;
                        content.Circle(left_start + 8, dot_position, 1);
                        content.Fill();
                    }
                }
                if (length == 0.25)
                {
                    double left_start = left - scoreRadius - 0.5;
                    double up_start   = position - 3.5 * lineSpace + 0.5;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start + 3, left_start + 6, up_start + 6, left_start + 3, up_start + 9);
                    content.Stroke();
                    up_start = up_start + 4;
                    content.MoveTo(left_start, up_start);
                    content.CurveTo(left_start + 1, up_start + 3, left_start + 6, up_start + 6, left_start + 3, up_start + 9);
                    content.Stroke();
                }
            }
            // If need addition lateral line
            if (number < 2 && ((int)number % 2 == 0))
            {
                content.MoveTo(left - scoreRadius * 2, position + scoreRadius);
                content.LineTo(left + scoreRadius * 2, position + scoreRadius);
                content.Stroke();
            }
            else if (number < 2 && ((int)number % 2 != 0))
            {
                content.MoveTo(left - scoreRadius * 2, position);
                content.LineTo(left + scoreRadius * 2, position);
                content.Stroke();
            }
            else if (number > 12 && ((int)number % 2 == 0))
            {
                content.MoveTo(left - scoreRadius * 2, position - scoreRadius);
                content.LineTo(left + scoreRadius * 2, position - scoreRadius);
                content.Stroke();
            }
            else if (number > 12 && ((int)number % 2 != 0))
            {
                content.MoveTo(left - scoreRadius * 2, position);
                content.LineTo(left + scoreRadius * 2, position);
                content.Stroke();
            }
        }
示例#15
0
        public Chap1015()
        {
            Console.WriteLine("Chapter 10 Example 15: Tiled Patterns");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1015.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4: we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                BaseFont bf = BaseFont.CreateFont("Times-Roman", "winansi", false);

                // step 5: we create some PdfPatternPainter instances for drawing path, text, or placing image

                // Image instance to be placed in PdfPatternPainter canvas. Any nice one?
                Image img = Image.GetInstance("pngnow.png");

                PdfPatternPainter p  = cb.CreatePattern(60f, 60f, 60f, 60f);
                PdfPatternPainter p1 = cb.CreatePattern(60f, 60f, 60f, 60f);
                PdfPatternPainter p2 = cb.CreatePattern(img.ScaledWidth, img.ScaledHeight, img.ScaledWidth, img.ScaledHeight);


                // step 6: put your drawing instruction in the painter canvas

                // A star pattern taken from Adobe PDF Reference Book p.207
                String star = "0.3 g\n15.000 27.000 m\n"
                              + "7.947 5.292 l\n26.413 18.708 l\n"
                              + "3.587 18.708 l\n22.053 5.292 l\nf\n"
                              + "45.000 57.000 m\n37.947 35.292 l\n"
                              + "56.413 48.708 l\n33.587 48.708 l\n"
                              + "52.053 35.292 l\nf\n"
                              + "0.7 g\n15.000 57.000 m\n"
                              + "7.947 35.292 l\n26.413 48.708 l\n"
                              + "3.587 48.708 l\n22.053 35.292 l\nf\n"
                              + "45.000 27.000 m\n37.947 5.292 l\n"
                              + "56.413 18.708 l\n33.587 18.708 l\n"
                              + "52.053 5.292 l\nf";

                p.SetLiteral(star);

                // A Pattern with some text drawing
                p1.SetGrayFill(0.3f);
                p1.SetFontAndSize(bf, 12);
                p1.BeginText();
                p1.SetTextMatrix(1f, 0f, 0f, 1f, 0f, 0f);
                p1.ShowText("A B C D");
                p1.EndText();
                p1.MoveTo(0f, 0f);
                p1.LineTo(60f, 60f);
                p1.Stroke();

                // A pattern with an image and position
                p2.AddImage(img, img.ScaledWidth, 0f, 0f, img.ScaledHeight, 0f, 0f);
                p2.SetPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);

                // See if we can apply the pattern color to chunk, phrase or paragraph
                PatternColor pat  = new PatternColor(p);
                PatternColor pat1 = new PatternColor(p1);
                PatternColor pat2 = new PatternColor(p2);
                String       text = "Text with pattern";
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, new GrayColor(0.3f))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, pat)));

                // draw a rectangle filled with star pattern
                cb.SetPatternFill(p);
                cb.SetGrayStroke(0.0f);
                cb.Rectangle(20, 20, 284, 120);
                cb.FillStroke();

                // draw some characters filled with star.
                // Note: A gray, rgb, cmyk or spot color should be applied first
                // otherwise, you will not be able to see the character glyph
                // since the glyph path is filled by pattern
                cb.BeginText();
                cb.SetFontAndSize(bf, 1);
                cb.SetTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
                cb.SetGrayFill(0.9f);
                cb.ShowText("ABC");
                cb.SetPatternFill(p);
                cb.MoveTextWithLeading(0.0f, 0.0f);
                cb.ShowText("ABC");
                cb.EndText();
                cb.SetPatternFill(p);

                // draw a circle. Similar to rectangle
                cb.SetGrayStroke(0.0f);
                cb.Circle(150f, 400f, 150f);
                cb.FillStroke();

                // New Page to draw text in the pattern painter's canvas
                document.NewPage();

                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, new GrayColor(0.3f))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, pat1)));
                // draw a rectangle
                cb.SetPatternFill(p1);
                cb.SetGrayStroke(0.0f);
                cb.Rectangle(0, 0, 284, 120);
                cb.FillStroke();

                // draw some characters
                cb.BeginText();
                cb.SetFontAndSize(bf, 1);
                cb.SetTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
                cb.SetGrayFill(0.9f);
                cb.ShowText("ABC");
                cb.SetPatternFill(p1);
                cb.MoveTextWithLeading(0.0f, 0.0f);
                cb.ShowText("ABC");
                cb.EndText();

                // draw a circle
                cb.SetPatternFill(p1);
                cb.SetGrayStroke(0.0f);
                cb.Circle(150f, 400f, 150f);
                cb.FillStroke();

                // New page to place image in the pattern painter's canvas
                document.NewPage();
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, new GrayColor(0.3f))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 60, Font.BOLD, pat2)));
                // The original Image for comparison reason.
                // Note: The width and height is the same as bbox in pattern
                cb.AddImage(img, img.ScaledWidth, 0f, 0f, img.ScaledHeight, 350f, 400f);

                // draw a rectangle
                cb.SetPatternFill(p2);
                cb.SetGrayStroke(0.0f);
                cb.Rectangle(60, 60, 300, 120);
                cb.FillStroke();

                // draw some characters.
                // Note: if the image fills up the pattern, there's no need to draw text twice
                // since colors in image will be clipped to character glyph path
                cb.BeginText();
                cb.SetFontAndSize(bf, 1);
                cb.SetTextMatrix(270f, 0f, 0f, 270f, 60f, 120f);
                cb.SetPatternFill(p2);
                cb.ShowText("ABC");
                cb.EndText();

                // draw a circle
                cb.SetPatternFill(p2);
                cb.SetGrayStroke(0.0f);
                cb.Circle(150f, 400f, 150f);
                cb.FillStroke();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }

            // finally, we close the document
            document.Close();
        }
示例#16
0
        private bool CreatePlayersPDF(string outputPDFPath)
        {
            int            bmpIndex;
            float          prec, radius;
            Document       outputDocument = null;
            PdfWriter      pdfWriter      = null;
            PdfReader      templatePDF    = null;
            PdfContentByte contentByte    = null;

            try
            {
                templatePDF = new PdfReader(Application.StartupPath + "//Data//PDF//Ludo_PDF//Ludo_Players.pdf");

                outputDocument = new iTextSharp.text.Document(templatePDF.GetPageSize(1));
                outputDocument.SetMargins(0f, 0f, 0f, 0f);

                // Create the pdf writer
                pdfWriter = PdfWriter.GetInstance(outputDocument, new FileStream(outputPDFPath, FileMode.Create, FileAccess.Write));

                // Open the pdf document
                outputDocument.Open();

                // Draw the corner dots
                contentByte = pdfWriter.DirectContent;

                for (int i = 0; i < 2; i++)
                {
                    // Place players images
                    for (int j = 0; j < 4 * m_images.Length; j++)
                    {
                        bmpIndex = j % m_images.Length;

                        // Scale image
                        prec = PLAYER_IMAGE_WIDTH / m_images[bmpIndex].Width;
                        m_images[bmpIndex].ScalePercent(prec * 100);

                        // Add image
                        m_images[bmpIndex].SetAbsolutePosition(
                            169.2f + (bmpIndex * (m_images[bmpIndex].ScaledWidth + HORIZ_GAP)),
                            678f - ((j / m_images.Length) * (m_images[bmpIndex].ScaledHeight + VERT_GAP)));
                        contentByte.AddImage(m_images[bmpIndex]);
                    }

                    // Set the dots radius
                    radius = 5.5f / 2.0f;

                    // BOTTOM LEFT
                    contentByte.Circle(167.8f + radius, 194.2f + radius, radius);
                    contentByte.Fill();

                    // TOP LEFT
                    contentByte.Circle(171.8f + radius, 812.4f + radius, radius);
                    contentByte.Fill();

                    // TOP RIGHT
                    contentByte.Circle(549.4f + radius, 819.1f + radius, radius);
                    contentByte.Fill();

                    // BOTTOM RIGHT
                    contentByte.Circle(510.7f + radius, 196.8f + radius, radius);
                    contentByte.Fill();

                    if (i + 1 < 2)
                    {
                        outputDocument.NewPage();
                    }
                }

                // Close the document
                outputDocument.Close();
            }
            catch (iTextSharp.text.DocumentException err)
            {
                MessageBox.Show(err.Message, m_cropperForm.m_langDictionary["Create PDF"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
            finally
            {
                // Clean up
                outputDocument = null;
            }


            return(true);
        }
示例#17
0
        public void GuardarFiguras(string nombrePDF, int page)
        {
            Console.WriteLine("Entro a funcion guardar figuras nombrepdf " + nombrePDF);
            string oldFile = nombrePDF;
            string newFile = "C:\\Users\\Denisse\\Desktop\\EDDIE-Augmented-Reading-master\\AugmentedReadingApp\\bin\\x86\\Debug\\temporal.pdf";


            PdfReader reader   = new PdfReader(oldFile);
            var       pageSize = reader.GetPageSize(1);

            Console.WriteLine("Tamano de pagina PDF " + pageSize);
            PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Append));


            PdfContentByte contentunder = stamper.GetUnderContent(1);

            //int rot;
            //rot = reader.GetPageRotation(1);
            //PdfDictionary pageDict;
            //pageDict = reader.GetPageN(1);
            //pageDict.Put(PdfName.ROTATE, new PdfNumber(rot + 90));


            float incremento = 130;

            foreach (var item in rect)
            {
                //float center1 = item.X+(item.X+item.Width)/2;
                //float center2 = item.Y + (item.Y + item.Height) / 2;
                //RotatedRect aux = new RotatedRect(new PointF(item.X, item.Y), item.Size, 180);
                //PointF[] puntos = aux.GetVertices();
                //float puntoX = puntos[0].X;
                //float puntoY = puntos[0].Y;
                //float tamanoH = item.Size.Height;
                //float tamanoW = item.Size.Width;


                float  porcentaje = (item.Y * 100 / 640);
                double nuevoPtoY  = (porcentaje * (841)) / 100;
                double proporcion = nuevoPtoY / item.Y;
                if (porcentaje < 50)
                {
                    incremento = 0;
                }
                else if (porcentaje > 50 && porcentaje < 80)
                {
                    incremento = 70;
                }
                else
                {
                    incremento = 100;
                }


                contentunder.SetColorStroke(BaseColor.YELLOW);
                ////Antigua coordenada contentunder.Rectangle(item.X - 50, (841 * 0.85) - (nuevoPtoY * proporcion)+incremento, item.Width * 1.3, item.Height * proporcion);
                ////nueva coordenada
                double propX    = ((item.X * 100) / 640);
                double ptoX2    = ((propX * 792) / 100);
                double propY    = ((item.Y * 100) / 480);
                double ptoY2    = ((propY * 612) / 100);
                double propArea = 1.58;
                double propW    = ((item.Width) * 100) / 640;
                double ptoW2    = ((propW * 792) / 100);
                double propH    = ((item.Height * 100) / 480);
                double ptoH2    = ((propH * 612) / 100);
                contentunder.Rectangle(ptoX2 + 30, (612 - ptoY2 - (ptoH2 - 30)), ptoW2 - 30, ptoH2 - 30);

                //contentunder.Rectangle(puntoX, puntoY, tamanoW, tamanoH);
                contentunder.Stroke();
            }

            //Sincronizar circulos
            foreach (var circle in circleList)
            {
                /*double x = circle.Center.X;
                 * double y = circle.Center.Y;
                 * double r = circle.Radius;
                 * double porcentaje = (y * 100 / 640);
                 * double nuevoPtoY = (porcentaje * (841*0.9)) / 100;
                 * double proporcion = nuevoPtoY / y;
                 *
                 * // Setting color to the circle
                 * contentunder.SetColorStroke(BaseColor.MAGENTA);
                 * // creating a circle
                 * contentunder.Circle(x, (841*0.9)-(nuevoPtoY), r*proporcion);*/
                double propX = ((circle.Center.X * 100) / 640);
                double ptoX2 = ((propX * 792) / 100);
                double propY = ((circle.Center.Y * 100) / 480);
                double ptoY2 = ((propY * 612) / 100);
                double r     = circle.Radius;
                // Setting color to the circle
                contentunder.SetColorStroke(BaseColor.MAGENTA);
                // creating a circle
                contentunder.Circle(ptoX2, 612 - ptoY2 - r, r * 1.58);
                // Filling the circ
                //canvas.Fill();
                contentunder.Stroke();
            }


            //Sincronizar elipses y circulos
            foreach (var ellipse in ellipseList)
            {
                System.Drawing.Rectangle rr = ellipse.RotatedRect.MinAreaRect();
                double propLeft             = ((rr.Left * 100) / 640);
                double ptoLeft2             = ((propLeft * 792) / 100);

                double propRight = ((rr.Right * 100) / 640);
                double ptoRight2 = ((propRight * 792) / 100);

                double propBottom = ((rr.Bottom * 100) / 480);
                double ptoBottom2 = ((propBottom * 612) / 100);

                double propTop = ((rr.Top * 100) / 480);
                double ptoTop2 = ((propTop * 612) / 100);

                contentunder.SetColorStroke(BaseColor.GREEN);
                contentunder.Ellipse(ptoLeft2, 612 - ptoBottom2, ptoRight2, 612 - ptoTop2);

                /*double porcentajeB = (rr.Bottom * 100 / 640);
                 * double nuevoPtoB = (porcentajeB * (841)) / 100;
                 * double proporcionB = nuevoPtoB / rr.Bottom;
                 *
                 * double porcentajeT = (rr.Top * 100 / 640);
                 * double nuevoPtoT = (porcentajeT * (841)) / 100;
                 * double proporcionT = nuevoPtoB / rr.Top;
                 *
                 * contentunder.SetColorStroke(BaseColor.GREEN);
                 * contentunder.Ellipse(rr.Left - 50, (841 * 0.9) - (nuevoPtoB), (rr.Right * 1.1) - 80, (841 * 0.9) - (nuevoPtoT));*/
                contentunder.Stroke();
            }

            stamper.Close();
            reader.Close();

            File.Replace(@newFile, oldFile, @"backup.pdf.bac");



            Console.WriteLine("Finalizado");
            //File.Replace(@"temporal.pdf", @"ejemploOK.pdf", @"backup.pdf.bac");
            // MessageBox.Show("Pdf modificado con exito, se ha guardado un backup de la versión anterior ");
            //axAcroPDF1.src = "C:\\Users\\Denisse\\Desktop\\prototipos\\Prototipo4-FigurasFisicoDigital\\Prototipo4-FigurasFisicoDigital\\bin\\Debug\\ejemploOK.pdf";
        }
示例#18
0
        public void ToPDF(iTextSharp.text.pdf.PdfWriter w)
        {
            PdfContentByte cb = w.DirectContent;

            cb.SetLineWidth((float)Settings.Thickness);
            if (Settings.Fill != null)
            {
                cb.SetColorFill(Settings.Fill.ToPDFColor());
            }

            if (Settings.Stroke != null)
            {
                cb.SetColorStroke(Settings.Stroke.ToPDFColor());
            }

            if (Geometry.GetType() == typeof(Dyn.Arc))
            {
                Dyn.Arc arc = Geometry as Dyn.Arc;
                cb.MoveTo(arc.StartPoint.X, arc.EndPoint.Y);
                cb.CurveTo(arc.PointAtParameter(0.5).X, arc.PointAtParameter(0.5).Y, arc.EndPoint.X, arc.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Line))
            {
                Dyn.Line line = Geometry as Dyn.Line;
                cb.MoveTo(line.StartPoint.X, line.StartPoint.Y);
                cb.LineTo(line.EndPoint.X, line.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Circle))
            {
                Dyn.Circle circle = Geometry as Dyn.Circle;
                cb.Circle(circle.CenterPoint.X, circle.CenterPoint.Y, circle.Radius);
            }
            else if (Geometry.GetType() == typeof(Dyn.Ellipse))
            {
                Dyn.Ellipse ellipse = Geometry as Dyn.Ellipse;
                cb.Ellipse(ellipse.StartPoint.X, ellipse.StartPoint.Y, ellipse.EndPoint.X, ellipse.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Rectangle))
            {
                Dyn.Rectangle rect = Geometry as Dyn.Rectangle;
                cb.Rectangle(rect.Center().X, rect.Center().Y, rect.Width, rect.Height);
            }
            else if (Geometry.GetType() == typeof(Dyn.Polygon))
            {
                Dyn.Polygon p = Geometry as Dyn.Polygon;
                foreach (var curve in p.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.PolyCurve))
            {
                Dyn.PolyCurve pc = Geometry as Dyn.PolyCurve;
                foreach (var curve in pc.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.NurbsCurve))
            {
                Dyn.NurbsCurve nc = Geometry as Dyn.NurbsCurve;

                foreach (var linearc in nc.ApproximateWithArcAndLineSegments())
                {
                    CurveToPDF(linearc, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.Curve))
            {
                Dyn.Curve curve = Geometry as Dyn.Curve;
                CurveToPDF(curve, cb);
            }
            else
            {
                throw new Exception(Properties.Resources.NotSupported);
            }

            if (Settings.Fill != null && Settings.Stroke != null)
            {
                cb.FillStroke();
            }
            else
            {
                if (Settings.Stroke != null)
                {
                    cb.Stroke();
                }
                if (Settings.Fill != null)
                {
                    cb.Fill();
                }
            }
        }
示例#19
0
    private static Boolean PrintShape(Shape shape, FrameworkElement relativeTo, PdfContentByte dc)
    {
      var noBorder = Helper.IsNullOrZero(shape.StrokeThickness) || Helper.IsTransparent(shape.Stroke);
      var noBackground = Helper.IsTransparent(shape.Fill);
      if (noBorder && noBackground)
        return true;

      dc.SaveState();

      try
      {
        var clipRect = GetClipRectange(shape, relativeTo);
        if (clipRect != null)
        {
          dc.Rectangle(clipRect.Value.Left, clipRect.Value.Top - clipRect.Value.Height, clipRect.Value.Width, clipRect.Value.Height);
          dc.Clip();
          dc.NewPath();
        }

        dc.SetColorFill(GetBaseColor(shape.Fill));
        dc.SetColorStroke(GetBaseColor(shape.Stroke));
        dc.SetLineWidth(shape.StrokeThickness);
        if (shape.StrokeDashArray != null && shape.StrokeDashArray.Any())
          dc.SetLineDash(shape.StrokeDashArray.Select(p => p * shape.StrokeThickness).ToArray(), 0);

        float left, top;
        if (!GetElementLocation(shape, relativeTo, out left, out top))
          return false;

        var lineGeometry = shape.RenderedGeometry as LineGeometry;
        if (lineGeometry != null)
        {
          var startPoint = shape.RenderedGeometry.Transform.Transform(lineGeometry.StartPoint);
          var endPoint = shape.RenderedGeometry.Transform.Transform(lineGeometry.EndPoint);
          dc.MoveTo(left + startPoint.X, top - startPoint.Y);
          dc.LineTo(left + endPoint.X, top - endPoint.Y);
        }
        var rectangleGeometry = shape.RenderedGeometry as RectangleGeometry;
        if (rectangleGeometry != null)
        {
          if (!rectangleGeometry.Rect.IsNaNOrZeroOrEmpty())
          {
            var bottomLeft = shape.RenderedGeometry.Transform.Transform(rectangleGeometry.Rect.BottomLeft);
            var widthHeight = shape.RenderedGeometry.Transform.Transform(new Point(rectangleGeometry.Rect.Width, rectangleGeometry.Rect.Height));
            dc.Rectangle(left + bottomLeft.X, top - bottomLeft.Y, widthHeight.X, widthHeight.Y);
          }
        }
        var ellipseGeometry = shape.RenderedGeometry as EllipseGeometry;
        if (ellipseGeometry != null)
        {
          var center = shape.RenderedGeometry.Transform.Transform(ellipseGeometry.Center);
          center = new Point(left + center.X, top - center.Y);
          if (Helper.IsNullOrZero(ellipseGeometry.RadiusX) && Helper.IsNullOrZero(ellipseGeometry.RadiusY))
            dc.Circle(center.X, center.Y, 0.01);
          else
          {
            var radius = shape.RenderedGeometry.Transform.Transform(new Point(ellipseGeometry.RadiusX, ellipseGeometry.RadiusY));
            var x1 = (Int32)Math.Max(1, Math.Round(center.X - radius.X));
            var y1 = (Int32)Math.Max(1, Math.Round(center.Y - radius.Y));
            var x2 = (Int32)Math.Max(1, Math.Round(center.X + radius.X));
            var y2 = (Int32)Math.Max(1, Math.Round(center.Y + radius.Y));
            dc.Ellipse(x1, y1, x2, y2);
          }
        }
        var streamGeometry = shape.RenderedGeometry as StreamGeometry;
        if (streamGeometry != null)
        {
          var figures = GeometryDataParser.GetDataFigures(streamGeometry.ToString());
          foreach (var figure in figures)
          {
            if (!figure.Draw(left, top, dc, shape.LayoutTransform))
              break;
          }
        }
        var pathGrometry = shape.RenderedGeometry as PathGeometry;
        if (pathGrometry != null)
        {
          var pathFigure = pathGrometry.Figures.First(p => p != null);
          if (pathFigure != null)
          {
            var points = new List<Point>();
            points.Add(shape.RenderedGeometry.Transform.Transform(pathFigure.StartPoint));

            var lineSegments = pathFigure.Segments.OfType<LineSegment>();
            if (lineSegments != null)
              points.AddRange(lineSegments.Select(p => shape.RenderedGeometry.Transform.Transform(p.Point)));

            var polyLineSegment = pathFigure.Segments.OfType<PolyLineSegment>().FirstOrDefault();
            if (polyLineSegment != null)
              points.AddRange(polyLineSegment.Points.Select(p => shape.RenderedGeometry.Transform.Transform(p)));

            points = points.Select(p => new Point(left + p.X, top - p.Y)).ToList();
            foreach (var point in points)
            {
              if (points.IndexOf(point) == 0)
                dc.MoveTo(point.X, point.Y);
              else
                dc.LineTo(point.X, point.Y);
            }
          }
        }

        if (!noBorder && !noBackground)
          dc.FillStroke();
        else
        {
          if (!noBorder)
            dc.Stroke();
          if (!noBackground)
            dc.Fill();
        }

        return true;
      }
      catch (Exception ex)
      {
        ExceptionHandler.ThrowException(ex);
        return false;
      }
      finally
      {
        dc.RestoreState();
      }
    }
        public void Verify_PathConstructionAndPainting_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfContentByte canvas = writer.DirectContent;

            // draw squares
            createSquares(canvas, 50, 720, 80, 20);
            ColumnText.ShowTextAligned(
                canvas, Element.ALIGN_LEFT,
                new Phrase(
                    "Methods MoveTo(), LineTo(), stroke(), closePathStroke(), Fill(), and closePathFill()"
                    ),
                50, 700, 0
                );
            // draw Bezier curves
            createBezierCurves(canvas, 70, 600, 80, 670, 140, 690, 160, 630, 160);
            ColumnText.ShowTextAligned(
                canvas, Element.ALIGN_LEFT,
                new Phrase("Different CurveTo() methods, followed by stroke()"),
                50, 580, 0
                );
            // draw stars and circles
            createStarsAndCircles(canvas, 50, 470, 40, 20);
            ColumnText.ShowTextAligned(
                canvas, Element.ALIGN_LEFT,
                new Phrase(
                    "Methods Fill(), eoFill(), NewPath(), FillStroke(), and EoFillStroke()"
                    ),
                50, 450, 0
                );
            // draw different shapes using convenience methods
            canvas.SaveState();
            canvas.SetColorStroke(new GrayColor(0.2f));
            canvas.SetColorFill(new GrayColor(0.9f));
            canvas.Arc(50, 270, 150, 330, 45, 270);
            canvas.Ellipse(170, 270, 270, 330);
            canvas.Circle(320, 300, 30);
            canvas.RoundRectangle(370, 270, 80, 60, 20);
            canvas.FillStroke();
            canvas.RestoreState();
            Rectangle rect = new Rectangle(470, 270, 550, 330)
            {
                BorderWidthBottom = 10,
                BorderColorBottom = new GrayColor(0f),
                BorderWidthLeft   = 4,
                BorderColorLeft   = new GrayColor(0.9f),
                BackgroundColor   = new GrayColor(0.4f)
            };

            canvas.Rectangle(rect);
            ColumnText.ShowTextAligned(
                canvas, Element.ALIGN_LEFT,
                new Phrase("Convenience methods"), 50, 250, 0
                );

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#21
0
    public static void DrawPieChart(this PdfContentByte canvas,
                                    PieChart chart,
                                    float x0,
                                    float y0,
                                    float r          = 50f,
                                    Font font        = null,
                                    bool showCaption = true)
    {
        if (chart.Values.Length != chart.Captions.Length)
        {
            return;
        }

        if (font == null)
        {
            font = FontFactory.GetFont(FontFactory.TIMES, 8);
        }

        canvas.SetLineWidth(0f);

        double _x1, _y1, _x2, _y2;
        float  x1, y1, x2, y2;

        canvas.SetLineWidth(1f);
        float cRadius = (float)(r + 0.5);

        canvas.Circle(x0, y0, cRadius);
        canvas.SetColorStroke(BaseColor.GRAY);
        canvas.Stroke();

        canvas.SetLineWidth(0f);
        float rectX1 = x0 - r;
        float rectY1 = y0 - r;

        float xPoint = x0 + r;
        float yPoint = y0 + r;

        //canvas.Rectangle(rectX1, rectY1, 2 * r, 2 * r);
        //canvas.Stroke();

        double _startAngle = 0;
        double _endAngle   = 0;

        float startAngle = 0;
        float endAngle   = 0;

        float  captionY = y0 + (chart.Values.Length - 1) * 6;
        double _percentage;
        string percentage;

        for (int counter = 0; counter < chart.Values.Length; counter++)
        {
            if (chart.TotalValues > 0)
            {
                _percentage = chart.Angles[counter] * 100 / 360;
            }
            else
            {
                _percentage = 0;
            }

            if (showCaption)
            {
                //captions from here
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);
                canvas.Rectangle(x0 + r + 10, captionY, 7, 7);
                canvas.ClosePathFillStroke();

                percentage = string.Format("{0:N}", _percentage);
                ColumnText text2  = new ColumnText(canvas);
                Phrase     phrase = new Phrase(string.Format("{0} ({1}%)", chart.Captions[counter], percentage), font);
                text2.SetSimpleColumn(phrase, x0 + r + 20, captionY, x0 + r + 200, captionY, 0f, 0);
                text2.Go();

                captionY -= 12;
                if (_percentage == 0)
                {
                    continue;
                }
                //end of caption
            }

            if (chart.TotalValues <= 0)
            {
                continue;
            }

            if (_percentage <= 50)
            {
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180);
                _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180);
                x1  = (float)_x1;
                y1  = (float)_y1;

                _endAngle += chart.Angles[counter];
                _x2        = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2        = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2         = (float)_x2;
                y2         = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle   = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, (float)chart.Angles[counter]);
                canvas.ClosePathFillStroke();
                _startAngle += chart.Angles[counter];
            }
            else
            {
                //DO THE FIRST PART
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180);
                _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180);
                x1  = (float)_x1;
                y1  = (float)_y1;

                _endAngle += 180;
                _x2        = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2        = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2         = (float)_x2;
                y2         = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle   = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, 180);
                canvas.ClosePathFillStroke();

                //DO THE SECOND PART
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos((_startAngle + 180) * Math.PI / 180);
                _y1 = y0 + r * Math.Sin((_startAngle + 180) * Math.PI / 180);
                x1  = (float)_x1;
                y1  = (float)_y1;

                _endAngle += chart.Angles[counter] - 180;
                _x2        = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2        = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2         = (float)_x2;
                y2         = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle   = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle + 180, (float)(chart.Angles[counter] - 180));
                canvas.ClosePathFillStroke();

                _startAngle += chart.Angles[counter];
            }
        }
    }
        private void button2_Click(object sender, EventArgs e)
        {
            string oldFile = "opcion2X.pdf";
            string newFile = "temporal.pdf";

            // string oldFile = textBox6.Text;
            //string newFile = "Code2.pdf";

            /* PdfDocument pdfDoc = new PdfDocument(new PdfReader(oldFile), new PdfWriter(newFile));
             * PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage());
             * iText.Kernel.Geom.Rectangle mediabox = pdfDoc.GetPage(1).GetMediaBox();
             * double anchoPDF = mediabox.GetWidth();
             * double altoPDF = mediabox.GetHeight();*/
            //MessageBox.Show("Medidas PDF ancho: "+ anchoPDF + " y alto: "+ altoPDF);
            //Sincronizar rectangulos
            //float incremento = 130;
            //Bitmap bmp = new Bitmap(1000, 1000, PixelFormat.Format32bppArgb);

            /* MemoryStream ms = new MemoryStream();
             * bmp.Save(ms, ImageFormat.Png);
             * byte[] bmpBytes = ms.ToArray();
             * ImageData data = ImageDataFactory.Create( bmpBytes);
             *
             *
             * canvas.AddImage(data,100,500,false);*/


            /*
             * foreach (var item in rect)
             * {
             *
             *
             *  float porcentaje = (item.Y * 100 / 640);
             *  double nuevoPtoY = (porcentaje * (841)) / 100;
             *  double proporcion = nuevoPtoY / item.Y;
             *  if (porcentaje < 50)
             *  {
             *      incremento = 0;
             *  }
             *  else if (porcentaje > 50 && porcentaje < 80)
             *  {
             *      incremento = 70;
             *  }
             *  else
             *  {
             *      incremento = 100;
             *  }
             *
             *
             *      //El x estaba con -50
             *  canvas.SetStrokeColor(new DeviceRgb(0, 0, 255))
             *          .SetLineWidth(2)
             *          .Rectangle(item.X-80, (841*0.9)-(nuevoPtoY*proporcion), item.Width*1.3, item.Height*proporcion)
             *          .Stroke();
             * }
             */
            //Sincronizar triangulos

            /*foreach (var triangle in triangleList)
             * {
             *  canvas.SetStrokeColor(new DeviceRgb(0, 0, 255));
             *  PointF[] vertices = triangle.GetVertices();
             *  MessageBox.Show("estos son los vertices 0: " + vertices[0] + " 1: " +vertices[1] + " 2:" + vertices[2]);
             *  double area = triangle.Area;
             *  double h = (2 * area / (vertices[0].X - vertices[2].X));
             *  MessageBox.Show("esto es el area y esto el h "+area+ " " + h);
             *  double x = (vertices[2].X+(vertices[0].X - vertices[2].X));
             *  double y = vertices[2].Y;
             *  canvas.MoveTo(x, y);
             *  canvas.LineTo(vertices[1].X, (vertices[1].Y+(h*2)));
             *  canvas.LineTo((vertices[0].X-(vertices[0].X - vertices[2].X)), vertices[0].Y);
             *  canvas.Stroke();
             * }*/

            //Sincronizar circulos

            /*  foreach (var circle in circleList)
             * {
             *    double x = circle.Center.X;
             *    double y = circle.Center.Y;
             *    double r = circle.Radius;
             *    double porcentaje = (y * 100 / 640);
             *    double nuevoPtoY = (porcentaje * (841*0.9)) / 100;
             *    double proporcion = nuevoPtoY / y;
             *    // Setting color to the circle
             *    canvas.SetStrokeColor(new DeviceRgb(0, 255, 0));
             *    // creating a circle
             *    canvas.Circle(x-50, (841*0.9)-(nuevoPtoY), r*proporcion);
             *
             *    // Filling the circ
             *    //canvas.Fill();
             *    canvas.Stroke();
             * }*/


            //Sincronizar elipses y circulos

            /* foreach (var ellipse in ellipseList)
             * {
             *   System.Drawing.Rectangle rr = ellipse.RotatedRect.MinAreaRect();
             *   double porcentajeB = (rr.Bottom * 100 / 640);
             *   double nuevoPtoB = (porcentajeB * (841)) / 100;
             *   double proporcionB = nuevoPtoB / rr.Bottom;
             *
             *   double porcentajeT = (rr.Top * 100 / 640);
             *   double nuevoPtoT = (porcentajeT * (841)) / 100;
             *   double proporcionT = nuevoPtoB / rr.Top;
             *
             *   canvas.SetStrokeColor(new DeviceRgb(255, 0, 255))
             *
             *       .Ellipse( rr.Left-80, (841*0.9)-(nuevoPtoB), (rr.Right*1.1)-80, (841*0.9)-(nuevoPtoT))
             *       .Stroke();
             * }
             *
             *
             *   pdfDoc.Close();
             */



            PdfReader reader   = new PdfReader(oldFile);
            var       pageSize = reader.GetPageSize(1);

            Console.WriteLine("Tamano de pagina PDF " + pageSize);
            PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Append));


            PdfContentByte contentunder = stamper.GetUnderContent(1);

            //int rot;
            //rot = reader.GetPageRotation(1);
            //PdfDictionary pageDict;
            //pageDict = reader.GetPageN(1);
            //pageDict.Put(PdfName.ROTATE, new PdfNumber(rot + 90));


            float incremento = 130;

            foreach (var item in rect)
            {
                //float center1 = item.X+(item.X+item.Width)/2;
                //float center2 = item.Y + (item.Y + item.Height) / 2;
                //RotatedRect aux = new RotatedRect(new PointF(item.X, item.Y), item.Size, 180);
                //PointF[] puntos = aux.GetVertices();
                //float puntoX = puntos[0].X;
                //float puntoY = puntos[0].Y;
                //float tamanoH = item.Size.Height;
                //float tamanoW = item.Size.Width;


                float  porcentaje = (item.Y * 100 / 640);
                double nuevoPtoY  = (porcentaje * (841)) / 100;
                double proporcion = nuevoPtoY / item.Y;
                if (porcentaje < 50)
                {
                    incremento = 0;
                }
                else if (porcentaje > 50 && porcentaje < 80)
                {
                    incremento = 70;
                }
                else
                {
                    incremento = 100;
                }

                MessageBox.Show("Info rectangulo real : " + item.X + ", puntoY : " + item.Y + ", tamanoH : " + item.Height + ", tamanoW : " + item.Width);

                contentunder.SetColorStroke(BaseColor.YELLOW);
                ////Antigua coordenada contentunder.Rectangle(item.X - 50, (841 * 0.85) - (nuevoPtoY * proporcion)+incremento, item.Width * 1.3, item.Height * proporcion);
                ////nueva coordenada
                double propX    = ((item.X * 100) / 640);
                double ptoX2    = ((propX * 792) / 100);
                double propY    = ((item.Y * 100) / 480);
                double ptoY2    = ((propY * 612) / 100);
                double propArea = 1.58;
                double propW    = ((item.Width) * 100) / 640;
                double ptoW2    = ((propW * 792) / 100);
                double propH    = ((item.Height * 100) / 480);
                double ptoH2    = ((propH * 612) / 100);
                contentunder.Rectangle(ptoX2 + 30, (612 - ptoY2 - (ptoH2 - 30)), ptoW2 - 30, ptoH2 - 30);

                //contentunder.Rectangle(puntoX, puntoY, tamanoW, tamanoH);
                contentunder.Stroke();
            }

            //Sincronizar circulos
            foreach (var circle in circleList)
            {
                /*double x = circle.Center.X;
                 * double y = circle.Center.Y;
                 * double r = circle.Radius;
                 * double porcentaje = (y * 100 / 640);
                 * double nuevoPtoY = (porcentaje * (841*0.9)) / 100;
                 * double proporcion = nuevoPtoY / y;
                 *
                 * // Setting color to the circle
                 * contentunder.SetColorStroke(BaseColor.MAGENTA);
                 * // creating a circle
                 * contentunder.Circle(x, (841*0.9)-(nuevoPtoY), r*proporcion);*/
                double propX = ((circle.Center.X * 100) / 640);
                double ptoX2 = ((propX * 792) / 100);
                double propY = ((circle.Center.Y * 100) / 480);
                double ptoY2 = ((propY * 612) / 100);
                double r     = circle.Radius;
                // Setting color to the circle
                contentunder.SetColorStroke(BaseColor.MAGENTA);
                // creating a circle
                contentunder.Circle(ptoX2, 612 - ptoY2 - r, r * 1.58);
                // Filling the circ
                //canvas.Fill();
                contentunder.Stroke();
            }


            //Sincronizar elipses y circulos
            foreach (var ellipse in ellipseList)
            {
                System.Drawing.Rectangle rr = ellipse.RotatedRect.MinAreaRect();
                double propLeft             = ((rr.Left * 100) / 640);
                double ptoLeft2             = ((propLeft * 792) / 100);

                double propRight = ((rr.Right * 100) / 640);
                double ptoRight2 = ((propRight * 792) / 100);

                double propBottom = ((rr.Bottom * 100) / 480);
                double ptoBottom2 = ((propBottom * 612) / 100);

                double propTop = ((rr.Top * 100) / 480);
                double ptoTop2 = ((propTop * 612) / 100);

                contentunder.SetColorStroke(BaseColor.GREEN);
                contentunder.Ellipse(ptoLeft2, 612 - ptoBottom2, ptoRight2, 612 - ptoTop2);

                /*double porcentajeB = (rr.Bottom * 100 / 640);
                 * double nuevoPtoB = (porcentajeB * (841)) / 100;
                 * double proporcionB = nuevoPtoB / rr.Bottom;
                 *
                 * double porcentajeT = (rr.Top * 100 / 640);
                 * double nuevoPtoT = (porcentajeT * (841)) / 100;
                 * double proporcionT = nuevoPtoB / rr.Top;
                 *
                 * contentunder.SetColorStroke(BaseColor.GREEN);
                 * contentunder.Ellipse(rr.Left - 50, (841 * 0.9) - (nuevoPtoB), (rr.Right * 1.1) - 80, (841 * 0.9) - (nuevoPtoT));*/
                contentunder.Stroke();
            }

            stamper.Close();
            reader.Close();

            File.Replace(@newFile, oldFile, @"backup.pdf.bac");

            //File.Replace(@"temporal.pdf", @"ejemploOK.pdf", @"backup.pdf.bac");
            MessageBox.Show("Pdf modificado con exito, se ha guardado un backup de la versión anterior ");
            axAcroPDF1.src = "C:\\Users\\Denisse\\Desktop\\prototipos\\Prototipo4-FigurasFisicoDigital\\Prototipo4-FigurasFisicoDigital\\bin\\Debug\\opcion2X.pdf";
        }