Example #1
0
        /*
         * private Color GetColorfromRGBString(string colorString)
         * {
         *  var r = 0;
         *  var g = 0;
         *  var b = 0;
         *  try
         *  {
         *      var cleanedString = colorString.Replace("RGB(", "");
         *      cleanedString = cleanedString.Replace(")", "");
         *      var splitStringArray = cleanedString.Split(',');
         *      r = int.Parse(splitStringArray[0]);
         *      g = int.Parse(splitStringArray[1]);
         *      b = int.Parse(splitStringArray[2]);
         *  }
         *  catch (Exception e)
         *  {
         *      Console.WriteLine("{0}", e.Message);
         *  }
         *
         *  return Color.FromArgb(r, g, b);
         * }
         *
         */


        private void DrawFrameAndBackgroundWaterMark()
        {
            // save graphics state
            Contents.SaveGraphicsState();
            Contents.SetColorNonStroking(Color.FromArgb(pk.BackgroundColor.Red, pk.BackgroundColor.Green, pk.BackgroundColor.Blue));
            Contents.DrawRectangle(0.0, 0.0, 8.5, 11, PaintOp.Fill);
            // restore graphics sate
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw heading
        ////////////////////////////////////////////////////////////////////

        private void DrawTwoLinesOfHeading
        (
            PdfContents Contents
        )
        {
            // page heading
            // Arguments: Font: ArialBold, size: 36 points, Position: X = 4.25", Y = 9.5"
            // Text Justify: Center (text center will be at X position)
            // Stoking color: R=128, G=0, B=255 (text outline)
            // Nonstroking color: R=255, G=0, B=128 (text body)
            Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");

            // save graphics state
            Contents.SaveGraphicsState();

            // change nonstroking (fill) color to purple
            Contents.SetColorNonStroking(Color.Purple);

            // Draw second line of heading text
            // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0"
            // Text Justify: Center (text center will be at X position)
            Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Example");
//		Contents.TranslateScaleRotate(4.25, 8.75, 1.5, Math.PI / 6);
//		Contents.DrawText(Comic, 30.0, 0, 0, TextJustify.Center, "Example");

            // restore graphics sate (non stroking color will be restored to default)
            Contents.RestoreGraphicsState();
            return;
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////
        // Draw heading
        ////////////////////////////////////////////////////////////////////

        private void DrawTwoLinesOfHeading()
        {
            // page heading
            // Arguments: Font: ArialBold, size: 36 points, Position: X = 4.25", Y = 9.5"
            // Text Justify: Center (text center will be at X position)
            // Stoking color: R=128, G=0, B=255 (text outline)
            // Nonstroking color: R=255, G=0, B=128 (text body)

            double y = (11.69 - 2.0) * 72;
            //double x = 1.5;
            double x = 36;

            //Contents.DrawText(TimesNormal, 9.0, x, y, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");
            Contents.DrawText(TimesNormal, 9.0, x, y, TextJustify.Left, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), ".");
            //Contents.DrawText(TimesNormal, 9.0, x, y, TextJustify.Center, DrawStyle.Normal, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");

            // save graphics state
            Contents.SaveGraphicsState();

            // change nonstroking (fill) color to purple
            Contents.SetColorNonStroking(Color.Purple);
            PdfFont pdf = PdfFont.CreatePdfFont(Document, "Times New Roman", FontStyle.Regular, true);
            PaintOp p   = PaintOp.CloseStroke;

            // Draw second line of heading text
            // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0"
            // Text Justify: Center (text center will be at X position)
            //PdfRectangle rect = pdf.TextBoundingBox(30.0, "\n");
            PdfRectangle rect1 = pdf.TextBoundingBox(30.0, "ExampleCenter");
            PdfRectangle rect2 = pdf.TextBoundingBox(30.0, "ExampleLeft");
            TextBox      box   = new TextBox(10.0 * 72, 0.25);

            box.AddText(TimesNormal, 30, ArticleString);
            double y1 = 8.75 * 72;
            // double value = Contents.DrawText(TimesNormal, 30.0, (4.25 * 72)+rect.Width/2  , 8.75 * 72, TextJustify.Right, "ExampleRight \n");
            double value  = Contents.DrawText((4.25 * 72), ref y1, 0, 0, box);
            double value1 = Contents.DrawText(TimesNormal, 30.0, 4.25 * 72, 6.75 * 72, TextJustify.Left, "ExampleLeft");
            double value2 = Contents.DrawText(TimesNormal, 30.0, 4.25 * 72 + (rect1.Width), 4.75 * 72, TextJustify.Center, "ExampleCenter");

            Contents.DrawRectangle(4.25 * 72, 6.75 * 72, value1, rect1.Height, p);
            Contents.DrawRectangle((4.25 * 72), y1, box.BoxWidth, box.BoxHeight, p);
            Contents.DrawRectangle((4.25 * 72), 4.75 * 72, value2, rect2.Height, p);
            // restore graphics sate (non stroking color will be restored to default)
            Contents.RestoreGraphicsState();
            return;
        }
        public void OnePage
        (
            int Cols,
            int Rows
        )
        {
            // Add new page
            PdfPage Page = new PdfPage(Document);

            // Add contents to page
            PdfContents Contents = new PdfContents(Page);

            double Left   = CenterX - 0.5 * Cols;
            double Right  = CenterX + 0.5 * Cols;
            double Top    = CenterY + 0.5 * Rows;
            double Bottom = CenterY - 0.5 * Rows;

            Contents.DrawText(ArialFont, FontSize, CenterX, Top + Descent + 0.2, TextJustify.Center, Cols == Rows ? "Square" : "Rectangle");

            // save state
            Contents.SaveGraphicsState();

            Contents.SetLineWidth(0.1);
            Contents.SetColorStroking(Color.Black);
            Contents.SetColorNonStroking(Color.LightBlue);
            Contents.DrawRectangle(Left, Bottom, Cols, Rows, PaintOp.CloseFillStroke);
            Contents.RestoreGraphicsState();

            Contents.SaveGraphicsState();
            Contents.SetLineWidth(0.04);
            for (int Row = 0; Row <= Rows; Row++)
            {
                Contents.DrawLine(Left - 0.25, Bottom + Row, Right, Bottom + Row);
                Contents.DrawText(ArialFont, FontSize, Left - 0.35, Bottom + Row - Descent, TextJustify.Right, Row.ToString());
            }

            for (int Col = 0; Col <= Cols; Col++)
            {
                Contents.DrawLine(Left + Col, Bottom - 0.25, Left + Col, Top);
                Contents.DrawText(ArialFont, FontSize, Left + Col, Bottom - 0.25 - FontHeight, TextJustify.Center, Col.ToString());
            }

            for (int Index = 0; Index < Rows * Cols; Index++)
            {
                int Row = Index / Cols;
                int Col = Index % Cols;
                Contents.DrawText(ArialFont, FontSize, Left + 0.5 + Col, Top - 0.5 - Descent - Row, TextJustify.Center, (Index + 1).ToString());
            }

            Contents.DrawText(ArialFont, FontSize, CenterX, Bottom - 1.0, TextJustify.Center, "Area");
            Contents.DrawText(ArialFont, FontSize, CenterX, Bottom - 1.4, TextJustify.Center, string.Format("{0} X {1} = {2}", Rows, Cols, Rows * Cols));

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw Happy Face
        ////////////////////////////////////////////////////////////////////

        private void DrawHappyFace
        (
            PdfContents Contents
        )
        {
            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the happy face
            Contents.Translate(4.25, 7.5);

            // change nonstroking (fill) color to yellow
            Contents.SetColorNonStroking(Color.Yellow);

            // draw happy face yellow oval
            Contents.DrawOval(-1.5, -1.0, 3.0, 2.0, PaintOp.Fill);

            // set line width to 0.2" this is the black circle around the eye
            Contents.SetLineWidth(0.2);

            // eye color is white with black outline circle
            Contents.SetColorNonStroking(Color.White);
            Contents.SetColorStroking(Color.Black);

            // draw eyes
            Contents.DrawOval(-0.75, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);
            Contents.DrawOval(0.25, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke);

            // mouth color is black
            Contents.SetColorNonStroking(Color.Black);

            // draw mouth by creating a path made of one line and one Bezier curve
            Contents.MoveTo(-0.6, -0.4);
            Contents.LineTo(0.6, -0.4);
            Contents.DrawBezier(0.0, -0.8, 0, -0.8, -0.6, -0.4);

            // fill the path with black color
            Contents.SetPaintOp(PaintOp.Fill);

            // restore graphics sate
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw heart
        ////////////////////////////////////////////////////////////////////

        private void DrawHeart
        (
            PdfContents Contents
        )
        {
            // save graphics state
            Contents.SaveGraphicsState();

            // draw heart
            // The first argument are the coordinates of the centerline of the heart shape.
            // The DrawHeart is a special case of DrawDoubleBezierPath method.
            Contents.SetColorNonStroking(Color.HotPink);
            Contents.DrawHeart(new LineD(new PointD(5.14, 5.1), new PointD(5.14, 6.0)), PaintOp.CloseFillStroke);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw six sided regular polygon
        ////////////////////////////////////////////////////////////////////

        private void DrawStar
        (
            PdfContents Contents
        )
        {
            // save graphics state
            Contents.SaveGraphicsState();

            // Regular polygon
            // Coordinate of center point is PosX=6.67" PosY=5.7"
            // Radius of end points is 0.7"
            // First drawing point is at 30 degrees (in radians PI / 6).
            // Number of sides is 6
            Contents.SetColorNonStroking(Color.Turquoise);
            Contents.DrawStar(6.67, 5.7, 0.7, Math.PI / 6, 6, PaintOp.CloseFillStroke);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Example #8
0
        ////////////////////////////////////////////////////////////////////
        // Create charting examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // for encryption test
//		Document.SetEncryption("Password", Permission.All & ~Permission.Print);

            ArialNormal = new PdfFont(Document, "Arial", FontStyle.Regular, true);
            Comic       = new PdfFont(Document, "Comic Sans MS", FontStyle.Bold, true);

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4:Add contents to page
            PdfContents Contents = new PdfContents(Page);

            // save graphics state
            Contents.SaveGraphicsState();

            // Draw frame around the page
            // Set line width to 0.02"
            Contents.SetLineWidth(0.02);

            // set frame color dark blue
            Contents.SetColorStroking(Color.DarkBlue);
            Contents.SetColorNonStroking(Color.FromArgb(240, 250, 250));

            // rectangle position: x=1.0", y=1.0", width=6.5", height=9.0"
            Contents.DrawRectangle(1.0, 1.0, 6.5, 9.0, PaintOp.CloseFillStroke);
            Contents.DrawLine(1.0, 8.5, 7.5, 8.5);
            Contents.DrawLine(1.0, 6.0, 7.5, 6.0);
            Contents.DrawLine(1.0, 3.5, 7.5, 3.5);

            // page heading
            Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");

            // change nonstroking (fill) color to purple
            Contents.SetColorNonStroking(Color.Purple);

            // Draw second line of heading text
            // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0"
            // Text Justify: Center (text center will be at X position)
            Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Media Example");

            // create embedded media file
            Example1();
            Example2();

            // restore graphics sate (non stroking color will be restored to default)
            Contents.RestoreGraphicsState();

            // create the PDF file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
        internal void Draw
        (
            PdfContents Contents,
            double DrawRectX,
            double DrawRectY,
            double DrawRectWidth,
            double DrawRectHeight,
            ContentAlignment Alignment = (ContentAlignment)0
        )
        {
            // save drawing rectangle in user coordinates
            this.DrawRectX      = DrawRectX;
            this.DrawRectY      = DrawRectY;
            this.DrawRectWidth  = DrawRectWidth;
            this.DrawRectHeight = DrawRectHeight;

            // test arguments
            if (DrawRectWidth == 0 && DrawRectHeight == 0 || DrawRectWidth == 0 && PathBBoxWidth != 0 || DrawRectHeight == 0 && PathBBoxHeight != 0)
            {
                throw new ApplicationException("DrawWPFPath: Drawing rectangle is empty");
            }

            // set transformation matrix
            SetTransformation(Alignment);

            // clip
            if (Stroking == null && NonStroking == null)
            {
                // build clipping path
                BuildPath(Contents, FillRule == FillRule.EvenOdd ? PaintOp.ClipPathEor : PaintOp.ClipPathWnr);
                return;
            }

            // paint operator
            PaintOp PaintOperator;

            // brush is defined as shading
            if (NonStroking != null && (NonStroking.GetType() == typeof(SysMedia.LinearGradientBrush) || NonStroking.GetType() == typeof(SysMedia.RadialGradientBrush) ||
                                        NonStroking.GetType() == typeof(PdfAxialShading) || NonStroking.GetType() == typeof(PdfRadialShading)))
            {
                // save graphics state
                Contents.SaveGraphicsState();

                // build clipping path
                BuildPath(Contents, FillRule == FillRule.EvenOdd ? PaintOp.ClipPathEor : PaintOp.ClipPathWnr);

                // set bland mode
                if (BlendMode != BlendMode.Normal)
                {
                    Contents.SetBlendMode(BlendMode);
                }

                // set opacity
                Contents.SetAlphaNonStroking(BrushOpacity);

                // draw linera gradient brush shading bounded by clip path
                if (NonStroking.GetType() == typeof(SysMedia.LinearGradientBrush))
                {
                    PdfAxialShading AxialShading = new PdfAxialShading(Contents.Document, (SysMedia.LinearGradientBrush)NonStroking);
                    AxialShading.SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight);
                    Contents.DrawShading(AxialShading);
                }

                // draw axial shading bounded by clip path
                else if (NonStroking.GetType() == typeof(PdfAxialShading))
                {
                    ((PdfAxialShading)NonStroking).SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight);
                    Contents.DrawShading((PdfAxialShading)NonStroking);
                }

                // draw radial gradient brush shading bounded by clip path
                else if (NonStroking.GetType() == typeof(SysMedia.RadialGradientBrush))
                {
                    PdfRadialShading RadialShading = new PdfRadialShading(Contents.Document, (SysMedia.RadialGradientBrush)NonStroking);
                    RadialShading.SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight);
                    Contents.DrawShading(RadialShading);
                }

                // draw radial shading bounded by clip path
                else
                {
                    ((PdfRadialShading)NonStroking).SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight);
                    Contents.DrawShading((PdfRadialShading)NonStroking);
                }

                // remove clipping path
                Contents.RestoreGraphicsState();

                // no pen defined
                if (Stroking == null)
                {
                    return;
                }

                // pen is defined
                PaintOperator = PaintOp.Stroke;
            }

            // set paint operator for all other cases (no shading)
            else
            {
                // we have pen and no brush
                if (NonStroking == null)
                {
                    PaintOperator = PaintOp.Stroke;
                }
                // we have brush but no pen
                else if (Stroking == null)
                {
                    PaintOperator = FillRule == FillRule.EvenOdd ? PaintOp.FillEor : PaintOp.Fill;
                }
                // we have brush and pen
                else
                {
                    PaintOperator = FillRule == FillRule.EvenOdd ? PaintOp.CloseFillStrokeEor: PaintOp.CloseFillStroke;
                }
            }

            // save graphics state
            Contents.SaveGraphicsState();

            // set bland mode
            if (BlendMode != BlendMode.Normal)
            {
                Contents.SetBlendMode(BlendMode);
            }

            // stroking (pen) is defined
            if (Stroking != null)
            {
                if (Stroking.GetType() == typeof(Color))
                {
                    // pen color
                    Contents.SetColorStroking((Color)Stroking);

                    // set opacity
                    if (PenOpacity != 1.0)
                    {
                        Contents.SetAlphaStroking(PenOpacity);
                    }

                    // pen width
                    if (PenWidth >= 0)
                    {
                        Contents.SetLineWidth(PenWidth);
                    }

                    // line cap
                    if (LineCap != (PdfLineCap)(-1))
                    {
                        Contents.SetLineCap(LineCap);
                    }

                    // line join
                    if (LineJoin != (PdfLineJoin)(-1))
                    {
                        Contents.SetLineJoin(LineJoin);
                    }

                    // Miter
                    if (MiterLimit != -1)
                    {
                        Contents.SetMiterLimit(MiterLimit);
                    }

                    // line is made of dashes
                    if (DashArray != null)
                    {
                        Contents.SetDashLine(DashArray, DashPhase);
                    }
                }

                else if (Stroking.GetType() == typeof(SysMedia.Pen))
                {
                    // media pen short cut
                    SysMedia.Pen Pen = (SysMedia.Pen)Stroking;

                    // media brush shortcut
                    SysMedia.SolidColorBrush Brush = (SysMedia.SolidColorBrush)Pen.Brush;

                    // media pen color short cut
                    SysMedia.Color PenColor = Brush.Color;

                    // pen color
                    Contents.SetColorStroking(Color.FromArgb(PenColor.R, PenColor.G, PenColor.B));

                    // pen opacity
                    if (PenColor.A != 255 || Brush.Opacity != 1.0)
                    {
                        Contents.SetAlphaStroking((PenColor.A / 255.0) * Brush.Opacity);
                    }

                    // pen thickness converted to user units
                    double Thickness = Pen.Thickness * Math.Max(Math.Abs(ScaleX), Math.Abs(ScaleY));
                    Contents.SetLineWidth(Thickness);

                    // line cap
                    // Note: PDF line cap is the same for start and end. We will ignore EndLineCap
                    // Triangle line cap will be round
                    switch (Pen.StartLineCap)
                    {
                    case SysMedia.PenLineCap.Flat: Contents.SetLineCap(PdfLineCap.Butt); break;

                    case SysMedia.PenLineCap.Square: Contents.SetLineCap(PdfLineCap.Square); break;

                    default: Contents.SetLineCap(PdfLineCap.Round); break;
                    }

                    // line join
                    switch (Pen.LineJoin)
                    {
                    case SysMedia.PenLineJoin.Bevel: Contents.SetLineJoin(PdfLineJoin.Bevel); break;

                    case SysMedia.PenLineJoin.Miter: Contents.SetLineJoin(PdfLineJoin.Miter); break;

                    default: Contents.SetLineJoin(PdfLineJoin.Round); break;
                    }

                    // Miter
                    Contents.SetMiterLimit(Pen.MiterLimit);

                    // dash pattern
                    if (Pen.DashStyle.Dashes.Count > 0)
                    {
                        int      End          = Pen.DashStyle.Dashes.Count;
                        double[] PenDashArray = new double[End];
                        for (int Index = 0; Index < End; Index++)
                        {
                            PenDashArray[Index] = Thickness * Pen.DashStyle.Dashes[Index];
                        }
                        Contents.SetDashLine(PenDashArray, Thickness * Pen.DashStyle.Offset);
                    }
                }
            }

            // non-stroking (brush) is defined
            // note shading brush was handled above
            if (NonStroking != null)
            {
                // set opacity
                if (BrushOpacity != 1.0)
                {
                    Contents.SetAlphaNonStroking(BrushOpacity);
                }

                // brush color
                if (NonStroking.GetType() == typeof(Color))
                {
                    Contents.SetColorNonStroking((Color)NonStroking);
                }

                else if (NonStroking.GetType() == typeof(PdfTilingPattern))
                {
                    Contents.SetPatternNonStroking((PdfTilingPattern)NonStroking);
                }
            }

            // build path
            BuildPath(Contents, PaintOperator);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Example #10
0
        public void Test
        (
            bool Debug,
            string InputFileName
        )
        {
            // create document
            using (Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName))
            {
                // set document page mode to open the layers panel
                Document.InitialDocDisplay = InitialDocDisplay.UseLayers;

                // define font
                ArialFont = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Bold);

                // open layer control object (in PDF terms optional content object)
                PdfLayers Layers = new PdfLayers(Document, "PDF layers group");

                // set layer panel to incluse all layers including ones that are not visible
                Layers.ListMode = ListMode.AllPages;

                // Add new page
                PdfPage Page = new PdfPage(Document);

                // Add contents to page
                PdfContents Contents = new PdfContents(Page);

                // heading
                Contents.DrawText(ArialFont, 24, 4.25, 10, TextJustify.Center, "PDF File Writer Layer Test/Demo");

                // define layers
                PdfLayer DrawingTest    = new PdfLayer(Layers, "Drawing Test");
                PdfLayer Rectangle      = new PdfLayer(Layers, "Rectangle");
                PdfLayer HorLines       = new PdfLayer(Layers, "Horizontal Lines");
                PdfLayer VertLines      = new PdfLayer(Layers, "Vertical Lines");
                PdfLayer QRCodeLayer    = new PdfLayer(Layers, "QRCode barcode");
                PdfLayer Pdf417Layer    = new PdfLayer(Layers, "PDF417 barcode");
                PdfLayer NoBarcodeLayer = new PdfLayer(Layers, "No barcode");

                // combine three layers into one group of radio buttons
                QRCodeLayer.RadioButton    = "Barcode";
                Pdf417Layer.RadioButton    = "Barcode";
                NoBarcodeLayer.RadioButton = "Barcode";

                // set the order of layers in the layer pane
                Layers.DisplayOrder(DrawingTest);
                Layers.DisplayOrder(Rectangle);
                Layers.DisplayOrder(HorLines);
                Layers.DisplayOrder(VertLines);
                Layers.DisplayOrderStartGroup("Barcode group");
                Layers.DisplayOrder(QRCodeLayer);
                Layers.DisplayOrder(Pdf417Layer);
                Layers.DisplayOrder(NoBarcodeLayer);
                Layers.DisplayOrderEndGroup();

                // start a group layer
                Contents.LayerStart(DrawingTest);

                // sticky note annotation
                PdfAnnotation StickyNote = Page.AddStickyNote(2.0, 9.0, "My sticky note", StickyNoteIcon.Note);
                StickyNote.LayerControl = DrawingTest;

                // draw a single layer
                Contents.LayerStart(Rectangle);
                Contents.DrawText(ArialFont, 14, 1.0, 8.0, TextJustify.Left, "Draw rectangle");
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(HorLines);
                Contents.DrawText(ArialFont, 14, 1.0, 7.5, TextJustify.Left, "Draw horizontal lines");
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(VertLines);
                Contents.DrawText(ArialFont, 14, 1.0, 7.0, TextJustify.Left, "Draw vertical lines");
                Contents.LayerEnd();

                double Left   = 4.0;
                double Right  = 7.0;
                double Top    = 9.0;
                double Bottom = 6.0;

                // draw a single layer
                Contents.LayerStart(Rectangle);
                Contents.SaveGraphicsState();
                Contents.SetLineWidth(0.1);
                Contents.SetColorStroking(Color.Black);
                Contents.SetColorNonStroking(Color.LightBlue);
                Contents.DrawRectangle(Left, Bottom, 3.0, 3.0, PaintOp.CloseFillStroke);
                Contents.RestoreGraphicsState();
                Contents.LayerEnd();

                // save graphics state
                Contents.SaveGraphicsState();

                // draw a single layer
                Contents.SetLineWidth(0.02);
                Contents.LayerStart(HorLines);
                for (int Row = 1; Row < 6; Row++)
                {
                    Contents.DrawLine(Left, Bottom + 0.5 * Row, Right, Bottom + 0.5 * Row);
                }
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(VertLines);
                for (int Col = 1; Col < 6; Col++)
                {
                    Contents.DrawLine(Left + 0.5 * Col, Bottom, Left + 0.5 * Col, Top);
                }
                Contents.LayerEnd();

                // restore graphics state
                Contents.RestoreGraphicsState();

                // terminate a group of layers
                Contents.LayerEnd();

                // define QRCode barcode
                QREncoder QREncoder = new QREncoder();
                QREncoder.ErrorCorrection = ErrorCorrection.M;
                QREncoder.Encode(QRCodeArticle);
                PdfImage QRImage = new PdfImage(Document);
                QRImage.LoadImage(QREncoder);

                // define PDF417 barcode
                Pdf417Encoder Pdf417Encoder = new Pdf417Encoder();
                Pdf417Encoder.ErrorCorrection = ErrorCorrectionLevel.AutoMedium;
                Pdf417Encoder.Encode(Pdf417Article);
                PdfImage Pdf417Image = new PdfImage(Document);
                Pdf417Image.LoadImage(Pdf417Encoder);

                // draw a single layer
                Contents.LayerStart(QRCodeLayer);
                Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "QRCode Barcode");
                Contents.DrawImage(QRImage, 3.7, 2.5 - 1.75, 3.5);
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(Pdf417Layer);
                Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "PDF417 Barcode");
                Contents.DrawImage(Pdf417Image, 3.7, 2.5 - 1.75 * Pdf417Encoder.ImageHeight / Pdf417Encoder.ImageWidth, 3.5);
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(NoBarcodeLayer);
                Contents.DrawText(ArialFont, 14, 1.0, 3.0, TextJustify.Left, "Display no barcode");
                Contents.LayerEnd();

                // create pdf file
                Document.CreateFile();

                // start default PDF reader and display the file
                Process Proc = new Process();
                Proc.StartInfo = new ProcessStartInfo(InputFileName);
                Proc.Start();
            }
            return;
        }
Example #11
0
 public void SetColor(Color fillCol)
 {
     cont.SetColorNonStroking(fillCol);
     cont.SetColorStroking(fillCol);
 }