////////////////////////////////////////////////////////////////////
        // Draw image of a flower and clip it
        ////////////////////////////////////////////////////////////////////

        private void DrawFlower
        (
            PdfDocument Document,
            PdfContents Contents
        )
        {
            // define local image resources
            PdfImage Image1 = new PdfImage(Document, "flower.jpg");

            // image size will be limited to 1.4" by 1.4"
            SizeD ImageSize = Image1.ImageSize(1.4, 1.4);

            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            Contents.Translate(3.36, 5.7);

            // clipping path
            Contents.DrawOval(-ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height, PaintOp.ClipPathEor);

            // draw image
            Contents.DrawImage(Image1, -ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Пример #2
0
        private void DrawLogImage()
        {
            // define local image resources
            // resolution 96 pixels per inch, image quality 100%
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 96.0;
            ImageControl.ImageQuality = 100;

            CreateLogoFile();

            PdfImage Image1 = new PdfImage(Document, "temps/" + pk.Logo.Filename, ImageControl);

            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            Contents.Translate(0, 10);

            // adjust image size an preserve aspect ratio
            PdfRectangle NewSize = Image1.ImageSizePosition(3, 1.1, ContentAlignment.MiddleCenter);

            // clipping path
            Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.Fill);

            // draw image
            Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height);

            // 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;
        }