Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

            Document document = new Document();

            /* chapter06/PdfPTableSplit.java */
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Graphics.pdf", FileMode.Create));

            document.Open();

            /* chapter10/InvisibleRectangles.java */
            PdfContentByte cb = writer.DirectContent;

            cb.MoveTo(30, 700);
            cb.LineTo(490, 700);
            cb.LineTo(490, 800);
            cb.LineTo(30, 800);
            cb.ClosePath();
            cb.Stroke();
            //cb.Rectangle(30, 700, 460, 100);
            //cb.Stroke();

            document.Close();

            webBrowser1.Navigate(string.Concat(appPath, "\\", @"Graphics.pdf"));
        }
Esempio n. 2
0
 public void StrokeAndFill(){
     MetaPen pen = state.CurrentPen;
     MetaBrush brush = state.CurrentBrush;
     int penStyle = pen.Style;
     int brushStyle = brush.Style;
     if (penStyle == MetaPen.PS_NULL) {
         cb.ClosePath();
         if (state.PolyFillMode == MetaState.ALTERNATE) {
             cb.EoFill();
         }
         else {
             cb.Fill();
         }
     }
     else {
         bool isBrush = (brushStyle == MetaBrush.BS_SOLID || (brushStyle == MetaBrush.BS_HATCHED && state.BackgroundMode == MetaState.OPAQUE));
         if (isBrush) {
             if (state.PolyFillMode == MetaState.ALTERNATE)
                 cb.ClosePathEoFillStroke();
             else
                 cb.ClosePathFillStroke();
         }
         else {
             cb.ClosePathStroke();
         }
     }
 }
Esempio n. 3
0
        protected override void Draw(PdfContentByte cb)
        {
            //TODO check the line width with this rectangles SVG takes 5 pixel out and 5 pixels in when asking line-width=10
            //TODO check the values for rx and ry what if they get to big

            if (rx == 0 || ry == 0)
            {
                cb.Rectangle(x, y, width, height);
            }
            else
            { //corners
              /*
               *
               * if(rx > x / 2){
               *  rx = x/2;
               * }
               * if(ry > y / 2){
               *  ry = y/2;
               * }*/

                cb.MoveTo(x + rx, y);
                cb.LineTo(x + width - rx, y);
                Arc(x + width - 2 * rx, y, x + width, y + 2 * ry, -90, 90, cb);
                cb.LineTo(x + width, y + height - ry);
                Arc(x + width, y + height - 2 * ry, x + width - 2 * rx, y + height, 0, 90, cb);
                cb.LineTo(x + rx, y + height);
                Arc(x + 2 * rx, y + height, x, y + height - 2 * ry, 90, 90, cb);
                cb.LineTo(x, y + ry);
                Arc(x, y + 2 * ry, x + 2 * rx, y, 180, 90, cb);
                cb.ClosePath();
            }
        }
Esempio n. 4
0
// ---------------------------------------------------------------------------

        /**
         * Creates a path for a five pointed star.
         * This method doesn't fill or stroke the star!
         * @param canvas the canvas for which the star is constructed
         * @param x      the X coordinate of the center of the star
         * @param y      the Y coordinate of the center of the star
         */
        public static void CreateStar(PdfContentByte canvas, float x, float y)
        {
            canvas.MoveTo(x + 10, y);
            canvas.LineTo(x + 80, y + 60);
            canvas.LineTo(x, y + 60);
            canvas.LineTo(x + 70, y);
            canvas.LineTo(x + 40, y + 90);
            canvas.ClosePath();
        }
