コード例 #1
0
        private static void DrawPatterns(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush    = new PdfBrush();
            PdfPen   blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfPen   darkRedPen       = new PdfPen(new PdfRgbColor(0xFF, 0x40, 0x40), 0.8);
            PdfPen   darkOrangePen    = new PdfPen(new PdfRgbColor(0xA6, 0x4B, 0x00), 0.8);
            PdfPen   darkCyanPen      = new PdfPen(new PdfRgbColor(0x00, 0x63, 0x63), 0.8);
            PdfPen   darkGreenPen     = new PdfPen(new PdfRgbColor(0x00, 0x85, 0x00), 0.8);
            PdfBrush lightRedBrush    = new PdfBrush(new PdfRgbColor(0xFF, 0x73, 0x73));
            PdfBrush lightOrangeBrush = new PdfBrush(new PdfRgbColor(0xFF, 0x96, 0x40));
            PdfBrush lightCyanBrush   = new PdfBrush(new PdfRgbColor(0x33, 0xCC, 0xCC));
            PdfBrush lightGreenBrush  = new PdfBrush(new PdfRgbColor(0x67, 0xE6, 0x67));

            page.Graphics.DrawString("Patterns", titleFont, brush, 20, 50);

            page.Graphics.DrawString("Colored patterns", sectionFont, brush, 25, 70);

            // Create the pattern visual appearance.
            PdfColoredTilingPattern ctp = new PdfColoredTilingPattern(20, 20);

            // Red circle
            ctp.Graphics.DrawEllipse(darkRedPen, lightRedBrush, 1, 1, 8, 8);
            // Cyan square
            ctp.Graphics.DrawRectangle(darkCyanPen, lightCyanBrush, 11, 1, 8, 8);
            // Green diamond
            PdfPath diamondPath = new PdfPath();

            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            ctp.Graphics.DrawPath(darkGreenPen, lightGreenBrush, diamondPath);
            // Orange triangle
            PdfPath trianglePath = new PdfPath();

            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            ctp.Graphics.DrawPath(darkOrangePen, lightOrangeBrush, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace coloredPatternColorSpace = new PdfPatternColorSpace(ctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor coloredPatternColor = new PdfPatternColor(coloredPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            PdfPatternBrush patternBrush = new PdfPatternBrush(coloredPatternColor);
            PdfPatternPen   patternPen   = new PdfPatternPen(coloredPatternColor, 40);

            page.Graphics.DrawEllipse(patternBrush, 25, 90, 250, 200);
            page.Graphics.DrawRoundRectangle(patternPen, 310, 110, 250, 160, 100, 100);

            page.Graphics.DrawString("Uncolored patterns", sectionFont, brush, 25, 300);

            // Create the pattern visual appearance.
            PdfUncoloredTilingPattern uctp = new PdfUncoloredTilingPattern(20, 20);
            // A pen without color is used to create the pattern content.
            PdfPen noColorPen = new PdfPen(null, 0.8);

            // Circle
            uctp.Graphics.DrawEllipse(noColorPen, 1, 1, 8, 8);
            // Square
            uctp.Graphics.DrawRectangle(noColorPen, 11, 1, 8, 8);
            // Diamond
            diamondPath = new PdfPath();
            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, diamondPath);
            // Triangle
            trianglePath = new PdfPath();
            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace uncoloredPatternColorSpace = new PdfPatternColorSpace(uctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor uncoloredPatternColor = new PdfPatternColor(uncoloredPatternColorSpace);

            // The pen and brush use the pattern color like any other color.
            patternBrush = new PdfPatternBrush(uncoloredPatternColor);

            // Before using the uncolored pattern set the color that will be used to paint the pattern.
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xFF, 0x40, 0x40);
            page.Graphics.DrawEllipse(patternBrush, 25, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xA6, 0x4B, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 175, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x63, 0x63);
            page.Graphics.DrawEllipse(patternBrush, 325, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x85, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 475, 320, 125, 200);

            page.Graphics.DrawString("Shading patterns", sectionFont, brush, 25, 550);

            // Create the pattern visual appearance.
            PdfAxialShading horizontalShading = new PdfAxialShading();

            horizontalShading.StartColor = new PdfRgbColor(255, 0, 0);
            horizontalShading.EndColor   = new PdfRgbColor(0, 0, 255);
            horizontalShading.StartPoint = new PdfPoint(25, 600);
            horizontalShading.EndPoint   = new PdfPoint(575, 600);
            PdfShadingPattern sp = new PdfShadingPattern(horizontalShading);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace shadingPatternColorSpace = new PdfPatternColorSpace(sp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor shadingPatternColor = new PdfPatternColor(shadingPatternColorSpace);

            // The pen and brush use the pattern color like any other color.
            patternPen = new PdfPatternPen(shadingPatternColor, 40);

            page.Graphics.DrawEllipse(patternPen, 50, 600, 500, 150);

            page.Graphics.CompressAndClose();
        }
コード例 #2
0
        private static void DrawPatterns(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfPen darkRedPen = new PdfPen(new PdfRgbColor(0xFF, 0x40, 0x40), 0.8);
            PdfPen darkOrangePen = new PdfPen(new PdfRgbColor(0xA6, 0x4B, 0x00), 0.8);
            PdfPen darkCyanPen = new PdfPen(new PdfRgbColor(0x00, 0x63, 0x63), 0.8);
            PdfPen darkGreenPen = new PdfPen(new PdfRgbColor(0x00, 0x85, 0x00), 0.8);
            PdfBrush lightRedBrush = new PdfBrush(new PdfRgbColor(0xFF, 0x73, 0x73));
            PdfBrush lightOrangeBrush = new PdfBrush(new PdfRgbColor(0xFF, 0x96, 0x40));
            PdfBrush lightCyanBrush = new PdfBrush(new PdfRgbColor(0x33, 0xCC, 0xCC));
            PdfBrush lightGreenBrush = new PdfBrush(new PdfRgbColor(0x67, 0xE6, 0x67));

            page.Graphics.DrawString("Patterns", titleFont, brush, 20, 50);

            page.Graphics.DrawString("Colored patterns", sectionFont, brush, 25, 70);

            // Create the pattern visual appearance.
            PdfColoredTilingPattern ctp = new PdfColoredTilingPattern(20, 20);
            // Red circle
            ctp.Graphics.DrawEllipse(darkRedPen, lightRedBrush, 1, 1, 8, 8);
            // Cyan square
            ctp.Graphics.DrawRectangle(darkCyanPen, lightCyanBrush, 11, 1, 8, 8);
            // Green diamond
            PdfPath diamondPath = new PdfPath();
            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            ctp.Graphics.DrawPath(darkGreenPen, lightGreenBrush, diamondPath);
            // Orange triangle
            PdfPath trianglePath = new PdfPath();
            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            ctp.Graphics.DrawPath(darkOrangePen, lightOrangeBrush, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace coloredPatternColorSpace = new PdfPatternColorSpace(ctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor coloredPatternColor = new PdfPatternColor(coloredPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            PdfPatternBrush patternBrush = new PdfPatternBrush(coloredPatternColor);
            PdfPatternPen patternPen = new PdfPatternPen(coloredPatternColor, 40);

            page.Graphics.DrawEllipse(patternBrush, 25, 90, 250, 200);
            page.Graphics.DrawRoundRectangle(patternPen, 310, 110, 250, 160, 100, 100);

            page.Graphics.DrawString("Uncolored patterns", sectionFont, brush, 25, 300);

            // Create the pattern visual appearance.
            PdfUncoloredTilingPattern uctp = new PdfUncoloredTilingPattern(20, 20);
            // A pen without color is used to create the pattern content.
            PdfPen noColorPen = new PdfPen(null, 0.8);
            // Circle
            uctp.Graphics.DrawEllipse(noColorPen, 1, 1, 8, 8);
            // Square
            uctp.Graphics.DrawRectangle(noColorPen, 11, 1, 8, 8);
            // Diamond
            diamondPath = new PdfPath();
            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, diamondPath);
            // Triangle
            trianglePath = new PdfPath();
            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace uncoloredPatternColorSpace = new PdfPatternColorSpace(uctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor uncoloredPatternColor = new PdfPatternColor(uncoloredPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            patternBrush = new PdfPatternBrush(uncoloredPatternColor);

            // Before using the uncolored pattern set the color that will be used to paint the pattern.
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xFF, 0x40, 0x40);
            page.Graphics.DrawEllipse(patternBrush, 25, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xA6, 0x4B, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 175, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x63, 0x63);
            page.Graphics.DrawEllipse(patternBrush, 325, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x85, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 475, 320, 125, 200);

            page.Graphics.DrawString("Shading patterns", sectionFont, brush, 25, 550);

            // Create the pattern visual appearance.
            PdfAxialShading horizontalShading = new PdfAxialShading();
            horizontalShading.StartColor = new PdfRgbColor(255, 0, 0);
            horizontalShading.EndColor = new PdfRgbColor(0, 0, 255);
            horizontalShading.StartPoint = new PdfPoint(25, 600);
            horizontalShading.EndPoint = new PdfPoint(575, 600);
            PdfShadingPattern sp = new PdfShadingPattern(horizontalShading);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace shadingPatternColorSpace = new PdfPatternColorSpace(sp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor shadingPatternColor = new PdfPatternColor(shadingPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            patternPen = new PdfPatternPen(shadingPatternColor, 40);

            page.Graphics.DrawEllipse(patternPen, 50, 600, 500, 150);

            page.Graphics.CompressAndClose();
        }