예제 #1
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     Create new PdfTilingPattern class with weave pattern.
        /// </summary>
        /// <param name="Document">Current PDF document.</param>
        /// <param name="Scale">Scale factor</param>
        /// <param name="Background">Background color.</param>
        /// <param name="Horizontal">Horizontal line color.</param>
        /// <param name="Vertical">Vertical line color.</param>
        /// <returns>PDF tiling pattern</returns>
        /// <remarks>
        ///     <para>
        ///         The pattern in a square with one user unit side.
        ///     </para>
        ///     <para>
        ///         It is made of horizontal and vertical rectangles.
        ///     </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public static PdfTilingPattern SetWeavePattern
        (
            PdfDocument Document,
            double Scale,
            Color Background,
            Color Horizontal,
            Color Vertical
        )
        {
            const double RectSide1 = 4.0 / 6.0;
            const double RectSide2 = 2.0 / 6.0;
            const double LineWidth = 0.2 / 6.0;
            const double HalfWidth = 0.5 * LineWidth;

            var Pattern = new PdfTilingPattern(Document);

            Pattern.SetScale(Scale);
            Pattern.SaveGraphicsState();
            Pattern.SetTileBox(1.0);
            Pattern.SetColorNonStroking(Background);
            Pattern.DrawRectangle(0.0, 0.0, 1.0, 1.0, PaintOp.Fill);
            Pattern.SetLineWidth(LineWidth);
            Pattern.SetColorStroking(Background);

            Pattern.SetColorNonStroking(Horizontal);
            Pattern.DrawRectangle(HalfWidth, 1.0 / 6.0 + HalfWidth, RectSide1 - LineWidth, RectSide2 - LineWidth,
                                  PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(-(3.0 / 6.0 - HalfWidth), 4.0 / 6.0 + HalfWidth, RectSide1 - LineWidth,
                                  RectSide2 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(3.0 / 6.0 + HalfWidth, 4.0 / 6.0 + HalfWidth, RectSide1 - LineWidth,
                                  RectSide2 - LineWidth, PaintOp.CloseFillStroke);

            Pattern.SetColorNonStroking(Vertical);
            Pattern.DrawRectangle(4.0 / 6.0 + HalfWidth, HalfWidth, RectSide2 - LineWidth, RectSide1 - LineWidth,
                                  PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(1.0 / 6.0 + HalfWidth, -(3.0 / 6.0 - HalfWidth), RectSide2 - LineWidth,
                                  RectSide1 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(1.0 / 6.0 + HalfWidth, 3.0 / 6.0 + HalfWidth, RectSide2 - LineWidth,
                                  RectSide1 - LineWidth, PaintOp.CloseFillStroke);

            Pattern.RestoreGraphicsState();
            return(Pattern);
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////
        // Create new PdfTilingPattern class with brick paatern
        // The pattern in a square with one user unit side.
        // The bottom half is one brick. The top half is two half bricks.
        // Arguments:
        // Scale the pattern to your requierments.
        // Stroking color is the mortar color.
        // Nonstrokink color is th brick color.
        ////////////////////////////////////////////////////////////////////

        public static PdfTilingPattern SetBrickPattern
        (
            PdfDocument Document,
            Double Scale,
            Color Stroking,
            Color NonStroking
        )
        {
            PdfTilingPattern Pattern = new PdfTilingPattern(Document);

            Pattern.SetScale(Scale);
            Pattern.SaveGraphicsState();
            Pattern.SetLineWidth(0.05);
            Pattern.SetColorStroking(Stroking);
            Pattern.SetColorNonStroking(NonStroking);
            Pattern.DrawRectangle(0.025, 0.025, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(-0.475, 0.525, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(0.525, 0.525, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.RestoreGraphicsState();
            return(Pattern);
        }
예제 #3
0
        // Define Tiling Pattern Resource
        private void DefineTilingPatternResource()
        {
            // create empty tiling pattern
            WaterMark = new PdfTilingPattern(Document);
            WaterMarkToPDF = new PdfTilingPattern(DocumentToPDF);

            // the pattern will be PdfFileWriter layed out in brick pattern
            String Mark = "PdfFileWriter";

            // text width and height for Arial bold size 18 points
            Double FontSize = 18.0;
            Double TextWidth = ArialBold.TextWidth(FontSize, Mark);
            Double TextHeight = ArialBold.LineSpacing(FontSize);

            // text base line
            Double BaseLine = ArialBold.DescentPlusLeading(FontSize);

            // the overall pattern box (we add text height value as left and right text margin)
            Double BoxWidth = TextWidth + 2 * TextHeight;
            Double BoxHeight = 4 * TextHeight;

            WaterMark.SetTileBox(BoxWidth, BoxHeight);
            WaterMark.SaveGraphicsState();
            WaterMark.SetColorNonStroking(Color.FromArgb(230, 244, 255));
            WaterMark.DrawRectangle(0, 0, BoxWidth, BoxHeight, PaintOp.Fill);
            WaterMark.SetColorNonStroking(Color.White);
            WaterMark.DrawText(ArialBold, FontSize, BoxWidth / 2, BaseLine, TextJustify.Center, Mark);

            WaterMarkToPDF.SetTileBox(BoxWidth, BoxHeight);
            WaterMarkToPDF.SaveGraphicsState();
            WaterMarkToPDF.SetColorNonStroking(Color.FromArgb(230, 244, 255));
            WaterMarkToPDF.DrawRectangle(0, 0, BoxWidth, BoxHeight, PaintOp.Fill);
            WaterMarkToPDF.SetColorNonStroking(Color.White);
            WaterMarkToPDF.DrawText(ArialBold, FontSize, BoxWidth / 2, BaseLine, TextJustify.Center, Mark);

            BaseLine += BoxHeight / 2;

            WaterMark.DrawText(ArialBold, FontSize, 0.0, BaseLine, TextJustify.Center, Mark);
            WaterMark.DrawText(ArialBold, FontSize, BoxWidth, BaseLine, TextJustify.Center, Mark);
            WaterMark.RestoreGraphicsState();

            WaterMarkToPDF.DrawText(ArialBold, FontSize, 0.0, BaseLine, TextJustify.Center, Mark);
            WaterMarkToPDF.DrawText(ArialBold, FontSize, BoxWidth, BaseLine, TextJustify.Center, Mark);
            WaterMarkToPDF.RestoreGraphicsState();

            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Define Tiling Pattern Resource
        ////////////////////////////////////////////////////////////////////
        private void DefineTilingPatternResource(
			PdfDocument Document
			)
        {
            // create empty tiling pattern
            WaterMark = new PdfTilingPattern(Document);

            // the pattern will be PdfFileWriter laied out in brick pattern
            String Mark = "PdfFileWriter";

            // text width and height for Arial bold size 18 points
            Double FontSize = 18.0;
            Double TextWidth = ArialBold.TextWidth(FontSize, Mark);
            Double TextHeight = ArialBold.LineSpacing(FontSize);

            // text base line
            Double BaseLine = ArialBold.DescentPlusLeading(FontSize);

            // the overall pattern box (we add text height value as left and right text margin)
            Double BoxWidth = TextWidth + 2 * TextHeight;
            Double BoxHeight = 4 * TextHeight;
            WaterMark.SetTileBox(BoxWidth, BoxHeight);

            // save graphics state
            WaterMark.SaveGraphicsState();

            // fill the pattern box with background light blue color
            WaterMark.SetColorNonStroking(Color.FromArgb(230, 244, 255));
            WaterMark.DrawRectangle(0, 0, BoxWidth, BoxHeight, PaintOp.Fill);

            // set fill color for water mark text to white
            WaterMark.SetColorNonStroking(Color.White);

            // draw PdfFileWriter at the bottom center of the box
            WaterMark.DrawText(ArialBold, FontSize, BoxWidth / 2, BaseLine, TextJustify.Center, Mark);

            // adjust base line upward by half height
            BaseLine += BoxHeight / 2;

            // draw the right half of PdfFileWriter shifted left by half width
            WaterMark.DrawText(ArialBold, FontSize, 0.0, BaseLine, TextJustify.Center, Mark);

            // draw the left half of PdfFileWriter shifted right by half width
            WaterMark.DrawText(ArialBold, FontSize, BoxWidth, BaseLine, TextJustify.Center, Mark);

            // restore graphics state
            WaterMark.RestoreGraphicsState();
            return;
        }
 private void DefineTilingPatternResource()
 {
     WaterMark = new PdfTilingPattern(Document);
     String Mark = "PdfFileWriter";
     Double FontSize = 18.0;
     Double TextWidth = ArialBold.TextWidth(FontSize, Mark);
     Double TextHeight = ArialBold.LineSpacing(FontSize);
     Double BaseLine = ArialBold.DescentPlusLeading(FontSize);
     Double BoxWidth = TextWidth + 2 * TextHeight;
     Double BoxHeight = 4 * TextHeight;
     WaterMark.SetTileBox(BoxWidth, BoxHeight);
     WaterMark.SaveGraphicsState();
     WaterMark.SetColorNonStroking(Color.FromArgb(230, 244, 255));
     WaterMark.DrawRectangle(0, 0, BoxWidth, BoxHeight, PaintOp.Fill);
     WaterMark.SetColorNonStroking(Color.White);
     WaterMark.DrawText(ArialBold, FontSize, BoxWidth / 2, BaseLine, TextJustify.Center, Mark);
     BaseLine += BoxHeight / 2;
     WaterMark.DrawText(ArialBold, FontSize, 0.0, BaseLine, TextJustify.Center, Mark);
     WaterMark.DrawText(ArialBold, FontSize, BoxWidth, BaseLine, TextJustify.Center, Mark);
     WaterMark.RestoreGraphicsState();
     return;
 }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Create new PdfTilingPattern class with weave pattern.
        /// </summary>
        /// <param name="Document">Current PDF document.</param>
        /// <param name="Scale">Scale factor</param>
        /// <param name="Background">Background color.</param>
        /// <param name="Horizontal">Horizontal line color.</param>
        /// <param name="Vertical">Vertical line color.</param>
        /// <returns>PDF tiling pattern</returns>
        /// <remarks>
        /// <para>
        /// The pattern in a square with one user unit side.
        /// </para>
        /// <para>
        /// It is made of horizontal and vertical rectangles.
        /// </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public static PdfTilingPattern SetWeavePattern(
			PdfDocument		Document,
			Double			Scale,
			Color			Background,
			Color			Horizontal,
			Color			Vertical
			)
        {
            const Double RectSide1 = 4.0 / 6.0;
            const Double RectSide2 = 2.0 / 6.0;
            const Double LineWidth = 0.2 / 6.0;
            const Double HalfWidth = 0.5 * LineWidth;

            PdfTilingPattern Pattern = new PdfTilingPattern(Document);
            Pattern.SetScale(Scale);
            Pattern.SaveGraphicsState();
            Pattern.SetTileBox(1.0);
            Pattern.SetColorNonStroking(Background);
            Pattern.DrawRectangle(0.0, 0.0, 1.0, 1.0, PaintOp.Fill);
            Pattern.SetLineWidth(LineWidth);
            Pattern.SetColorStroking(Background);

            Pattern.SetColorNonStroking(Horizontal);
            Pattern.DrawRectangle(HalfWidth, 1.0 / 6.0 + HalfWidth, RectSide1 - LineWidth, RectSide2 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(-(3.0 / 6.0 - HalfWidth), 4.0 / 6.0 + HalfWidth, RectSide1 - LineWidth, RectSide2 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(3.0 / 6.0 + HalfWidth, 4.0 / 6.0 + HalfWidth, RectSide1 - LineWidth, RectSide2 - LineWidth, PaintOp.CloseFillStroke);

            Pattern.SetColorNonStroking(Vertical);
            Pattern.DrawRectangle(4.0 / 6.0 + HalfWidth, HalfWidth, RectSide2 - LineWidth, RectSide1 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(1.0 / 6.0 + HalfWidth, -(3.0 / 6.0 - HalfWidth), RectSide2 - LineWidth, RectSide1 - LineWidth, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(1.0 / 6.0 + HalfWidth, 3.0 / 6.0 + HalfWidth, RectSide2 - LineWidth, RectSide1 - LineWidth, PaintOp.CloseFillStroke);

            Pattern.RestoreGraphicsState();
            return(Pattern);
        }
        //////////////////////////////////////////////////////////////////// 
        /// <summary>
        /// Create new PdfTilingPattern class with brick pattern.
        /// </summary>
        /// <param name="Document">Current document object.</param>
        /// <param name="Scale">Scale factor.</param>
        /// <param name="Stroking">Stroking color.</param>
        /// <param name="NonStroking">Non-stroking color.</param>
        /// <returns>PDF tiling pattern</returns>
        /// <remarks>
        /// <para>
        /// The pattern is a square with one user unit side.
        /// </para>
        /// <para>
        /// The bottom half is one brick. The top half is two half bricks.
        /// </para>
        /// <para>
        /// Arguments:
        /// </para>
        /// <para>
        /// Scale the pattern to your requirements.
        /// </para>
        /// <para>
        /// Stroking color is the mortar color.
        /// </para>
        /// <para>
        /// Nonstroking color is the brick color.
        /// </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public static PdfTilingPattern SetBrickPattern(
			PdfDocument		Document,
			Double			Scale,
			Color			Stroking,
			Color			NonStroking
			)
        {
            PdfTilingPattern Pattern = new PdfTilingPattern(Document);
            Pattern.SetScale(Scale);
            Pattern.SaveGraphicsState();
            Pattern.SetLineWidth(0.05);
            Pattern.SetColorStroking(Stroking);
            Pattern.SetColorNonStroking(NonStroking);
            Pattern.DrawRectangle(0.025, 0.025, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(-0.475, 0.525, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.DrawRectangle(0.525, 0.525, 0.95, 0.45, PaintOp.CloseFillStroke);
            Pattern.RestoreGraphicsState();
            return(Pattern);
        }