示例#1
0
        virtual 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();
                }
            }
        }
示例#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();
                }
            }
        }
示例#3
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
                Type3Font      t3 = new Type3Font(writer, true);
                PdfContentByte d  = t3.DefineGlyph('D', 600, 0, 0, 600, 700);
                d.SetColorStroke(new BaseColor(0xFF, 0x00, 0x00));
                d.SetColorFill(new GrayColor(0.7f));
                d.SetLineWidth(100);
                d.MoveTo(5, 5);
                d.LineTo(300, 695);
                d.LineTo(595, 5);
                d.ClosePathFillStroke();
                PdfContentByte s = t3.DefineGlyph('S', 600, 0, 0, 600, 700);
                s.SetColorStroke(new BaseColor(0x00, 0x80, 0x80));
                s.SetLineWidth(100);
                s.MoveTo(595, 5);
                s.LineTo(5, 5);
                s.LineTo(300, 350);
                s.LineTo(5, 695);
                s.LineTo(595, 695);
                s.Stroke();
                Font      f = new Font(t3, 12);
                Paragraph p = new Paragraph();
                p.Add("This is a String with a Type3 font that contains a fancy Delta (");
                p.Add(new Chunk("D", f));
                p.Add(") and a custom Sigma (");
                p.Add(new Chunk("S", f));
                p.Add(").");
                document.Add(p);
            }
        }
示例#4
0
// ---------------------------------------------------------------------------

        /**
         * Draws a row of squares.
         * @param canvas the canvas to which the squares have to be drawn
         * @param x      X coordinate to position the row
         * @param y      Y coordinate to position the row
         * @param side   the side of the square
         * @param gutter the space between the squares
         */
        public void CreateSquares(PdfContentByte canvas,
                                  float x, float y, float side, float gutter)
        {
            canvas.SaveState();
            canvas.SetColorStroke(new GrayColor(0.2f));
            canvas.SetColorFill(new GrayColor(0.9f));
            canvas.MoveTo(x, y);
            canvas.LineTo(x + side, y);
            canvas.LineTo(x + side, y + side);
            canvas.LineTo(x, y + side);
            canvas.Stroke();
            x = x + side + gutter;
            canvas.MoveTo(x, y);
            canvas.LineTo(x + side, y);
            canvas.LineTo(x + side, y + side);
            canvas.LineTo(x, y + side);
            canvas.ClosePathStroke();
            x = x + side + gutter;
            canvas.MoveTo(x, y);
            canvas.LineTo(x + side, y);
            canvas.LineTo(x + side, y + side);
            canvas.LineTo(x, y + side);
            canvas.Fill();
            x = x + side + gutter;
            canvas.MoveTo(x, y);
            canvas.LineTo(x + side, y);
            canvas.LineTo(x + side, y + side);
            canvas.LineTo(x, y + side);
            canvas.FillStroke();
            x = x + side + gutter;
            canvas.MoveTo(x, y);
            canvas.LineTo(x + side, y);
            canvas.LineTo(x + side, y + side);
            canvas.LineTo(x, y + side);
            canvas.ClosePathFillStroke();
            canvas.RestoreState();
        }
        public void RenderText(TextRenderInfo renderInfo)
        {
            var text = renderInfo.GetText();

            var match = Regex.Match(text, _matchPattern);

            if (match.Success)
            {
                var p1 = renderInfo.GetCharacterRenderInfos()[match.Index].GetAscentLine().GetStartPoint();
                var p2 = renderInfo.GetCharacterRenderInfos()[match.Index + match.Length].GetAscentLine().GetEndPoint();
                var p3 = renderInfo.GetCharacterRenderInfos()[match.Index + match.Length].GetDescentLine().GetEndPoint();
                var p4 = renderInfo.GetCharacterRenderInfos()[match.Index].GetDescentLine().GetStartPoint();

                _canvas.SaveState();
                _canvas.SetColorStroke(BaseColor.BLACK);
                _canvas.SetColorFill(BaseColor.BLACK);
                _canvas.MoveTo(p1[Vector.I1], p1[Vector.I2]);
                _canvas.LineTo(p2[Vector.I1], p2[Vector.I2]);
                _canvas.LineTo(p3[Vector.I1], p3[Vector.I2]);
                _canvas.LineTo(p4[Vector.I1], p4[Vector.I2]);
                _canvas.ClosePathFillStroke();
                _canvas.RestoreState();
            }
        }