Esempio n. 5
0
// ---------------------------------------------------------------------------

        /**
         * Draws the time table for a day at the film festival.
         * @param directcontent a canvas to which the time table has to be drawn.
         */
        protected void DrawTimeTable(PdfContentByte directcontent)
        {
            directcontent.SaveState();
            directcontent.SetLineWidth(1.2f);
            float llx, lly, urx, ury;

            llx = OFFSET_LEFT;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LEFT + WIDTH;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePath();
            directcontent.Stroke();

            llx = OFFSET_LOCATION;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LOCATION + WIDTH_LOCATION;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePathStroke();

            directcontent.SetLineWidth(1);
            directcontent.MoveTo(
                OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM
                );
            directcontent.LineTo(
                OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM + HEIGHT
                );
            float y;

            for (int i = 1; i < LOCATIONS; i++)
            {
                y = OFFSET_BOTTOM + (i * HEIGHT_LOCATION);
                if (i == 2 || i == 6)
                {
                    directcontent.MoveTo(OFFSET_LOCATION, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                else
                {
                    directcontent.MoveTo(OFFSET_LOCATION + WIDTH_LOCATION / 2, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                directcontent.MoveTo(OFFSET_LEFT, y);
                directcontent.LineTo(OFFSET_LEFT + WIDTH, y);
            }
            directcontent.Stroke();
            directcontent.RestoreState();
        }
Esempio n. 6
0
        private void AddColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation)
        {
            Rectangle cleanUpRegion = cleanUpLocation.Region;

            canvas.SaveState();
            canvas.SetColorFill(cleanUpLocation.CleanUpColor);
            canvas.MoveTo(cleanUpRegion.Left, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Top);
            canvas.LineTo(cleanUpRegion.Left, cleanUpRegion.Top);
            canvas.ClosePath();
            canvas.Fill();
            canvas.RestoreState();
        }
Esempio n. 7
0
        private void CreatePDFFile(PolygonApiModel polygon, string folderPath)
        {
            PdfContentByte cb     = null;
            Document       doc    = null;
            var            points = JsonConvert.DeserializeObject <List <Point> >(polygon.Points);

            points = ConvertCordinations(points);
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {
                doc = new Document();
                var writer = PdfWriter.GetInstance(doc, new FileStream(folderPath + "/" + polygon.Name + "-" + polygon.PolygonID + ".pdf", FileMode.Create));
                doc.Open();

                cb = writer.DirectContent;
                int index = 0;
                foreach (var point in points)
                {
                    if (doc.PageSize.Height > point.Latitude && doc.PageSize.Width > point.Longitude)
                    {
                        if (index == 0)
                        {
                            cb.MoveTo(point.Longitude, doc.PageSize.Height - point.Latitude);
                        }
                        else
                        {
                            cb.LineTo(point.Longitude, doc.PageSize.Height - point.Latitude);
                        }
                        index++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cb.ClosePath();
                cb.Stroke();
                doc.Close();
            }
        }
Esempio n. 8
0
        void DrawElement(PdfContentByte cb)
        {
            try
            {
                IList <PathItem> translatedItems = Translate(path.PathItems);

                //loop over the items in the path
                foreach (PathItem item in translatedItems)
                {
                    IList <float> numbers = item.Coordinates;

                    if (item.IsMoveTo())
                    {
                        cb.MoveTo(numbers[0], numbers[1]);
                    }
                    else if (item.IsLineTo())
                    {
                        cb.LineTo(numbers[0], numbers[1]);
                    }
                    else if (item.IsCubicBezier())
                    {
                        cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
                    }
                    else if (item.IsQuadraticBezier())
                    {
                        cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3]);
                    }
                    else if (item.IsArcTo())
                    {
                        DrawArc(cb, numbers);
                    }
                    else if (item.IsClosePath())
                    {
                        cb.ClosePath();
                    }
                    else
                    {
                        //System.out.Println(item);
                    }
                }
            } catch {
                //TODO
            }
        }
        public void StrokeAndFill()
        {
            var pen        = _state.CurrentPen;
            var brush      = _state.CurrentBrush;
            var penStyle   = pen.Style;
            var brushStyle = brush.Style;

            if (penStyle == MetaPen.PS_NULL)
            {
                Cb.ClosePath();
                if (_state.PolyFillMode == MetaState.Alternate)
                {
                    Cb.EoFill();
                }
                else
                {
                    Cb.Fill();
                }
            }
            else
            {
                var isBrush = (brushStyle == MetaBrush.BS_SOLID || (brushStyle == MetaBrush.BS_HATCHED && _state.BackgroundMode == MetaState.Opaque));
                if (isBrush)
                {
                    if (_state.PolyFillMode == MetaState.Alternate)
                    {
                        Cb.ClosePathEoFillStroke();
                    }
                    else
                    {
                        Cb.ClosePathFillStroke();
                    }
                }
                else
                {
                    Cb.ClosePathStroke();
                }
            }
        }
Esempio n. 10
0
 public void closePath()
 {
     m_canvas.ClosePath();
 }
Esempio n. 11
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //TODO: THIS WILL BE DRIVEN BY A FORM FILLED BY THE USER TO ADD ITEMS FOR THE TEAM TO CHECK
            String[] LANGUAGES_gc = { "Scac", "Master Bill", "Comm Inv No", "Test Item", "Another" };

            System.IO.FileStream fs = new FileStream(@"C:\Users\abuchanan.LII01\Desktop\First PDF document.pdf", FileMode.Create);

            // Create an instance of the document class which represents the PDF document itself.
            Document document = new Document(PageSize.A4, 25, 25, 30, 30);
            // Create an instance to the PDF file by creating an instance of the PDF
            // Writer class using the document and the filestrem in the constructor.

            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            // Add meta information to the document

            document.AddAuthor("Anthony Buchanan");

            document.AddKeywords("USeTeam EDI - Operations Team Testing Signoff");

            document.AddSubject("Document subject - Describing the steps creating a PDF document");

            document.AddTitle("The document title - PDF creation using iTextSharp");

            // Open the document to enable you to write to the document

            document.Open();
            PdfContentByte cb = writer.DirectContent;
            //TextField _text = new TextField(writer, new Rectangle(40, 806, 160, 788), "g1");
            //_text.Alignment = Element.ALIGN_LEFT;
            //_text.Options = TextField.MULTILINE;
            //_text.Text = "abc";
            //writer.AddAnnotation(_text.GetTextField());

            Rectangle    _rect;
            PdfFormField _Field1;
            PdfFormField _Field2;

            PdfAppearance[] onOff = new PdfAppearance[3];
            onOff[0] = cb.CreateAppearance(20, 20);
            onOff[0].Rectangle(1, 1, 18, 18);
            onOff[0].Stroke();

            //Pass Checkbox
            onOff[1] = cb.CreateAppearance(20, 20);
            onOff[1].SetRGBColorFill(0, 252, 0);
            onOff[1].Rectangle(1, 1, 18, 18);
            onOff[1].FillStroke();
            onOff[1].MoveTo(1, 1);
            onOff[1].LineTo(19, 19);
            onOff[1].MoveTo(1, 19);
            onOff[1].LineTo(19, 1);
            onOff[1].Stroke();

            //Fail Checkbox
            onOff[2] = cb.CreateAppearance(20, 20);
            onOff[2].SetRGBColorFill(252, 0, 0);
            onOff[2].Rectangle(1, 1, 18, 18);
            onOff[2].FillStroke();
            onOff[2].MoveTo(1, 1);
            onOff[2].LineTo(19, 19);
            onOff[2].MoveTo(1, 19);
            onOff[2].LineTo(19, 1);
            onOff[2].Stroke();

            RadioCheckField _checkbox1;
            RadioCheckField _checkbox2;

            document.Add(new Paragraph("Pass   Fail  Field Name                                  Comments"));

            //Header Line
            cb.MoveTo(20f, 807f);
            cb.LineTo(560f, 807f);
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(20f, 791f);
            cb.LineTo(560f, 791f);
            cb.ClosePath();
            cb.Stroke();

            for (int i = 0; i < LANGUAGES_gc.Length; i++)
            {
                _rect      = new Rectangle(30, 789 - i * 20, 50, 771 - i * 20);
                _checkbox1 = new RadioCheckField(writer, _rect, LANGUAGES_gc[i], "on");
                _Field1    = _checkbox1.CheckField;
                _Field1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
                _Field1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1]);
                writer.AddAnnotation(_Field1);

                _rect      = new Rectangle(60, 789 - i * 20, 80, 771 - i * 20);
                _checkbox2 = new RadioCheckField(writer, _rect, LANGUAGES_gc[i], "on");
                _Field2    = _checkbox2.CheckField;
                _Field2.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
                _Field2.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[2]);
                writer.AddAnnotation(_Field2);

                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(LANGUAGES_gc[i], new Font(Font.FontFamily.HELVETICA, 12)), 90, 775 - i * 20, 0);

                TextField _text = new TextField(writer, new Rectangle(260, 789 - i * 20, 560, 771 - i * 20), "NoteBox");
                _text.Alignment = Element.ALIGN_LEFT;
                _text.Text      = "Add Notes here.";
                _text.SetExtraMargin(5, 0);
                writer.AddAnnotation(_text.GetTextField());

                cb.MoveTo(20f, 770 - i * 20);
                cb.LineTo(560f, 770 - i * 20);
                cb.ClosePath();
                cb.Stroke();
            }

            //TODO: ADD LOGIC IN CASE THERE ARE NO ITEMS ENTERED.

            //Column Lines

            cb.MoveTo(20f, 807f);
            cb.LineTo(20f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(55f, 807f);
            cb.LineTo(55f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(85f, 807f);
            cb.LineTo(85f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(259f, 807f);
            cb.LineTo(259f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(560f, 807f);
            cb.LineTo(560f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb = writer.DirectContent;

            document.Close();
            writer.Close();
            fs.Close();
        }
Esempio n. 12
0
 public Boolean Draw(float left, float top, PdfContentByte dc, Transform transform)
 {
     dc.ClosePath();
     return(true);
 }