//////////////////////////////////////////////////////////////////// // Draw frame around example area //////////////////////////////////////////////////////////////////// private void DrawFrameAndBackgroundWaterMark( PdfContents Contents ) { // 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); // use water mark tiling pattern to fill the frame Contents.SetPatternNonStroking(WaterMark); // 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); // restore graphics sate Contents.RestoreGraphicsState(); // draw article name under the frame // Note: the \u00a4 is character 164 that was substituted during Font resource definition // this character is a solid circle it is normally unicode 9679 or \u25cf in the Arial family Contents.DrawText(ArialNormal, 9.0, 1.1, 0.85, "PdfFileWriter \u00a4 PDF File Writer C# Class Library \u00a4 Author: Uzi Granot"); 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 rectangle with rounded corners and filled with brick pattern //////////////////////////////////////////////////////////////////// private void DrawBrickPattern( PdfDocument Document, PdfContents Contents ) { // Define brick tilling pattern resource // Arguments: PdfDocument class, Scale factor (0.25), Stroking color (lines between bricks), Nonstroking color (brick) // Return value: tilling pattern resource PdfTilingPattern BrickPattern = PdfTilingPattern.SetBrickPattern(Document, 0.25, Color.LightYellow, Color.SandyBrown); // save graphics state Contents.SaveGraphicsState(); // set outline width 0.04" Contents.SetLineWidth(0.04); // set outline color to purple Contents.SetColorStroking(Color.Purple); // set fill pattern to brick Contents.SetPatternNonStroking(BrickPattern); // draw rounded rectangle filled with brick pattern Contents.DrawRoundedRectangle(1.13, 5.0, 1.4, 1.4, 0.2, PaintOp.CloseFillStroke); // restore graphics sate Contents.RestoreGraphicsState(); return; }