示例#6
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];
            }
        }
    }
        /* a method that save the packing slip pdf */
        public static void CreatePackingSlip(GiantTigerValues value, int[] cancelIndex, bool preview)
        {
            // the case if all of the items in the order are cancelled -> don't need to print the packing slip
            if (cancelIndex.Length >= value.VendorSku.Count)
            {
                return;
            }

            // first check if the save directory exist -> if not create it
            if (!File.Exists(SavePath))
            {
                Directory.CreateDirectory(SavePath);
            }

            // initialize fields
            Document  doc    = new Document(PageSize.LETTER, 0, 0, 0, 0);
            string    file   = SavePath + "\\" + value.PoNumber + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create));

            // open the documents
            doc.Open();
            PdfContentByte contentByte = writer.DirectContent;
            PdfContentByte draw        = writer.DirectContent;

            #region Logo and Barcode Set Up
            // add giant tiger logo
            Image logo = Image.GetInstance(Properties.Resources.giantTigerPackSlip, System.Drawing.Imaging.ImageFormat.Png);
            logo.ScalePercent(20f);
            logo.SetAbsolutePosition(40f, doc.PageSize.Height - 100f);
            doc.Add(logo);

            // add barcode
            Barcode39 barcode39 = new Barcode39
            {
                Code          = value.OmsOrderNumber,
                StartStopText = false,
                Font          = null,
                Extended      = true
            };

            Image image = barcode39.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK);
            image.ScaleAbsoluteHeight(40f);
            image.SetAbsolutePosition(340f, doc.PageSize.Height - 80f);
            contentByte.AddImage(image);
            #endregion

            // initialize local fields for text
            BaseFont   baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
            BaseFont   boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false);
            CMYKColor  white    = new CMYKColor(0f, 0f, 0f, 0f);
            CMYKColor  black    = new CMYKColor(0f, 0f, 0f, 1f);
            ColumnText ct       = new ColumnText(draw);

            #region Sold To
            // sold to
            Phrase text = new Phrase("SOLD TO / VENDU A", new Font(boldFont, 10));
            ct.SetSimpleColumn(text, 40f, 655f, 200f, 670f, 0f, Element.ALIGN_LEFT);
            ct.Go();

            // sold to address
            text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada",
                              new Font(baseFont, 9));
            ct.SetSimpleColumn(text, 42f, 568f, 177f, 668f, 10f, Element.ALIGN_LEFT);
            ct.Go();
            #endregion

            #region Ship To
            // ship to
            text = new Phrase("SHIP TO / EXPEDIE A", new Font(boldFont, 10f));
            ct.SetSimpleColumn(text, 300f, 655f, 450f, 670f, 0f, Element.ALIGN_LEFT);
            ct.Go();

            // ship to address
            text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada\n"
                              + value.ShipTo.DayPhone, new Font(baseFont, 9f));
            ct.SetSimpleColumn(text, 302f, 568f, 447f, 668f, 10f, Element.ALIGN_LEFT);
            ct.Go();
            #endregion

            #region Draw First Box
            draw.SetColorFill(black);
            draw.MoveTo(40f, 580f);
            draw.LineTo(doc.PageSize.Width - 40f, 580f);
            draw.LineTo(doc.PageSize.Width - 40f, 543f);
            draw.LineTo(40f, 543f);
            draw.LineTo(40f, 580f);
            draw.ClosePathFillStroke();

            draw.SetColorStroke(white);
            draw.MoveTo(160f, 580f);
            draw.LineTo(160f, 543f);
            draw.Stroke();

            draw.MoveTo(280f, 580f);
            draw.LineTo(280f, 543f);
            draw.Stroke();

            draw.MoveTo(320f, 580f);
            draw.LineTo(320f, 543f);
            draw.Stroke();

            draw.MoveTo(500f, 580f);
            draw.LineTo(500f, 543f);
            draw.Stroke();

            draw.SetColorStroke(black);
            draw.MoveTo(40f, 543f);
            draw.LineTo(40f, 530f);
            draw.Stroke();

            draw.MoveTo(40f, 530f);
            draw.LineTo(doc.PageSize.Width - 40f, 530f);
            draw.Stroke();

            draw.MoveTo(doc.PageSize.Width - 40f, 530f);
            draw.LineTo(doc.PageSize.Width - 40f, 543f);
            draw.Stroke();

            draw.MoveTo(160f, 543f);
            draw.LineTo(160f, 530f);
            draw.Stroke();

            draw.MoveTo(280f, 543f);
            draw.LineTo(280f, 530f);
            draw.Stroke();

            draw.MoveTo(320f, 543f);
            draw.LineTo(320f, 530f);
            draw.Stroke();

            draw.MoveTo(500f, 543f);
            draw.LineTo(500f, 530f);
            draw.Stroke();
            #endregion

            #region Messgae in First Box
            text = new Phrase("SHIPPING METHOD \\\nMODE D'EXPEDITION", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 40f, 550f, 160f, 580f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("ORDER DATE \\\nDATE DE LA\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 160f, 540f, 280f, 580f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("PAGE", new Font(boldFont, 10, Font.NORMAL, new CMYKColor(0f, 0f, 0f, 0f)));
            ct.SetSimpleColumn(text, 280f, 550f, 320f, 580f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("ORDER NUMBER \\\nNUMERO DE COMMANDE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 320f, 550f, 500f, 580f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("PO NUMBER \\\nBON DE\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 500f, 540f, doc.PageSize.Width - 40f, 580f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("Canada Post Ground", new Font(baseFont, 10));
            ct.SetSimpleColumn(text, 40f, 523f, 160f, 533f, 0f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase(value.OrderDate.ToString("MM/dd/yyyy"), new Font(baseFont, 10));
            ct.SetSimpleColumn(text, 160f, 523f, 280f, 533f, 0f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("1 of 1", new Font(baseFont, 10));
            ct.SetSimpleColumn(text, 280f, 523f, 320f, 533f, 0f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase(value.WebOrderNo, new Font(baseFont, 10));
            ct.SetSimpleColumn(text, 320f, 523f, 500f, 533f, 0f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase(value.PoNumber, new Font(baseFont, 10));
            ct.SetSimpleColumn(text, 500f, 523f, doc.PageSize.Width - 40f, 533f, 0f, Element.ALIGN_CENTER);
            ct.Go();
            #endregion

            #region Draw Second Box
            draw.MoveTo(40f, 520f);
            draw.LineTo(doc.PageSize.Width - 40f, 520f);
            draw.LineTo(doc.PageSize.Width - 40f, 483f);
            draw.LineTo(40f, 483f);
            draw.LineTo(40f, 520f);
            draw.ClosePathFillStroke();

            draw.SetColorStroke(white);
            draw.MoveTo(130f, 520f);
            draw.LineTo(130f, 483f);
            draw.Stroke();

            draw.MoveTo(220f, 520f);
            draw.LineTo(220f, 483f);
            draw.Stroke();

            draw.MoveTo(400f, 520f);
            draw.LineTo(400f, 483f);
            draw.Stroke();

            draw.MoveTo(480f, 520f);
            draw.LineTo(480f, 483f);
            draw.Stroke();
            #endregion

            #region Message in Second Box
            text = new Phrase("QTY ORDERED \\\nQTE\nCOMMANDEE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 40f, 480f, 130f, 520f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("ITEM \\\nARTICLE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 130f, 480f, 220f, 520f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("DESCRIPTION", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 220f, 480f, 400f, 520f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("QTY SHIPPED \\\nQTE EXPEDIEE", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 400f, 480f, 480f, 520f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            text = new Phrase("VENDOR SKU \\\nNO D'ARTICLE DU\nFOURNISSEUR", new Font(boldFont, 10, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 480f, 480f, doc.PageSize.Width - 40f, 520f, 11f, Element.ALIGN_CENTER);
            ct.Go();

            // item addition
            draw.SetColorStroke(black);
            draw.SetLineWidth(0.25f);
            float height = 480f;

            // adding items
            for (int i = 0; i < value.VendorSku.Count; i++)
            {
                // if the item is cancelled, skip this item
                if (cancelIndex.Any(j => i == j))
                {
                    continue;
                }

                // draw box
                draw.MoveTo(40f, height);
                draw.LineTo(40f, height - 10f);
                draw.Stroke();
                draw.MoveTo(40f, height - 10f);
                draw.LineTo(doc.PageSize.Width - 40f, height - 10f);
                draw.Stroke();
                draw.MoveTo(doc.PageSize.Width - 40f, height - 10f);
                draw.LineTo(doc.PageSize.Width - 40f, height);
                draw.Stroke();
                draw.MoveTo(130f, height);
                draw.LineTo(130f, height - 10f);
                draw.Stroke();
                draw.MoveTo(220f, height);
                draw.LineTo(220f, height - 10f);
                draw.Stroke();
                draw.MoveTo(400f, height);
                draw.LineTo(400f, height - 10f);
                draw.Stroke();
                draw.MoveTo(480f, height);
                draw.LineTo(480f, height - 10f);
                draw.Stroke();

                // qty
                text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10));
                ct.SetSimpleColumn(text, 40f, height - 19f, 130, height - 9f, 0f, Element.ALIGN_CENTER);
                ct.Go();

                // item
                text = new Phrase(value.ClientItemId[i], new Font(baseFont, 10));
                ct.SetSimpleColumn(text, 130f, height - 19f, 220f, height - 9f, 0f, Element.ALIGN_CENTER);
                ct.Go();

                // description
                text = new Phrase("", new Font(baseFont, 10));
                ct.SetSimpleColumn(text, 220f, height - 19f, 400f, height - 9f, 0f, Element.ALIGN_CENTER);
                ct.Go();

                // qty shipped
                text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10));
                ct.SetSimpleColumn(text, 400f, height - 19f, 480f, height - 9f, 0f, Element.ALIGN_CENTER);
                ct.Go();

                // vendor sku
                text = new Phrase(value.VendorSku[i], new Font(baseFont, 10));
                ct.SetSimpleColumn(text, 480f, height - 19f, doc.PageSize.Width - 40f, height - 9f, 0f, Element.ALIGN_CENTER);
                ct.Go();

                // decrease height for next item
                height -= 10f;
            }
            #endregion

            #region Ending Boxes
            #region Top Box
            // restore width
            draw.SetLineWidth(1f);

            // draw box
            draw.MoveTo(40f, 250f);
            draw.LineTo(doc.PageSize.Width - 40f, 250f);
            draw.LineTo(doc.PageSize.Width - 40f, 235f);
            draw.LineTo(40f, 235f);
            draw.LineTo(40f, 250f);
            draw.ClosePathFillStroke();

            // message in the box
            text = new Phrase("Thank you for ordering from Giant Tiger!        Merci d’avoir placé une commande chez Tigre Géant!", new Font(boldFont, 10f, Font.NORMAL, white));
            ct.SetSimpleColumn(text, 40f, 224f, doc.PageSize.Width - 40f, 239f, 0f, Element.ALIGN_CENTER);
            ct.Go();
            #endregion

            #region Bottom Box
            // draw box
            draw.MoveTo(40f, 225f);
            draw.LineTo(doc.PageSize.Width - 40f, 225f);
            draw.Stroke();
            draw.MoveTo(doc.PageSize.Width - 40f, 225f);
            draw.LineTo(doc.PageSize.Width - 40f, 50f);
            draw.Stroke();
            draw.MoveTo(doc.PageSize.Width - 40f, 50f);
            draw.LineTo(40f, 50f);
            draw.Stroke();
            draw.MoveTo(40f, 50f);
            draw.LineTo(40f, 225f);
            draw.Stroke();
            draw.MoveTo(doc.PageSize.Width / 2, 225f);
            draw.LineTo(doc.PageSize.Width / 2, 50f);
            draw.Stroke();

            // message in the left box
            text = new Phrase("Didn't receive your entire order or questions about your order?\n" +
                              "You may receive your order in separate shipments. To track your order status. Please log into My Account at gianttiger.com.\n\r" +
                              "Want to Return or Exchange an Item?\n" +
                              "If you are not satisfied with your order for any reason please contact our Customer Service Team at 1-844-99-GIANT (44268) or email [email protected]. " +
                              "For in-store returns or exchanges, your shipment confirmation email is required. To review our return policy, please visit gianttiger.com/ReturnPolicy.",
                              new Font(baseFont, 9f));
            ct.SetSimpleColumn(text, 50f, 55f, doc.PageSize.Width / 2 - 10, 225f, 10f, Element.ALIGN_LEFT);
            ct.Go();

            // message in the right box
            text = new Phrase("Votre commande est incomplète ou vous avez des questions à son sujet?\n" +
                              "Il se peut que vous receviez votre commande dans des envois distincts. Pour suivre l'état de votre commande, s’il vous plaît vous connecter à Mon Compte au tigregeant.com.\n\r" +
                              "Vous voulez retourner ou échanger un article?\nSi vous n'êtes pas satisfait avec votre achat, veuillez communiquer avec notre service à la clientèle au 1-844-99-GIANT (44268) " +
                              "ou envoyer un courriel à [email protected]. Les échanges et les remboursements peuvent être effectués à n’importe quel de nos magasins avec la présentation du courriel confirmant " +
                              "l'expédition de votre commande. Pour consulter notre politique de retour, s'il vous plaît visitez tigregeant.com/PolitiqueRetour.",
                              new Font(baseFont, 9f));
            ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 10f, 55f, doc.PageSize.Width - 50f, 225f, 10f, Element.ALIGN_LEFT);
            ct.Go();
            #endregion
            #endregion

            doc.Close();

            if (!preview)
            {
                return;
            }

            // start the pdf for previewing
            if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1)
            {
                System.Diagnostics.Process.Start(file);
            }
        }
示例#8
0
        public void Draw(PdfContentByte cb, int y)
        {
            int yPosition     = y;
            int currentHeight = CalculateHeight();
            int HEIGHT        = currentHeight >= MINIMUMHEIGHT ? currentHeight : MINIMUMHEIGHT;
            int TOP           = yPosition + HEIGHT;
            int BOTTOM        = yPosition;

            int SPECIFICATIONHEIGHT = CalculateSpecificationElementHeight();


            BaseFont f_cb = BaseFont.CreateFont("c:\\windows\\fonts\\calibrib.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            //Background of element
            cb.SetColorFill(new BaseColor(245, 245, 245));
            cb.Rectangle(0, BOTTOM, WINDOWWIDTH, HEIGHT);
            cb.Fill();

            //Top bar background
            cb.SetColorFill(new BaseColor(22, 137, 206));
            cb.Rectangle(0, TOP - TOPBARHEIGHT, WINDOWWIDTH, TOPBARHEIGHT);
            cb.Fill();

            //Top bar text
            cb.BeginText();
            cb.SetFontAndSize(f_cb, 20);
            cb.SetColorFill(BaseColor.WHITE);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, headerText, 20, TOP - 26, 0);
            cb.EndText();

            //Shadow line under top bar
            cb.SetColorStroke(new BaseColor(222, 222, 222));
            cb.SetLineWidth(2);
            cb.MoveTo(0, TOP - TOPBARHEIGHT - 1);
            cb.LineTo(WINDOWWIDTH, TOP - TOPBARHEIGHT - 1);
            cb.ClosePathFillStroke();

            //Image of product
            Image img = Image.GetInstance("mokgroen.jpg");

            img.SetAbsolutePosition(MARGIN, TOP - TOPBARHEIGHT - 200 + MARGIN);
            img.ScaleAbsolute(200 - MARGIN - MARGIN, 200 - MARGIN - MARGIN);
            cb.AddImage(img);

            //Shadow line under image
            cb.SetColorStroke(new BaseColor(222, 222, 222));
            cb.SetLineWidth(2);
            cb.MoveTo(MARGIN, TOP - TOPBARHEIGHT - 200 + MARGIN);
            cb.LineTo(200 - MARGIN, TOP - TOPBARHEIGHT - 200 + MARGIN);
            cb.ClosePathFillStroke();

            //Background of summary element
            cb.SetColorFill(new BaseColor(255, 255, 255));
            cb.Rectangle(200, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT, WINDOWWIDTH - 200 - MARGIN, SUMMARYHEIGHT);
            cb.Fill();

            //Header text for summary
            cb.BeginText();
            cb.SetFontAndSize(f_cb, 12);
            cb.SetColorFill(new BaseColor(22, 137, 206));
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Description", 210, TOP - TOPBARHEIGHT - MARGIN - 15, 0);

            //Summary text inside element
            cb.SetFontAndSize(f_cb, 12);
            cb.SetColorFill(new BaseColor(120, 120, 120));
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, summaryText, 210, TOP - TOPBARHEIGHT - MARGIN - 35, 0);
            cb.EndText();

            //Shadow line under summary
            cb.SetColorStroke(new BaseColor(222, 222, 222));
            cb.SetLineWidth(2);
            cb.MoveTo(200, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - 1);
            cb.LineTo(200 + WINDOWWIDTH - 200 - MARGIN, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - 1);
            cb.ClosePathFillStroke();

            if (specifications.Count > 0)
            {
                //Background of specifications
                cb.SetColorFill(new BaseColor(255, 255, 255));
                cb.Rectangle(200, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - MARGIN - SPECIFICATIONHEIGHT, WINDOWWIDTH - 200 - MARGIN, SPECIFICATIONHEIGHT);
                cb.Fill();

                //Header text for specifications
                cb.BeginText();
                cb.SetFontAndSize(f_cb, 12);
                cb.SetColorFill(new BaseColor(22, 137, 206));
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Specifications", 210, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - MARGIN - 15, 0);

                //Summary text inside specifications
                cb.SetFontAndSize(f_cb, 12);
                cb.SetColorFill(new BaseColor(120, 120, 120));
                for (int i = 0; i < specifications.Count; i++)
                {
                    string[] specValuePairs = specifications[i];

                    int textYPos = TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - MARGIN - 25 - 15 - (25 * i);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, specValuePairs[0], 210, textYPos, 0);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, specValuePairs[1], 320, textYPos, 0);
                }
                cb.EndText();

                //Shadow line under specifications
                cb.SetColorStroke(new BaseColor(222, 222, 222));
                cb.SetLineWidth(2);
                cb.MoveTo(200, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - MARGIN - SPECIFICATIONHEIGHT - 1);
                cb.LineTo(200 + WINDOWWIDTH - 200 - MARGIN, TOP - TOPBARHEIGHT - MARGIN - SUMMARYHEIGHT - MARGIN - SPECIFICATIONHEIGHT - 1);
                cb.ClosePathFillStroke();
            }
        }
示例#9
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();
        }
        private void BtnPrint_Click(object sender, EventArgs e)
        {
            Document document = new Document();

            this.produkterDir = produkterLocation();
            this.fvfilename   = this.produkterDir + "produkter.pdf";

            // if (this.fvfilename.Contains("/")) { this.fvfilename = this.fvfilename.Replace("/", "-"); }
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(this.fvfilename, FileMode.Create));

            // open the document
            document.Open();

            PdfContentByte cb = writer.DirectContent;

            cb.SetColorStroke(new CMYKColor(100f, 100f, 100f, 100f));

            cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f));

            // x, y of bottom left corner, width, height
            //-----------------------------------------------------------
            cb.Rectangle(300f, 775f, 260f, 25f); // pierwsza tabelka
            cb.Stroke();
            cb.Rectangle(300f, 745f, 135f, 25f); // druga tabelka
            cb.Stroke();

            cb.Rectangle(440f, 745f, 120f, 25f); // druga tabelka
            cb.Stroke();


            cb.Rectangle(300f, 650f, 260f, 90f); // czwarta tabelka
            cb.Stroke();

            if (logoExist() == true)
            {
                iTextSharp.text.Image imgLogo = iTextSharp.text.Image.GetInstance(this.imageLogo);
                imgLogo.ScaleAbsolute(264, 187);
                imgLogo.SetAbsolutePosition(30, 613);
                imgLogo.Alignment = iTextSharp.text.Image.TEXTWRAP;
                document.Add(imgLogo);
            }

            iTextSharp.text.Font georgia = FontFactory.GetFont("georgia", 10f);

            int       fontSix  = Convert.ToInt32(this.fontsize);
            Paragraph p        = new Paragraph(this.foretagnamn, FontFactory.GetFont(FontFactory.TIMES_BOLD, fontSix, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0)));
            Chapter   chapter2 = new Chapter(p, 0);

            if (logoExist() == false)
            {
                document.Add(p);
            }

            cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f));
            PlaceText(writer.DirectContent, "BENÄMNING", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, 650, 30, 30, 14, Element.ALIGN_LEFT);
            PlaceText(writer.DirectContent, "", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 346, 650, -185, 30, 14, Element.ALIGN_RIGHT);
            PlaceText(writer.DirectContent, "ENHETER", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 447, 650, -185, 30, 14, Element.ALIGN_RIGHT);
            PlaceText(writer.DirectContent, "À-PRIS", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, 650, -185, 30, 14, Element.ALIGN_RIGHT);
            PlaceText(writer.DirectContent, "Produkter", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.BOLD), 386, 793, -185, 30, 14, Element.ALIGN_RIGHT);
            cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f));

            string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\data\produkter.xml";
            // listViewProdukter.Items.Clear();

            XDocument xmldoc = XDocument.Load(path);
            var       items  = (from i in xmldoc.Descendants("produkt")
                                // where (string)(i.Element("pnamn")) == "AL LAMELL 30 mm 9,6 m²"
                                select new
            {
                pnamn = i.Element("pnamn").Value,
                pris = i.Element("pris").Value
            }).ToList();

            // liczba stron
            if ((items.Count % 40) == 0)
            {
                this.pagesAll = items.Count / 40;
            }
            else if ((items.Count % 40) != 0)
            {
                this.pagesAll = (items.Count / 40) + 1;
            }
            double item_price = 0.8;
            string s_item_price;
            int    currentPage        = 1;
            string text_faktura_datum = @"Datum";

            string text_faktura_address_l1 = this.adress1;
            string text_faktura_address_l2 = this.adress2;
            string text_faktura_address_l3 = this.adress3;


            PdfContentByte cbs = writer.DirectContent;

            cbs.BeginText();

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8);
            cbs.SetTextMatrix(443, 762);
            cbs.ShowText(text_faktura_datum);

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8);
            cbs.SetTextMatrix(303, 732);
            cbs.ShowText("Företagadress");

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8);
            cbs.SetTextMatrix(303, 762);
            cbs.ShowText("Sida");

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
            cbs.SetTextMatrix(314, 749);
            cbs.ShowText("  " + currentPage.ToString() + " / " + this.pagesAll.ToString());

            string strDateNow = System.DateTime.Now.ToString("yyyy-MM-dd");

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
            cbs.SetTextMatrix(460, 749);
            cbs.ShowText(strDateNow);

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
            cbs.SetTextMatrix(314, 717);
            cbs.ShowText(text_faktura_address_l1);

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
            cbs.SetTextMatrix(314, 702);
            cbs.ShowText(text_faktura_address_l2);

            cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
            cbs.SetTextMatrix(314, 687);
            cbs.ShowText(text_faktura_address_l3);

            cbs.EndText();


            int kLine     = 650;
            int underLine = 633;

            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].pris.ToString() != "")
                {
                    if (IsNumber(items[i].pris.ToString()) == true)
                    {
                        item_price   = Convert.ToDouble(items[i].pris.ToString());
                        s_item_price = item_price.ToString("0,0.00") + " kr";
                    }
                    else
                    {
                        item_price   = 0;
                        s_item_price = items[i].pris.ToString();
                    }
                }
                else
                {
                    item_price   = 0;
                    s_item_price = "";
                }

                PlaceText(writer.DirectContent, items[i].pnamn.ToString(), FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, kLine, 30, 30, 14, Element.ALIGN_LEFT);
                PlaceText(writer.DirectContent, s_item_price, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, kLine, -185, 30, 14, Element.ALIGN_RIGHT);
                kLine = kLine - 15;

                cb.MoveTo(100, underLine);
                cb.LineTo(560, underLine);
                cb.ClosePathStroke();
                underLine = underLine - 15;
                if (Is40(i) == true && i != 0) //
                                               // if (i == 40 || i == 80 || i == 120 || i == 160 || i == 200)
                {
                    kLine     = 685;
                    underLine = 668;

                    document.NewPage();
                    // currentPage = document.PageNumber;

                    PdfContentByte Dcbs = writer.DirectContent;
                    Dcbs.BeginText();

                    Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8);
                    Dcbs.SetTextMatrix(443, 762);
                    Dcbs.ShowText(text_faktura_datum);


                    Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
                    Dcbs.SetTextMatrix(460, 749);
                    Dcbs.ShowText(strDateNow);

                    Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8);
                    Dcbs.SetTextMatrix(303, 762);
                    Dcbs.ShowText("Sida");

                    Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12);
                    Dcbs.SetTextMatrix(314, 749);
                    currentPage = currentPage + 1;
                    Dcbs.ShowText("  " + currentPage.ToString() + " / " + this.pagesAll.ToString());


                    Dcbs.EndText();

                    // x, y of bottom left corner, width, height
                    //-----------------------------------------------------------
                    cb.Rectangle(300f, 775f, 260f, 25f); // first table
                    cb.Stroke();

                    cb.Rectangle(300f, 745f, 135f, 25f); // second table
                    cb.Stroke();

                    cb.Rectangle(440f, 745f, 120f, 25f); // third table
                    cb.Stroke();

                    if (logoExist() == true)
                    {
                        iTextSharp.text.Image imgLogo = iTextSharp.text.Image.GetInstance(this.imageLogo);
                        imgLogo.ScaleAbsolute(264, 187);
                        imgLogo.SetAbsolutePosition(30, 613);
                        imgLogo.Alignment = iTextSharp.text.Image.TEXTWRAP;
                        document.Add(imgLogo);
                    }

                    if (logoExist() == false)
                    {
                        document.Add(p);
                    }

                    cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f));
                    PlaceText(writer.DirectContent, "BENÄMNING", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, kLine + 15, 30, 30, 14, Element.ALIGN_LEFT);
                    PlaceText(writer.DirectContent, "", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 346, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT);
                    PlaceText(writer.DirectContent, "ENHETER", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 447, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT);
                    PlaceText(writer.DirectContent, "À-PRIS", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT);
                    PlaceText(writer.DirectContent, "Produkter", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.BOLD), 386, 793, -185, 30, 14, Element.ALIGN_RIGHT);
                    cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f));

                    cb.MoveTo(100, 683);
                    cb.LineTo(560, 683);
                    cb.ClosePathStroke();
                }
            }

            cb.ClosePathFillStroke();

            document.Close();

            System.Threading.Thread.Sleep(1000);
            try
            {
                System.Diagnostics.Process.Start(this.fvfilename);
            }
            catch
            { }
        }