Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkOverPageContent(PdfPage page)
        {
            PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0));
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 32);

            // The page graphics is located by default on top of existing page content.
            //page.SetGraphicsPosition(PdfPageGraphicsPosition.OverExistingPageContent);

            // Draw the watermark over page content.
            // Page content under the watermark will be masked.
            page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 335);

            page.Graphics.SaveGraphicsState();

            // Draw the watermark over page content but using the Multiply blend mode.
            // The watermak will appear as if drawn under the page content, useful when watermarking scanned documents.
            // If the watermark is drawn under page content for scanned documents, it will not be visible because the scanned image will block it.
            PdfExtendedGraphicState gs1 = new PdfExtendedGraphicState();
            gs1.BlendMode = PdfBlendMode.Multiply;
            page.Graphics.SetExtendedGraphicState(gs1);
            page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 385);

            // Draw the watermark over page content but using the Luminosity blend mode.
            // Both the page content and the watermark will be visible.
            PdfExtendedGraphicState gs2 = new PdfExtendedGraphicState();
            gs2.BlendMode = PdfBlendMode.Luminosity;
            page.Graphics.SetExtendedGraphicState(gs2);
            page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 435);

            page.Graphics.RestoreGraphicsState();
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Construct new instnace of the PrintPageLoadedEventArgs class
		/// </summary>
		/// <param name="page">The page what will be printed.</param>
		/// <param name="width">The page's width calculated to match the sheet size.</param>
		/// <param name="height">The page's height calculated to match the sheet size.</param>
		/// <param name="rotation">The page rotation.</param>
		public BeforeRenderPageEventArgs(PdfPage page, double width, double height, PageRotate rotation)
		{
			Page = page;
			Width = width;
			Height = height;
			Rotation = rotation;
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the content stream(s) of the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        static public CSequence ReadContent(PdfPage page)
        {
            CParser parser = new CParser(page);
            CSequence sequence = parser.ReadContent();

            return sequence;
        }
Ejemplo n.º 4
0
 public CParser(PdfPage page)
 {
     _page = page;
     PdfContent content = page.Contents.CreateSingleContent();
     byte[] bytes = content.Stream.Value;
     _lexer = new CLexer(bytes);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkUnderPageContent(PdfPage page)
        {
            PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0));
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 36);

            // Set the page graphics to be located under existing page content.
            page.SetGraphicsPosition(PdfPageGraphicsPosition.UnderExistingPageContent);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = redBrush;
            sao.Font = helvetica;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.X = 130;
            slo.Y = 670;
            slo.Rotation = 60;
            page.Graphics.DrawString("Sample watermark under page content", sao, slo);
        }
Ejemplo n.º 6
0
        private static void HighlightSearchResults(PdfPage page, PdfTextSearchResultCollection searchResults, PdfColor color)
        {
            PdfPen pen = new PdfPen(color, 0.5);

            for (int i = 0; i < searchResults.Count; i++)
            {
                PdfTextFragmentCollection tfc = searchResults[i].TextFragments;
                for (int j = 0; j < tfc.Count; j++)
                {
                    PdfPath path = new PdfPath();

                    path.StartSubpath(tfc[j].FragmentCorners[0].X, tfc[j].FragmentCorners[0].Y);
                    path.AddPolygon(tfc[j].FragmentCorners);

                    page.Graphics.DrawPath(pen, path);
                }
            }
        }
Ejemplo n.º 7
0
        private static void DisableTextCopy(PdfPage page, Stream ttfStream)
        {
            PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 22);
            PdfBrush blackBrush = new PdfBrush(new PdfRgbColor());

            page.Graphics.DrawString("Draw text that cannot be copied and", titleFont, blackBrush, 20, 50);
            page.Graphics.DrawString("pasted in another applications", titleFont, blackBrush, 20, 75);

            ttfStream.Position = 0;
            PdfUnicodeTrueTypeFont f1 = new PdfUnicodeTrueTypeFont(ttfStream, 16, true);
            page.Graphics.DrawString("This text can be copied and pasted", f1, blackBrush, 20, 150);
            page.Graphics.DrawString("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", f1, blackBrush, 20, 175);

            ttfStream.Position = 0;
            PdfUnicodeTrueTypeFont f2 = new PdfUnicodeTrueTypeFont(ttfStream, 16, true);
            f2.EnableTextCopy = false;
            page.Graphics.DrawString("This text cannot be copied and pasted.", f2, blackBrush, 20, 225);
            page.Graphics.DrawString("Praesent sed massa a est fringilla mattis. Aenean sit amet odio ac nunc.", f2, blackBrush, 20, 250);
        }
Ejemplo n.º 8
0
        private static void DrawAffineTransformations(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);
            PdfPen bluePen = new PdfPen(PdfRgbColor.Blue, 1);
            PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 1);

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

            page.Graphics.DrawLine(blackPen, 0, page.Height / 2, page.Width, page.Height / 2);
            page.Graphics.DrawLine(blackPen, page.Width / 2, 0, page.Width / 2, page.Height);

            page.Graphics.SaveGraphicsState();

            // Move the coordinate system in the center of the page.
            page.Graphics.TranslateTransform(page.Width / 2, page.Height / 2);

            // Draw a rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(redPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Rotate the coordinate system with 30 degrees.
            page.Graphics.RotateTransform(30);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(greenPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Scale the coordinate system with 1.5
            page.Graphics.ScaleTransform(1.5, 1.5);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(bluePen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            page.Graphics.RestoreGraphicsState();

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        private static void DrawBezierCurves(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);
            PdfBrush blueBrush = new PdfBrush(PdfRgbColor.DarkBlue);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);

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

            page.Graphics.DrawLine(blackPen, 20, 210, 600, 210);
            page.Graphics.DrawLine(blackPen, 306, 70, 306, 350);
            page.Graphics.DrawRectangle(blueBrush, 39, 339, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 279, 79, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 499, 299, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 589, 69, 2, 2);
            page.Graphics.DrawBezier(redPen, 40, 340, 280, 80, 500, 300, 590, 70);

            page.Graphics.DrawString("Random bezier curves clipped to view", sectionFont, brush, 20, 385);
            PdfPath rectPath = new PdfPath();
            rectPath.AddRectangle(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(rectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                double x1 = rnd.NextDouble() * page.Width;
                double y1 = 380 + rnd.NextDouble() * 350;
                double x2 = rnd.NextDouble() * page.Width;
                double y2 = 380 + rnd.NextDouble() * 350;
                double x3 = rnd.NextDouble() * page.Width;
                double y3 = 380 + rnd.NextDouble() * 350;
                double x4 = rnd.NextDouble() * page.Width;
                double y4 = 380 + rnd.NextDouble() * 350;

                page.Graphics.DrawBezier(randomPen, x1, y1, x2, y2, x3, y3, x4, y4);
            }

            page.Graphics.RestoreGraphicsState();

            blackPen.DashPattern = null;
            page.Graphics.DrawPath(blackPen, rectPath);

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 11
0
        private static void DrawFormXObjects(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Form XObjects", titleFont, brush, 20, 50);
            page.Graphics.DrawString("Scaling", sectionFont, brush, 20, 70);

            // Create the XObject content - random rectangles
            PdfFormXObject xobject = new PdfFormXObject(300, 300);
            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                double left = rnd.NextDouble() * xobject.Width;
                double top = rnd.NextDouble() * xobject.Height;
                double width = rnd.NextDouble() * xobject.Width;
                double height = rnd.NextDouble() * xobject.Height;
                double orientation = rnd.Next(360);
                xobject.Graphics.DrawRectangle(randomPen, randomBrush, left, top, width, height, orientation);
            }

            xobject.Graphics.DrawRectangle(blackPen, 0, 0, xobject.Width, xobject.Height);
            xobject.Graphics.CompressAndClose();

            // Draw the form XObject 3 times on the page at different sizes.
            page.Graphics.DrawFormXObject(xobject, 3, 90, 100, 100);
            page.Graphics.DrawFormXObject(xobject, 106, 90, 200, 200);
            page.Graphics.DrawFormXObject(xobject, 309, 90, 300, 300);

            page.Graphics.DrawString("Flipping", sectionFont, brush, 20, 420);
            page.Graphics.DrawFormXObject(xobject, 20, 440, 150, 150);
            page.Graphics.DrawFormXObject(xobject, 200, 440, 150, 150, 0, PdfFlipDirection.VerticalFlip);
            page.Graphics.DrawFormXObject(xobject, 20, 620, 150, 150, 0, PdfFlipDirection.HorizontalFlip);
            page.Graphics.DrawFormXObject(xobject, 200, 620, 150, 150, 0, PdfFlipDirection.VerticalFlip | PdfFlipDirection.HorizontalFlip);

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int Digit(int num)//数字の桁数を求める関数
            {
                // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
                return((num == 0) ? 1 : ((int)Math.Log10(num) + 1));
            }

            XColor RGB(double h, double s, double l)//convert HSL to RGB
            {
                var max = 0.0; var min = 0.0; var R = 0.0; var g = 0.0; var b = 0.0;

                if (l < 0.5)
                {
                    max = l + l * s;
                    min = l - l * s;
                }
                else
                {
                    max = l + (1 - l) * s;
                    min = l - (1 - l) * s;
                }
                var HUE_MAX = 360.0; var RGB_MAX = 255;
                var hp = HUE_MAX / 6.0; h *= HUE_MAX; var q = h / hp;

                if (q <= 1)
                {
                    R = max;
                    g = (h / hp) * (max - min) + min;
                    b = min;
                }
                else if (q <= 2)
                {
                    R = ((hp * 2 - h) / hp) * (max - min) + min;
                    g = max;
                    b = min;
                }
                else if (q <= 3)
                {
                    R = min;
                    g = max;
                    b = ((h - hp * 2) / hp) * (max - min) + min;
                }
                else if (q <= 4)
                {
                    R = min;
                    g = ((hp * 4 - h) / hp) * (max - min) + min;
                    b = max;
                }
                else if (q <= 5)
                {
                    R = ((h - hp * 4) / hp) * (max - min) + min;
                    g = min;
                    b = max;
                }
                else
                {
                    R = max;
                    g = min;
                    b = ((HUE_MAX - h) / hp) * (max - min) + min;
                }
                R *= RGB_MAX; g *= RGB_MAX; b *= RGB_MAX;
                return(XColor.FromArgb((int)R, (int)g, (int)b));
            }

            Vector3d rotation(Vector3d a, Vector3d b, double theta)
            {
                double rad = theta * Math.PI / 180;
                double s = Math.Sin(rad); double c = Math.Cos(rad);

                b /= Math.Sqrt(Vector3d.Multiply(b, b));
                double   b1 = b[0]; double b2 = b[1]; double b3 = b[2];
                Vector3d m1 = new Vector3d(c + Math.Pow(b1, 2) * (1 - c), b1 * b2 * (1 - c) - b3 * s, b1 * b3 * (1 - c) + b2 * s);
                Vector3d m2 = new Vector3d(b2 * b1 * (1 - c) + b3 * s, c + Math.Pow(b2, 2) * (1 - c), b2 * b3 * (1 - c) - b1 * s);
                Vector3d m3 = new Vector3d(b3 * b1 * (1 - c) - b2 * s, b3 * b2 * (1 - c) + b1 * s, c + Math.Pow(b3, 2) * (1 - c));

                return(new Vector3d(Vector3d.Multiply(m1, a), Vector3d.Multiply(m2, a), Vector3d.Multiply(m3, a)));
            }

            var doc = RhinoDoc.ActiveDoc;

            DA.GetDataTree("R", out GH_Structure <GH_Number> _r); var           r = _r.Branches;
            DA.GetDataTree("reac_f", out GH_Structure <GH_Number> _reac_f); var reac_f = _reac_f.Branches; var m = reac_f.Count;
            List <string> layer = new List <string>(); var nameB = "布基礎"; var namet = "t"; var namerho = "ρ"; var nameD = "D"; var namepitch = "@"; var nameft = "ft"; var namew = "w"; var nameac = "as";

            DA.GetDataList("layer", layer); DA.GetData("name B", ref nameB); DA.GetData("name t", ref namet); DA.GetData("name rho", ref namerho); DA.GetData("name bar", ref nameD); DA.GetData("name pitch", ref namepitch); DA.GetData("name ft", ref nameft); DA.GetData("name w", ref namew); DA.GetData("name as", ref nameac);
            DA.GetData("FS", ref fontsize);
            var pdfname = "StripBase"; DA.GetData("outputname", ref pdfname);

            var pressure = new List <double>(); var baseshape = new List <Curve>(); var baseline = new List <List <Point3d> >();
            var B = new List <double>(); var T = new List <double>(); var L = new List <double>(); var Rz = new List <double>(); var Sz = new List <double>(); var A = new List <double>();
            var bar = new List <string>(); var M = new List <double>(); var Ma = new List <double>(); var LL = new List <double>(); var Ft = new List <double>(); var J = new List <double>(); var At = new List <double>(); var Ac = new List <double>();

            for (int i = 0; i < layer.Count; i++)
            {
                var line = doc.Objects.FindByLayer(layer[i]);
                for (int j = 0; j < line.Length; j++)
                {
                    var le = line[j];
                    var re = new ObjRef(le);
                    var l = re.Curve(); baseshape.Add(l);
                    var r1 = l.PointAtStart; var r2 = l.PointAtEnd; var l2 = r2 - r1;
                    baseline.Add(new List <Point3d> {
                        r1, r2
                    });
                    var N = 0.0;
                    for (int k = 0; k < m; k++)
                    {
                        int e  = (int)reac_f[k][0].Value;
                        var pt = new Point3d(r[e][0].Value, r[e][1].Value, r[e][2].Value);
                        var l1 = pt - r1;
                        if (l2.Length - l1.Length >= -1e-8 && (l1 / l1.Length - l2 / l2.Length).Length < 1e-8)
                        {
                            N += reac_f[k][3].Value;
                        }
                    }
                    var b   = float.Parse(le.Attributes.GetUserString(nameB));
                    var t   = float.Parse(le.Attributes.GetUserString(namet));
                    var rho = float.Parse(le.Attributes.GetUserString(namerho));
                    L.Add(l2.Length); A.Add(b * L[j]);
                    B.Add(b); T.Add(t); Rz.Add(N); Sz.Add(t * A[j] * rho);
                    var prs = (N + Sz[j]) / A[j];
                    pressure.Add(prs);
                    if (BaseWidth == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(b.ToString("F6").Substring(0, digit) + unit_of_length);
                        _c2.Add(Color.Blue);
                    }
                    if (BaseNo == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(j.ToString());
                        _c2.Add(Color.Black);
                    }
                    if (BaseThick == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(t.ToString("F6").Substring(0, digit) + unit_of_length);
                        _c2.Add(Color.Purple);
                    }
                    if (Pressure == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(prs.ToString("F6").Substring(0, digit) + unit_of_force + "/" + unit_of_length + "2");
                        _c2.Add(Color.Red);
                    }
                    if (BaseShape == 1)
                    {
                        Random rand1 = new Random((i + 1) * (j + 1) * 1000); Random rand2 = new Random((i + 1) * (j + 1) * 2000); Random rand3 = new Random((i + 1) * (j + 1) * 3000);
                        _c.Add(Color.FromArgb(rand1.Next(0, 256), rand2.Next(0, 256), rand3.Next(0, 256)));
                        var l1 = rotation(l2, new Vector3d(0, 0, 1), 90); l1 = l1 / l1.Length;
                        var p1 = r1 + l1 * b / 2.0; var p2 = r2 + l1 * b / 2.0; var p3 = r2 - l1 * b / 2.0; var p4 = r1 - l1 * b / 2.0;
                        var brep = Brep.CreatePlanarBreps(new Polyline(new List <Point3d> {
                            p1, p2, p3, p4, p1
                        }).ToNurbsCurve(), 0.001)[0];
                        _s.Add(brep);
                    }
                    var text = le.Attributes.GetUserString(nameD);
                    var D    = 10.0;//[mm]
                    if (text != null)
                    {
                        D = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(namepitch);
                    var pitch = 200.0;//[mm]
                    if (text != null)
                    {
                        pitch = float.Parse(text);
                    }
                    var ft = 195.0;//[mm2]
                    text = le.Attributes.GetUserString(nameft);
                    if (text != null)
                    {
                        ft = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(namew);
                    var w = 0.2;//[mm]
                    if (text != null)
                    {
                        w = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(nameac);
                    var ac = 30.0;//[kN/m2]
                    if (text != null)
                    {
                        ac = float.Parse(text);
                    }
                    Ac.Add(ac);
                    var at = Math.PI * Math.Pow(D, 2) / 4.0 * 1000.0 / pitch; //[mm2]
                    var dj = (t * 1000 - 60) * 7 / 8;                         //[mm]
                    J.Add(dj); At.Add(at);
                    var span = b / 2.0 - w; LL.Add(span);
                    M.Add(prs * Math.Pow(span, 2) / 2.0); //[kNm]
                    Ma.Add(at * ft * dj / 1e+6);          //[kNm]
                    bar.Add("D" + ((int)D).ToString() + "@" + ((int)pitch).ToString()); Ft.Add(ft);
                }
            }
            DA.SetDataList("base", baseshape);
            DA.SetDataList("N/A", pressure);
            DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij);
            var ij = _ij.Branches; GH_Structure <GH_Number> e_load = new GH_Structure <GH_Number>(); int kk = 0;

            if (_ij.Branches[0][0].Value != -9999)
            {
                for (int k = 0; k < pressure.Count; k++)
                {
                    var ri = baseline[k][0]; var rj = baseline[k][1];//布基礎の両端の座標
                    var xi = ri[0]; var yi = ri[1]; var zi = ri[2]; var xj = rj[0]; var yj = rj[1]; var zj = rj[2];
                    var xmin = Math.Min(xi, xj) - 0.1; var xmax = Math.Max(xi, xj) + 0.1; var ymin = Math.Min(yi, yj) - 0.1; var ymax = Math.Max(yi, yj) + 0.1; var zmin = Math.Min(zi, zj) - 0.1; var zmax = Math.Max(zi, zj) + 0.1;
                    var v1 = rj - ri;
                    for (int e = 0; e < ij.Count; e++)
                    {
                        int ni = (int)ij[e][0].Value; int nj = (int)ij[e][1].Value;
                        var x1 = r[ni][0].Value; var y1 = r[ni][1].Value; var z1 = r[ni][2].Value; var x2 = r[nj][0].Value; var y2 = r[nj][1].Value; var z2 = r[nj][2].Value;
                        var r1 = new Point3d(x1, y1, z1); var r2 = new Point3d(x2, y2, z2);
                        var v2 = r2 - r1;
                        if (Math.Abs(Math.Abs(Vector3d.VectorAngle(v1, v2))) < 1e-2 || Math.Abs(Math.Abs(Vector3d.VectorAngle(v1, v2))) + 1e-2 > Math.PI)
                        {
                            if (xmin < x1 && x1 < xmax && xmin < x2 && x2 < xmax && ymin < y1 && y1 < ymax && ymin < y2 && y2 < ymax && zmin < z1 && z1 < zmax && zmin < z2 && z2 < zmax)
                            {
                                List <GH_Number> flist = new List <GH_Number>();
                                flist.Add(new GH_Number(e)); flist.Add(new GH_Number(0)); flist.Add(new GH_Number(0)); flist.Add(new GH_Number(pressure[k]));
                                e_load.AppendRange(flist, new GH_Path(kk));
                                kk += 1;
                            }
                        }
                    }
                }
                DA.SetDataTree(2, e_load);
            }
            //pdf作成
            if (on_off == 1)
            {
                // フォントリゾルバーのグローバル登録
                if (PdfCreate.JapaneseFontResolver.fontset == 0)
                {
                    PdfSharp.Fonts.GlobalFontSettings.FontResolver = fontresolver; PdfCreate.JapaneseFontResolver.fontset = 1;
                }
                // PDFドキュメントを作成。
                PdfDocument document = new PdfDocument();
                document.Info.Title  = pdfname;
                document.Info.Author = "Shinnosuke Fujita, Assoc. Prof., The Univ. of Kitakyushu";
                // フォントを作成。
                XFont font     = new XFont("Gen Shin Gothic", 9, XFontStyle.Regular);
                XFont fontbold = new XFont("Gen Shin Gothic", 9, XFontStyle.Bold);
                var   pen      = XPens.Black;
                var   labels   = new List <string>
                {
                    "基礎番号", "幅B[m]", "厚みt[m]", "長さL[m]", "底面積A[m2]", "反力合計[kN]", "基礎自重[kN]", "接地圧N/A[kN/m2]", "許容地耐力[kN/m2]", "地耐力検定比", "基礎出幅[m]", "M[kNm]", "配筋", "断面積at[mm2]", "ft[N/mm2]", "応力中心間距離j[mm]", "Ma[kNm]", "曲げ検定比M/Ma"
                };
                var label_width = 105; var offset_x = 25; var offset_y = 25; var pitchy = 13; var text_width = 20; PdfPage page = new PdfPage(); page.Size = PageSize.A4;
                for (int e = 0; e < pressure.Count; e++)
                {
                    var e_text = e.ToString();
                    var B_text = B[e].ToString("F").Substring(0, Digit((int)(B[e])) + 3);
                    var t_text = T[e].ToString("F").Substring(0, Digit((int)(T[e])) + 3);
                    var L_text = L[e].ToString("F").Substring(0, Digit((int)(L[e])) + 3);
                    var A_text = A[e].ToString("F").Substring(0, Digit((int)(A[e])) + 3);
                    var Rz_text = Rz[e].ToString("F").Substring(0, Digit((int)(Rz[e])) + 3);
                    var Sz_text = Sz[e].ToString("F").Substring(0, Digit((int)(Sz[e])) + 3);
                    var P_text = pressure[e].ToString("F").Substring(0, Digit((int)(pressure[e])) + 3);
                    var ac_text = Ac[e].ToString("F").Substring(0, Digit((int)(Ac[e])) + 3);
                    var l_text = LL[e].ToString("F").Substring(0, Digit((int)(LL[e])) + 3);
                    var M_text = M[e].ToString("F").Substring(0, Digit((int)(M[e])) + 3);
                    var Ma_text = Ma[e].ToString("F").Substring(0, Digit((int)(Ma[e])) + 3);
                    var at_text = At[e].ToString("F").Substring(0, Digit((int)(At[e])) + 3);
                    var ft_text = Ft[e].ToString("F").Substring(0, Digit((int)(Ft[e])) + 3);
                    var j_text = J[e].ToString("F").Substring(0, Digit((int)(J[e])) + 3);
                    var bar_text = bar[e];
                    var kentei2 = pressure[e] / Ac[e];
                    var k2_text = kentei2.ToString("F").Substring(0, 4); var k2_color = new XSolidBrush(RGB((1 - Math.Min(kentei2, 1.0)) * 1.9 / 3.0, 1, 0.5));
                    var kentei = M[e] / Ma[e];
                    var k_text = kentei.ToString("F").Substring(0, 4); var k_color = new XSolidBrush(RGB((1 - Math.Min(kentei, 1.0)) * 1.9 / 3.0, 1, 0.5));
                    var values = new List <string>();
                    values.Add(e_text); values.Add(B_text); values.Add(t_text); values.Add(L_text); values.Add(A_text); values.Add(Rz_text); values.Add(Sz_text); values.Add(P_text); values.Add(ac_text); values.Add(k2_text); values.Add(l_text); values.Add(M_text); values.Add(bar_text); values.Add(at_text); values.Add(ft_text); values.Add(j_text); values.Add(Ma_text);
                    values.Add(k_text);

                    var slide = 0.0;
                    if (6 <= e % 18 && e % 18 < 12)
                    {
                        slide = pitchy * 20;
                    }
                    if (12 <= e % 18 && e % 18 < 18)
                    {
                        slide = pitchy * 40;
                    }

                    if (e % 6 == 0)
                    {
                        // 空白ページを作成。
                        if (e % 18 == 0)
                        {
                            page = document.AddPage(); gfx = XGraphics.FromPdfPage(page);
                        }
                        // 描画するためにXGraphicsオブジェクトを取得。
                        for (int i = 0; i < labels.Count; i++)                                                                                                     //ラベル列**************************************************************************
                        {
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * i + slide);                     //横線
                            gfx.DrawLine(pen, offset_x + label_width, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * (i + 1) + slide); //縦線
                            gfx.DrawString(labels[i], font, XBrushes.Black, new XRect(offset_x, offset_y + pitchy * i + slide, label_width, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                            if (i == labels.Count - 1)
                            {
                                i += 1;
                                gfx.DrawLine(pen, offset_x, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * i + slide);//横線
                            }
                        }//***********************************************************************************************************************
                    }
                    for (int i = 0; i < values.Count; i++)
                    {
                        var j = e % 6;
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i + slide); //横線
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * (i + 1) + slide); //縦線
                        if (i == values.Count - 1)
                        {
                            gfx.DrawString(values[i], font, k_color, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, text_width * 3, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                            i += 1;
                            gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i + slide);//横線
                        }
                        else
                        {
                            var color = XBrushes.Black;
                            if (i == 9)
                            {
                                color = k2_color;
                            }
                            gfx.DrawString(values[i], font, color, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, text_width * 3, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                        }
                    }
                }
                var dir = Path.GetDirectoryName(Rhino.RhinoDoc.ActiveDoc.Path);
                // ドキュメントを保存。
                var filename = dir + "/" + pdfname + ".pdf";
                document.Save(filename);
                // ビューアを起動。
                Process.Start(filename);
            }
        }
Ejemplo n.º 13
0
        private void чистыйToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            String from       = textBox1.Text;
            String fromAdress = textBox2.Text;
            String fromIndex  = textBox5.Text;
            String to         = textBox3.Text;
            String toAdress   = textBox4.Text;
            String toIndex    = textBox6.Text;
            //Создание страницы (Конверт С4)
            PdfDocument print = new PdfDocument();
            PdfPage     page  = print.AddPage();

            page.Height = XUnit.FromMillimeter(229);
            page.Width  = XUnit.FromMillimeter(324);
            XGraphics gfx = XGraphics.FromPdfPage(page);
            //Стили для документа
            XPdfFontOptions options    = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont           font       = new XFont("Times New Roman", 14, XFontStyle.Italic, options);
            XFont           font2      = new XFont("Times New Roman", 14, XFontStyle.Underline, options);
            XFont           fontIndex  = new XFont("Times New Roman", 8, XFontStyle.Italic, options);
            XFont           fontIndex2 = new XFont("Times New Roman", 10, XFontStyle.Bold, options);

            XPen line          = new XPen(XColors.Black, 1);
            XPen lineForIndex  = new XPen(XColors.Black, 5);
            XPen lineForIndex2 = new XPen(XColors.Black, 2);
            XPen DashLine      = new XPen(XColors.Black, 1);

            DashLine.DashStyle = XDashStyle.Dash;

            // Отрисовка индекса слева внизу
            // Толстый пунктир
            gfx.DrawLine(lineForIndex, 140, 560, 160, 560);
            gfx.DrawLine(lineForIndex, 115, 560, 135, 560);
            gfx.DrawLine(lineForIndex, 90, 560, 110, 560);
            gfx.DrawLine(lineForIndex, 65, 560, 85, 560);
            gfx.DrawLine(lineForIndex, 40, 560, 60, 560);
            gfx.DrawLine(lineForIndex, 15, 560, 35, 560);
            gfx.DrawLine(lineForIndex, 165, 560, 185, 560);
            // Черточка слева
            gfx.DrawLine(lineForIndex2, 15, 570, 35, 570);
            // Крышечки сверху
            gfx.DrawLine(DashLine, 40, 570, 60, 570);
            gfx.DrawLine(DashLine, 65, 570, 85, 570);
            gfx.DrawLine(DashLine, 90, 570, 110, 570);
            gfx.DrawLine(DashLine, 115, 570, 135, 570);
            gfx.DrawLine(DashLine, 140, 570, 160, 570);
            gfx.DrawLine(DashLine, 165, 570, 185, 570);
            // Диагональные линии
            gfx.DrawLine(DashLine, 40, 590, 60, 570);
            gfx.DrawLine(DashLine, 40, 610, 60, 590);

            gfx.DrawLine(DashLine, 65, 590, 85, 570);
            gfx.DrawLine(DashLine, 65, 610, 85, 590);

            gfx.DrawLine(DashLine, 90, 590, 110, 570);
            gfx.DrawLine(DashLine, 90, 610, 110, 590);

            gfx.DrawLine(DashLine, 115, 590, 135, 570);
            gfx.DrawLine(DashLine, 115, 610, 135, 590);

            gfx.DrawLine(DashLine, 140, 590, 160, 570);
            gfx.DrawLine(DashLine, 140, 610, 160, 590);

            gfx.DrawLine(DashLine, 165, 590, 185, 570);
            gfx.DrawLine(DashLine, 165, 610, 185, 590);
            // Нижние крышечки
            gfx.DrawLine(DashLine, 40, 610, 60, 610);
            gfx.DrawLine(DashLine, 65, 610, 85, 610);
            gfx.DrawLine(DashLine, 90, 610, 110, 610);
            gfx.DrawLine(DashLine, 115, 610, 135, 610);
            gfx.DrawLine(DashLine, 140, 610, 160, 610);
            gfx.DrawLine(DashLine, 165, 610, 185, 610);
            // Средние крышечки
            gfx.DrawLine(DashLine, 40, 590, 60, 590);
            gfx.DrawLine(DashLine, 65, 590, 85, 590);
            gfx.DrawLine(DashLine, 90, 590, 110, 590);
            gfx.DrawLine(DashLine, 115, 590, 135, 590);
            gfx.DrawLine(DashLine, 140, 590, 160, 590);
            gfx.DrawLine(DashLine, 165, 590, 185, 590);
            //Палки слева
            gfx.DrawLine(DashLine, 40, 570, 40, 610);
            gfx.DrawLine(DashLine, 65, 570, 65, 610);
            gfx.DrawLine(DashLine, 90, 570, 90, 610);
            gfx.DrawLine(DashLine, 115, 570, 115, 610);
            gfx.DrawLine(DashLine, 140, 570, 140, 610);
            gfx.DrawLine(DashLine, 165, 570, 165, 610);
            //Палки справа
            gfx.DrawLine(DashLine, 60, 570, 60, 610);
            gfx.DrawLine(DashLine, 85, 570, 85, 610);
            gfx.DrawLine(DashLine, 110, 570, 110, 610);
            gfx.DrawLine(DashLine, 135, 570, 135, 610);
            gfx.DrawLine(DashLine, 160, 570, 160, 610);
            gfx.DrawLine(DashLine, 185, 570, 185, 610);

            // Отрисовка правого верхнего угла
            gfx.DrawLine(line, 750, 80, 850, 80);
            gfx.DrawLine(line, 850, 80, 850, 180);

            // Отрисовка рамки индекса слева вверху
            gfx.DrawLine(line, 140, 165, 250, 165);
            gfx.DrawLine(line, 140, 145, 140, 165);
            gfx.DrawLine(line, 250, 145, 250, 165);

            // Отрисовка рамки индекса справа снизу
            gfx.DrawLine(line, 585, 560, 685, 560);
            gfx.DrawLine(line, 585, 540, 585, 560);
            gfx.DrawLine(line, 685, 540, 685, 560);

            gfx.DrawString("От кого", font, XBrushes.Black,
                           new XRect(60, 100, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(from, font2, XBrushes.Black,
                           new XRect(120, 100, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("От куда", font, XBrushes.Black,
                           new XRect(60, 120, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(fromAdress, font2, XBrushes.Black,
                           new XRect(120, 120, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("Индекс места отправления", fontIndex, XBrushes.Black,
                           new XRect(150, 140, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(fromIndex, fontIndex2, XBrushes.Black,
                           new XRect(180, 150, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("Кому", font, XBrushes.Black,
                           new XRect(550, 500, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(to, font2, XBrushes.Black,
                           new XRect(590, 500, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("Куда", font, XBrushes.Black,
                           new XRect(550, 520, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(toAdress, font2, XBrushes.Black,
                           new XRect(590, 520, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("Индекс места назначения", fontIndex, XBrushes.Black,
                           new XRect(590, 540, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(toIndex, fontIndex2, XBrushes.Black,
                           new XRect(620, 550, page.Width, page.Height),
                           XStringFormat.TopLeft);

            string filename = "Test23.pdf";

            print.Save(filename);
            Process.Start(filename);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the index of the sibling page of the current page.
        /// A sibling page is the page either before or after the current page.
        /// Usually it is the previous page (to help avoid spoilers).
        /// If both adjacent pages are of different orientations, there is no sibling page.
        /// If the current page is the first page, the sibling will be page 2 if it's the same orientation.
        /// If only one of the current page's siblings is of the same orientation, that page is the sibling.
        /// </summary>
        /// <param name="currentPage">The index of the page to get the sibling page index for.</param>
        /// <returns>The index of the sibling page, or null if there is no sibling.</returns>
        private PdfPage GetSiblingPage(PdfPage currentPage) {
            if(currentPage == null) {
                throw new ArgumentNullException("currentPage", "The currentPage parameter cannot be null.");
            }

            PdfPage previousPage = currentPage.Index > 0 ? pdf.GetPage(currentPage.Index - 1) : null;
            PdfPage nextPage = currentPage.Index < pdf.PageCount - 1 ? pdf.GetPage(currentPage.Index + 1) : null;

            if(previousPage == null && nextPage == null) {
                // One page document.
                return null;
            }

            PdfPageOrientation currentPageOrientation = GetPageOrientation(currentPage);

            if(previousPage == null) {
                return (currentPageOrientation == GetPageOrientation(nextPage)) || GetPageOrientation(nextPage) == PdfPageOrientation.Square ? nextPage : null;
            } else if((currentPageOrientation == GetPageOrientation(previousPage)) || GetPageOrientation(previousPage) == PdfPageOrientation.Square) {
                return previousPage;
            } else {
                return (currentPageOrientation == GetPageOrientation(nextPage)) || GetPageOrientation(nextPage) == PdfPageOrientation.Square ? nextPage : null;
            }
        }
Ejemplo n.º 15
0
		/// <summary>
		/// Draw loading icon
		/// </summary>
		/// <param name="drawingContext">Drawing surface</param>
		/// <param name="page">Page to be drawn</param>
		/// <param name="actualRect">Page bounds in control coordinates</param>
		/// <remarks>
		/// Full page rendering is performed in the following order:
		/// <list type="bullet">
		/// <item><see cref="DrawPageBackColor"/></item>
		/// <item><see cref="DrawPage"/> / <see cref="DrawLoadingIcon"/></item>
		/// <item><see cref="DrawFillForms"/></item>
		/// <item><see cref="DrawPageBorder"/></item>
		/// <item><see cref="DrawFillFormsSelection"/></item>
		/// <item><see cref="DrawTextHighlight"/></item>
		/// <item><see cref="DrawTextSelection"/></item>
		/// <item><see cref="DrawCurrentPageHighlight"/></item>
		/// <item><see cref="DrawPageSeparators"/></item>
		/// </list>
		/// </remarks>
		protected virtual void DrawLoadingIcon(DrawingContext drawingContext, PdfPage page, Rect actualRect)
		{
			Typeface tf = new Typeface("Tahoma");
			var ft = new FormattedText(
				LoadingIconText,
				CultureInfo.CurrentCulture, 
				FlowDirection.LeftToRight, 
				tf, 14, Brushes.Black);
			ft.MaxTextWidth = actualRect.Width;
			ft.MaxTextHeight = actualRect.Height;
			ft.TextAlignment = TextAlignment.Left;

			double x = (actualRect.Width - ft.Width) / 2 + actualRect.X;
			if (x < actualRect.X)
				x = actualRect.X;
			double y = (actualRect.Height - ft.Height) / 2 + actualRect.Y;
			if (y < actualRect.Y)
				y = actualRect.Y;
			drawingContext.DrawText(ft, new Point(x, y));
		}
Ejemplo n.º 16
0
        public static void SaveEva()
        {
            Tournament tnmt    = new Tournament();
            INIFile    tnmtIni = new INIFile(Tournament.iniPath);

            tnmt.Getter();
            Team[] evaTeams = new Team[tnmt.tnmtTeamCnt];
            for (int i = 0; i < evaTeams.Length; i++)
            {
                Team addTeam = new Team();
                addTeam.Getter(i + 1);
                evaTeams[i] = addTeam;
            }

            SortTeamsByWinAndGamePoints(evaTeams);

            PdfDocument pdf  = new PdfDocument();
            PdfPage     page = pdf.AddPage();

            XGraphics graph = XGraphics.FromPdfPage(page);

            XFont fontHeader           = new XFont("Verdana", 20, XFontStyle.Bold);
            XFont fontLine             = new XFont("Courier New", 12, XFontStyle.Regular);
            XFont fontLineInfo         = new XFont("Courier New", 12, XFontStyle.Bold);
            XFont fontNotFinishedState = new XFont("Courier New", 12, XFontStyle.Bold);

            //graph.DrawString("Ranglist " + tnmt.tnmtName, fontHeader, XBrushes.Black, new XRect(10, 10, page.Width.Point, page.Height.Point), XStringFormats.TopCenter);
            SetHeader(tnmt, fontHeader, page, graph);

            string line   = "";
            int    yPoint = 40;

            //if (CheckTnmtNotFinishState(tnmtIni))
            //{
            //    line = "ZUM ZEITPUNKT DER ERSTELLUNG DIESER DATEI WAR DAS TURNIER NOCH NICHT BEENDET!";
            //    graph.DrawString(line, notFinishedState, XBrushes.Black, new XRect(10, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //    yPoint += 20;
            //}

            SetTnmtNotFinishState(tnmtIni, line, fontNotFinishedState, page, graph, ref yPoint);

            //line = "Allgemine Daten:";
            //graph.DrawString(line, fontLineInfo, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 20;
            //line = "    Anzahl Durchgänge: " + Convert.ToString(tnmt.tnmtRunCnt);
            //graph.DrawString(line, fontLine, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 20;
            //line = "    Anzahl Spiel/Druchgang: " + Convert.ToString(tnmt.tnmtGameProRunCnt);
            //graph.DrawString(line, fontLine, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 20;
            //line = "    Anzahl Teams: " + Convert.ToString(tnmt.tnmtTeamCnt);
            //graph.DrawString(line, fontLine, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 50;

            SetDefaultData(tnmt, ref line, fontLineInfo, fontLine, page, graph, ref yPoint);

            int x = 0;

            line = "";

            //line = Const.posHeader + "|" + Const.teamNumberHeader + "|" + Const.teamNameHeader + "|" + Const.winPointsHeader + "|" + Const.gamePointsDiffHeader;
            //graph.DrawString(line, fontLineInfo, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 20;
            //line = "";

            int    pageNumber    = 1;
            double rowCntperPage = 22;
            double pageCnt       = tnmt.tnmtTeamCnt <= rowCntperPage ? 1 : (tnmt.tnmtTeamCnt / rowCntperPage);

            pageCnt = (int)pageCnt < (tnmt.tnmtTeamCnt / rowCntperPage) ? pageCnt + 1 : pageCnt;

            SetPageNumber(ref line, pageNumber, (int)pageCnt, fontLineInfo, page, graph, ref yPoint);

            SetTableHeader(ref line, fontLineInfo, page, graph, ref yPoint);

            //graph.DrawString(SetRow(), fontLineInfo, XBrushes.Black, new XRect(40, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
            //yPoint += 20;



            int rowCnt = 0;

            foreach (Team team in evaTeams)
            {
                if (rowCnt < rowCntperPage)
                {
                    x++;
                    SetTableRowData(ref line, team, x, fontLineInfo, fontLine, page, graph, ref yPoint);
                    rowCnt++;
                }
                else
                {
                    page        = pdf.AddPage();
                    graph       = XGraphics.FromPdfPage(page);
                    rowCnt      = 1;
                    yPoint      = 40;
                    pageNumber += 1;
                    SetTimeStamp(ref line, fontLineInfo, page, graph, ref yPoint);
                    yPoint += 110;
                    SetPageNumber(ref line, pageNumber, (int)pageCnt, fontLineInfo, page, graph, ref yPoint);
                    SetTableHeader(ref line, fontLineInfo, page, graph, ref yPoint);
                    x++;
                    SetTableRowData(ref line, team, x, fontLineInfo, fontLine, page, graph, ref yPoint);
                }
            }

            if (!Directory.Exists(tnmt.tnmtSpecPath))
            {
                Directory.CreateDirectory(tnmt.tnmtSpecPath);
                Log.Create("Directory: " + tnmt.tnmtSpecPath);
            }

            string pdfFileName = "";
            string pdfFilePath = "";

            try
            {
                pdfFileName = "Rangliste_" + tnmt.tnmtName + "_" + DateTime.Now.ToShortDateString() + ".pdf";
                pdfFilePath = System.IO.Path.Combine(tnmt.tnmtSpecPath, pdfFileName);
                pdf.Save(pdfFilePath);
                Log.Create("Evaluation-PDF: " + pdfFileName + " | saved at: " + pdfFilePath);
            }
            catch
            {
                Log.Error("creating Evaluation-PDF: " + pdfFileName + " tried to save at: " + pdfFilePath);
            }
        }
Ejemplo n.º 17
0
        public ActionResult Layers(string InsideBrowser)
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();

            doc.PageSettings = new PdfPageSettings(new SizeF(350, 300));

            PdfPage page = doc.Pages.Add();

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);

            page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, new PointF(150, 10));

            //Add the first layer
            PdfPageLayer layer = page.Layers.Add("Layer1");

            PdfGraphics graphics = layer.Graphics;

            graphics.TranslateTransform(100, 60);

            //Draw Arc
            PdfPen     pen  = new PdfPen(Color.Red, 50);
            RectangleF rect = new RectangleF(0, 0, 50, 50);

            graphics.DrawArc(pen, rect, 360, 360);

            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, 360, 360);

            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            //Add another layer on the page
            layer = page.Layers.Add("Layer2");

            graphics = layer.Graphics;
            graphics.TranslateTransform(100, 180);
            //graphics.SkewTransform(0, 50);

            //Draw another set of elements
            pen = new PdfPen(Color.Red, 50);
            graphics.DrawArc(pen, rect, 360, 360);
            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, 360, 360);
            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            //Add another layer
            layer    = page.Layers.Add("Layer3");
            graphics = layer.Graphics;
            graphics.TranslateTransform(160, 120);

            //Draw another set of elements.
            pen = new PdfPen(Color.Red, 50);
            graphics.DrawArc(pen, rect, -60, 60);
            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, -60, 60);
            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, -60, 60);
            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, -60, 60);

            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            doc.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "Layers.pdf";
            return(fileStreamResult);
        }
Ejemplo n.º 18
0
 private static void SetTableRowGrid(XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     i_graph.DrawString(SetRow(), i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftTabelRow;
 }
Ejemplo n.º 19
0
 private static void SetTableRowData(ref string i_line, Team i_team, int i_TeamNumber, XFont i_fontHeader, XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     i_graph.DrawString(FillPdfTable(i_team, Convert.ToString(i_TeamNumber)), i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftTabelRow;
     i_line    = "";
     SetTableRowGrid(i_fontHeader, i_page, i_graph, ref i_yPoint);
 }
Ejemplo n.º 20
0
 private static void SetPageNumber(ref string i_line, int pageNumber, int pageCnt, XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     i_line = "Seite: " + Convert.ToString(pageNumber) + "/" + Convert.ToString(pageCnt);
     i_graph.DrawString(i_line, i_font, XBrushes.Black, new XRect(40, 780, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     //i_yPoint += 20;
     i_line = "";
 }
Ejemplo n.º 21
0
 private static void SetDefaultData(Tournament i_tnmt, ref string i_line, XFont i_fontHeader, XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     SetTimeStamp(ref i_line, i_fontHeader, i_page, i_graph, ref i_yPoint);
     i_line = "Allgemine Daten:";
     i_graph.DrawString(i_line, i_fontHeader, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftNormalRow;
     i_line    = "    Anzahl Durchgänge: " + Convert.ToString(i_tnmt.tnmtRunCnt);
     i_graph.DrawString(i_line, i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftNormalRow;
     i_line    = "    Anzahl Spiel/Durchgang: " + Convert.ToString(i_tnmt.tnmtGameProRunCnt);
     i_graph.DrawString(i_line, i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftNormalRow;
     i_line    = "    Anzahl Teams: " + Convert.ToString(i_tnmt.tnmtTeamCnt);
     i_graph.DrawString(i_line, i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += 50;
 }
Ejemplo n.º 22
0
 private static void SetTimeStamp(ref string i_line, XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     i_line = "Erstellt: " + DateTime.Now.ToLongDateString() + " | " + DateTime.Now.ToShortTimeString();
     i_graph.DrawString(i_line, i_font, XBrushes.Black, new XRect(40, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
     i_yPoint += yShiftNormalRow;
 }
Ejemplo n.º 23
0
 private static void SetTnmtNotFinishState(INIFile i_tnmtIni, string i_line, XFont i_font, PdfPage i_page, XGraphics i_graph, ref int i_yPoint)
 {
     if (CheckTnmtNotFinishState(i_tnmtIni))
     {
         i_line = "ZUM ZEITPUNKT DER ERSTELLUNG DIESER DATEI WAR DAS TURNIER NOCH NICHT BEENDET!";
         i_graph.DrawString(i_line, i_font, XBrushes.Red, new XRect(10, i_yPoint, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopLeft);
         i_yPoint += yShiftNormalRow;
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream JobApplicationPDF()
        {
            //Create a new PDF document
            PdfDocument pdfDoc = new PdfDocument();

            pdfDoc.ViewerPreferences.HideMenubar  = true;
            pdfDoc.ViewerPreferences.HideWindowUI = true;
            pdfDoc.ViewerPreferences.HideToolbar  = true;
            pdfDoc.ViewerPreferences.FitWindow    = true;

            pdfDoc.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage;
            pdfDoc.PageSettings.Orientation     = PdfPageOrientation.Portrait;
            pdfDoc.PageSettings.Margins.All     = 0;

            //To set coordinates to draw form fields
            RectangleF       bounds = new RectangleF(180, 65, 156, 15);
            PdfUnitConverter con    = new PdfUnitConverter();

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(ResolveApplicationPath("Careers.png"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            PdfImage img = new PdfBitmap(file);

            //Set the page size
            SizeF pageSize = new SizeF(500, 310);

            pdfDoc.PageSettings.Height = pageSize.Height;
            pdfDoc.PageSettings.Width  = pageSize.Width;

            PdfFont pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);

            #region First Page
            pdfDoc.Pages.Add();

            PdfPage firstPage = pdfDoc.Pages[0];
            pdfDoc.Pages[0].Graphics.DrawImage(img, 0, 0, pageSize.Width, pageSize.Height);
            pdfDoc.Pages[0].Graphics.DrawString("General Information", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 25, 40);
            pdfDoc.Pages[0].Graphics.DrawString("Education Grade", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 25, 190);

            pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            //Create fields in first page.
            pdfDoc.Pages[0].Graphics.DrawString("First Name:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 65);

            //Create text box for firstname.
            PdfTextBoxField textBoxField1 = new PdfTextBoxField(pdfDoc.Pages[0], "FirstName");
            textBoxField1.ToolTip = "First Name";
            PdfStandardFont font1 = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            textBoxField1.Font        = font1;
            textBoxField1.BorderColor = new PdfColor(Color.Gray);
            textBoxField1.BorderStyle = PdfBorderStyle.Beveled;
            textBoxField1.Bounds      = bounds;
            pdfDoc.Form.Fields.Add(textBoxField1);

            pdfDoc.Pages[0].Graphics.DrawString("Last Name:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 83);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;
            //Create text box for lastname.
            PdfTextBoxField textBoxField2 = new PdfTextBoxField(pdfDoc.Pages[0], "LastName");
            textBoxField2.ToolTip     = "Last Name";
            textBoxField2.Font        = font1;
            textBoxField2.BorderColor = new PdfColor(Color.Gray);
            textBoxField2.BorderStyle = PdfBorderStyle.Beveled;
            textBoxField2.Bounds      = bounds;
            pdfDoc.Form.Fields.Add(textBoxField2);

            pdfDoc.Pages[0].Graphics.DrawString("Email:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 103);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;

            //Create text box for Email.
            PdfTextBoxField textBoxField3 = new PdfTextBoxField(pdfDoc.Pages[0], "Email");
            textBoxField3.ToolTip     = "Email id";
            textBoxField3.Font        = font1;
            textBoxField3.BorderColor = new PdfColor(Color.Gray);
            textBoxField3.BorderStyle = PdfBorderStyle.Beveled;
            textBoxField3.Bounds      = bounds;
            pdfDoc.Form.Fields.Add(textBoxField3);

            pdfDoc.Pages[0].Graphics.DrawString("Business Phone:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 123);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;

            //Create text box for Business phone.
            PdfTextBoxField textBoxField4 = new PdfTextBoxField(pdfDoc.Pages[0], "Business");
            textBoxField4.ToolTip     = "Business phone";
            textBoxField4.Font        = font1;
            textBoxField4.BorderColor = new PdfColor(Color.Gray);
            textBoxField4.BorderStyle = PdfBorderStyle.Beveled;
            textBoxField4.Bounds      = bounds;
            pdfDoc.Form.Fields.Add(textBoxField4);

            pdfDoc.Pages[0].Graphics.DrawString("Which position are\nyou applying for?", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 143);

            //Create combo box for Position.
            #region Create ComboBox
            //Set position to draw Combo Box
            bounds.Y = bounds.Y + 24;

            PdfComboBoxField comboBox = new PdfComboBoxField(pdfDoc.Pages[0], "JobTitle");
            comboBox.Bounds      = bounds;
            comboBox.BorderWidth = 1;
            comboBox.BorderColor = new PdfColor(Color.Gray);
            comboBox.Font        = pdfFont;
            comboBox.ToolTip     = "Job Title";


            comboBox.Items.Add(new PdfListFieldItem("Development", "accounts"));
            comboBox.Items.Add(new PdfListFieldItem("Support", "advertise"));
            comboBox.Items.Add(new PdfListFieldItem("Documentation", "agri"));

            pdfDoc.Form.Fields.Add(comboBox);
            #endregion

            pdfDoc.Pages[0].Graphics.DrawString("Highest qualification", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 217);

            //Create Checkbox box.
            #region Create CheckBox
            pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            //Set position to draw Checkbox
            bounds.Y     = 239;
            bounds.X     = 25;
            bounds.Width = 10;

            bounds.Height = 10;

            // Create a Check Box
            PdfCheckBoxField chb = new PdfCheckBoxField(pdfDoc.Pages[0], "Adegree");

            chb.Font        = pdfFont;
            chb.ToolTip     = "degree";
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Associate degree", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);
            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb             = new PdfCheckBoxField(pdfDoc.Pages[0], "Bdegree");
            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Bachelor degree", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "college");

            chb.Font        = pdfFont;
            chb.ToolTip     = "college";
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(Color.Gray);

            bounds.X += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("College", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.Y += 20;
            bounds.X  = 25;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "pg");

            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Post Graduate", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "mba");

            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(Color.Gray);

            bounds.X += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("MBA", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            pdfDoc.Form.Fields.Add(chb);
            #endregion

            # region Create Button
Ejemplo n.º 25
0
 public override void Process(iPDF owner, ref PdfDocument Document, ref PdfPage Page, ref XGraphics Graphics)
 {
     Graphics.DrawLine(XPens.Black, new XPoint(X1, Y1), new XPoint(X2, Y2));
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        public void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue)
        {
            PdfDocument document = new PdfDocument();

            document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            document.PageSettings.Margins.All = 50;
            PdfPage        page    = document.Pages.Add();
            PdfGraphics    g       = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");

            element.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfLayoutResult result    = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Assembly        assembly  = typeof(MainPage).Assembly;
            Stream          imgStream = assembly.GetManifestResourceStream("Invoice.Assets.SyncfusionLogo.jpg");
            PdfImage        img       = PdfImage.FromStream(imgStream);

            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);

            g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));
            element       = new PdfTextElement("INVOICE " + billInfo.InvoiceNumber.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE " + billInfo.Date.ToString("d");
            SizeF  textSize    = subHeadingFont.MeasureString(currentDate);

            g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));

            element       = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 12));
            element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            element       = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 11));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));

            element       = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 11));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();

            grid.DataSource = ConvertToDataTable(dataSource);
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();

            headerStyle.Borders.All     = new PdfPen(new PdfColor(34, 83, 142));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            headerStyle.TextBrush       = PdfBrushes.White;
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }
            header.Cells[0].Value = "ITEM";
            header.Cells[1].Value = "QUANTITY";
            header.Cells[2].Value = "RATE";
            header.Cells[3].Value = "TAXES";
            header.Cells[4].Value = "AMOUNT";
            header.ApplyStyle(headerStyle);
            grid.Columns[0].Width    = 180;
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f);
            cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f);
            cellStyle.TextBrush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                    }

                    if (i > 1)
                    {
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            if (cell.Value is double)
                            {
                                cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                cell.Value = "$" + cell.Value.ToString();
                            }
                        }
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;

            for (int i = 0; i < grid.Columns.Count - 1; i++)
            {
                pos += grid.Columns[i].Width;
            }

            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold);

            gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right));

            document.Save("Invoice.pdf");
            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if !NETCORE
                System.Diagnostics.Process.Start("Invoice.pdf");
#else
                ProcessStartInfo psi = new ProcessStartInfo
                {
                    FileName        = "cmd",
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                    Arguments       = "/c start Invoice.pdf"
                };
                Process.Start(psi);
#endif
                //this.Close();
            }
            //else
            // Exit
            //this.Close();

            document.Close(true);
        }
Ejemplo n.º 27
0
		/// <summary>
		/// Draws page content and fillforms
		/// </summary>
		/// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param>
		/// <param name="page">Page to be drawn</param>
		/// <param name="actualRect">Page bounds in control coordinates</param>
		/// <remarks>
		/// Full page rendering is performed in the following order:
		/// <list type="bullet">
		/// <item><see cref="DrawPageBackColor"/></item>
		/// <item><see cref="DrawPage"/> / <see cref="DrawLoadingIcon"/></item>
		/// <item><see cref="DrawFillForms"/></item>
		/// <item><see cref="DrawPageBorder"/></item>
		/// <item><see cref="DrawFillFormsSelection"/></item>
		/// <item><see cref="DrawTextHighlight"/></item>
		/// <item><see cref="DrawTextSelection"/></item>
		/// <item><see cref="DrawCurrentPageHighlight"/></item>
		/// <item><see cref="DrawPageSeparators"/></item>
		/// </list>
		/// </remarks>
		/// <returns>true if page was rendered; false if any error is occurred or page is still rendering.</returns>
		protected virtual bool DrawPage(DrawingContext drawingContext, PdfPage page, Rect actualRect)
		{
			if (actualRect.Width <= 0 || actualRect.Height <= 0)
				return true;
			int width = Helpers.PointsToPixels(actualRect.Width);
			int height = Helpers.PointsToPixels(actualRect.Height);
			if (width <= 0 || height <= 0)
				return true;

			var pageRect = new Int32Rect(
				Helpers.PointsToPixels(actualRect.X), 
				Helpers.PointsToPixels(actualRect.Y), width, height);
			return _prPages.RenderPage(page, pageRect, PageRotation(page), RenderFlags, UseProgressiveRender);
		}
        private void btnSubmitTrans_Click(object sender, RoutedEventArgs e)
        {
            if (TxtPay.Text == "0" || TxtPay.Text == "")
            {
                MessageBox.Show("Fill column pay please", "Alert", MessageBoxButton.OK);
                TxtPay.Focus();
            }
            else
            {
                int change = Convert.ToInt32(TxtPay.Text) - Convert.ToInt32(TxtTotal.Text);
                try
                {
                    int transid = Convert.ToInt32(TxtTransId.Text);
                    var item    = myContext.TransactionItems.FirstOrDefault(i => i.TransactionFK.Id == transid);
                    var trans   = myContext.Transactions.FirstOrDefault(data => data.Id == transid);
                    trans.Total = Convert.ToInt32(TxtTotal.Text);
                    trans.Pay   = Convert.ToInt32(TxtPay.Text);
                    myContext.SaveChanges();
                    TxtChange.Text = "Rp. " + change.ToString("n0") + ",-";
                    foreach (var transItem in TransDetail)
                    {
                        myContext.TransactionItems.Add(transItem);
                        myContext.SaveChanges();
                    }

                    MessageBox.Show("Your change is Rp. " + change.ToString("n0") + ",-", "Message", MessageBoxButton.OK);
                    receipt += item.ItemFK.Name + "\t" + item.Quantity + "\t" + item.SubTotal + "\nTotal: Rp. "
                               + item.TransactionFK.Total.ToString("n0") + ",-\nPay: Rp. "
                               + item.TransactionFK.Pay.ToString("n0") + ",-\nChange: Rp. "
                               + (item.TransactionFK.Pay - item.TransactionFK.Total).ToString("n0") + ",-";
                    using (PdfDocument document = new PdfDocument())
                    {
                        //Add a page to the document
                        PdfPage page = document.Pages.Add();

                        //Create PDF graphics for a page
                        PdfGraphics graphics = page.Graphics;

                        //Set the standard font
                        PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

                        //Draw the text
                        graphics.DrawString(receipt, font, PdfBrushes.Black, new PointF(0, 0));

                        //Save the document
                        document.Save("Receipt.pdf");
                    }
                }
                catch (Exception)
                {
                }
                //comboBoxItem.Text = "--Choose Item--";
                TxtTransId.Text = "";
                GridTransItem.Items.Clear();
                grandTotal               = 0;
                TxtTotal.Text            = "0";
                TxtChange.Text           = "0";
                TxtPay.IsEnabled         = false;
                btnAddTrans.IsEnabled    = true;
                comboBoxItem.IsEnabled   = false;
                TxtQuantity.IsEnabled    = false;
                btnAddToCart.IsEnabled   = false;
                btnDeleteTrans.IsEnabled = false;
                btnCancel.IsEnabled      = false;
                btnSubmitTrans.IsEnabled = false;
                Load();
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Adds the specified outline entry.
 /// </summary>
 /// <param name="title">The outline text.</param>
 /// <param name="destinationPage">The destination page.</param>
 public PdfOutline Add(string title, PdfPage destinationPage)
 {
   PdfOutline outline = new PdfOutline(title, destinationPage);
   Add(outline);
   return outline;
 }
Ejemplo n.º 30
0
//	Teckpack Print
//http://localhost/ReportPublishCrystal/ReportPdfPrint.aspx?ReportName=2^4489&uid=66e7fed1-1dfc-4003-89ad-f0831a0b4138&MainReferenceID=4489&ReportDataSourceType=PLMDatabase



        private void PrintUserReaTimeReport(int?aUId, string mutipleReportFiles, string PdmRequestRegisterID, string dataSourceType, string mainreferenceID, string masterReferenceId, string reportBatchNumber)
        {
            //allReportFileNmae=ReportName=Crystal_OSC_GetTab1.rpt^21836|OSC_Proto Summary.rdlx^21863
            if (mutipleReportFiles != string.Empty)
            {
                // only create once !!

                List <Stream> pdfFileStream = new List <Stream>();


                // it is batch print
                if (!string.IsNullOrWhiteSpace(reportBatchNumber))
                {
                    List <string> requestRegistIds = DDSetup.GetPdmRequestRegisterIdsByBatchNimber(reportBatchNumber);

                    foreach (string requestRegisterID in requestRegistIds)
                    {
                        // only for single report !!
                        string singleReportId = mutipleReportFiles;

                        List <Stream> pdfFileStreamFromSearchView = PrintSearchViewPdf(aUId, singleReportId, requestRegisterID, dataSourceType, mainreferenceID, masterReferenceId);

                        pdfFileStream.AddRange(pdfFileStreamFromSearchView);
                    }
                }
                else                 // it is NOT BATCH print, need to process singe request
                {
                    if (string.IsNullOrWhiteSpace(PdmRequestRegisterID))
                    {
                        List <Stream> pdfFileStreamTeckpacks = PrintTechPackPdf(aUId, mutipleReportFiles, string.Empty, dataSourceType, mainreferenceID, masterReferenceId);

                        pdfFileStream.AddRange(pdfFileStreamTeckpacks);
                    }
                    else                     // it is searchView print Calls  for each single request PdmRequestRegisterID
                    {
                        string singleReportId = mutipleReportFiles;

                        List <Stream> pdfFileStreamFromSearchView = PrintSearchViewPdf(aUId, singleReportId, PdmRequestRegisterID, dataSourceType, mainreferenceID, masterReferenceId);

                        pdfFileStream.AddRange(pdfFileStreamFromSearchView);
                    }
                }



                using (PdfDocument outputPdfDocument = new PdfDocument())
                {
                    try
                    {
                        foreach (Stream stream in pdfFileStream)
                        {
                            // Open the document to import pages from it.
                            if (stream.Length > 0)
                            {
                                using (PdfDocument inputDocument = PdfReader.Open(stream, PdfDocumentOpenMode.Import))
                                {
                                    // Iterate pages
                                    int count = inputDocument.PageCount;
                                    for (int idx = 0; idx < count; idx++)
                                    {
                                        // Get the page from the external document...
                                        PdfPage page = inputDocument.Pages[idx];
                                        // ...and add it to the output document.
                                        outputPdfDocument.AddPage(page);
                                    }
                                    stream.Close();
                                    stream.Dispose();
                                }
                            }
                        }

                        ApplicationLog.WriteError("IsReportCompressionActivate:" + DDSetup.ReorptSetup.IsReportCompressionActivate);

                        if (DDSetup.ReorptSetup.IsReportCompressionActivate)
                        {
                            string fileID         = Guid.NewGuid().ToString();
                            string FileNameOrigin = DDSetup.ReorptSetup.ReportPdfCompressPath + "Origin_" + fileID + ".pdf";
                            outputPdfDocument.Save(FileNameOrigin);

                            string FileNameDestination = DDSetup.ReorptSetup.ReportPdfCompressPath + "Dest_" + fileID + ".pdf";
                            ReportJobManagement.PdfCompression(FileNameOrigin, FileNameDestination);
                            File.Delete(FileNameOrigin);
                            OutputPdfFile(FileNameDestination);
                        }
                        else                         // need to compress PDF
                        {
                            MemoryStream memoStream = new MemoryStream();

                            outputPdfDocument.Save(memoStream, false);
                            OutPutResponse(memoStream);
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write("Print pdf Failed" + ex.ToString());
                    }
                }

                // need to dispsoe output to release memeory
                //  outputPdfDocument.Dispose();
                // need to dispost
            }
        }
Ejemplo n.º 31
0
 public void Transform(PdfPage page)
 {
     transform.Invoke(page);
 }
 public static iText.Kernel.Pdf.Navigation.PdfExplicitDestination CreateFitR(PdfPage page, float left, float
                                                                             bottom, float right, float top)
 {
     return(Create(page, PdfName.FitR, left, bottom, right, top, float.NaN));
 }
Ejemplo n.º 33
0
        private static void DrawArcsAndPies(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Arcs", titleFont, brush, 20, 50);
            page.Graphics.DrawString("Pies", titleFont, brush, 310, 50);

            page.Graphics.DrawLine(blackPen, 20, 210, 300, 210);
            page.Graphics.DrawLine(blackPen, 160, 70, 160, 350);
            page.Graphics.DrawLine(blackPen, 310, 210, 590, 210);
            page.Graphics.DrawLine(blackPen, 450, 70, 450, 350);

            blackPen.DashPattern = new double[] { 2, 2 };
            page.Graphics.DrawLine(blackPen, 20, 70, 300, 350);
            page.Graphics.DrawLine(blackPen, 20, 350, 300, 70);
            page.Graphics.DrawLine(blackPen, 310, 70, 590, 350);
            page.Graphics.DrawLine(blackPen, 310, 350, 590, 70);

            page.Graphics.DrawArc(redPen, 30, 80, 260, 260, 0, 135);
            page.Graphics.DrawPie(redPen, 320, 80, 260, 260, 45, 270);

            page.Graphics.DrawString("Random arcs and pies clipped to view", sectionFont, brush, 20, 385);
            PdfPath rectPath = new PdfPath();
            rectPath.AddRectangle(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(rectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int mode = rnd.Next(4);
                double left = rnd.NextDouble() * page.Width;
                double top = 380 + rnd.NextDouble() * 350;
                double width = rnd.NextDouble() * page.Width;
                double height = rnd.NextDouble() * 250;
                double startAngle = rnd.Next(360);
                double sweepAngle = rnd.Next(360);
                switch (mode)
                {
                    case 0:
                        // Stroke arc outline
                        page.Graphics.DrawArc(randomPen, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 1:
                        // Stroke pie outline
                        page.Graphics.DrawPie(randomPen, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 2:
                        // Fill pie interior
                        page.Graphics.DrawPie(randomBrush, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 3:
                        // Stroke and fill pie
                        page.Graphics.DrawPie(randomPen, randomBrush, left, top, width, height, startAngle, sweepAngle);
                        break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            blackPen.DashPattern = null;
            page.Graphics.DrawPath(blackPen, rectPath);

            page.Graphics.CompressAndClose();
        }
 public static iText.Kernel.Pdf.Navigation.PdfExplicitDestination Create(PdfPage page, PdfName type, float
                                                                         left, float bottom, float right, float top, float zoom)
 {
     return(new iText.Kernel.Pdf.Navigation.PdfExplicitDestination().Add(page).Add(type).Add(left).Add(bottom).
            Add(right).Add(top).Add(zoom));
 }
Ejemplo n.º 35
0
        private static void DrawColorsAndColorSpaces(PdfPage page, PdfFont titleFont, PdfFont sectionFont, Stream iccStream)
        {
            PdfBrush brush = new PdfBrush();

            page.Graphics.DrawString("Colors and colorspaces", titleFont, brush, 20, 50);

            page.Graphics.DrawString("DeviceRGB", sectionFont, brush, 20, 70);
            PdfPen rgbPen = new PdfPen(PdfRgbColor.DarkRed, 4);
            PdfBrush rgbBrush = new PdfBrush(PdfRgbColor.LightGoldenrodYellow);
            page.Graphics.DrawRectangle(rgbPen, rgbBrush, 20, 85, 250, 100);

            page.Graphics.DrawString("DeviceCMYK", sectionFont, brush, 340, 70);
            PdfPen cmykPen = new PdfPen(new PdfCmykColor(1, 0.5, 0, 0.1), 4);
            PdfBrush cmykBrush = new PdfBrush(new PdfCmykColor(0, 0.5, 0.43, 0));
            page.Graphics.DrawRectangle(cmykPen, cmykBrush, 340, 85, 250, 100);

            page.Graphics.DrawString("DeviceGray", sectionFont, brush, 20, 200);
            PdfPen grayPen = new PdfPen(new PdfGrayColor(0.1), 4);
            PdfBrush grayBrush = new PdfBrush(new PdfGrayColor(0.75));
            page.Graphics.DrawRectangle(grayPen, grayBrush, 20, 215, 250, 100);

            page.Graphics.DrawString("Indexed", sectionFont, brush, 340, 200);
            PdfIndexedColorSpace indexedColorSpace = new PdfIndexedColorSpace();
            indexedColorSpace.ColorCount = 2;
            indexedColorSpace.BaseColorSpace = new PdfRgbColorSpace();
            indexedColorSpace.ColorTable = new byte[] { 192, 0, 0, 0, 0, 128 };
            PdfIndexedColor indexedColor0 = new PdfIndexedColor(indexedColorSpace);
            indexedColor0.ColorIndex = 0;
            PdfIndexedColor indexedColor1 = new PdfIndexedColor(indexedColorSpace);
            indexedColor1.ColorIndex = 1;
            PdfPen indexedPen = new PdfPen(indexedColor0, 4);
            PdfBrush indexedBrush = new PdfBrush(indexedColor1);
            page.Graphics.DrawRectangle(indexedPen, indexedBrush, 340, 215, 250, 100);

            page.Graphics.DrawString("CalGray", sectionFont, brush, 20, 330);
            PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace();
            PdfCalGrayColor calGrayColor1 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor1.Gray = 0.6;
            PdfCalGrayColor calGrayColor2 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor2.Gray = 0.2;
            PdfPen calGrayPen = new PdfPen(calGrayColor1, 4);
            PdfBrush calGrayBrush = new PdfBrush(calGrayColor2);
            page.Graphics.DrawRectangle(calGrayPen, calGrayBrush, 20, 345, 250, 100);

            page.Graphics.DrawString("CalRGB", sectionFont, brush, 340, 330);
            PdfCalRgbColorSpace calRgbColorSpace = new PdfCalRgbColorSpace();
            PdfCalRgbColor calRgbColor1 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor1.Red = 0.1;
            calRgbColor1.Green = 0.5;
            calRgbColor1.Blue = 0.25;
            PdfCalRgbColor calRgbColor2 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor2.Red = 0.6;
            calRgbColor2.Green = 0.1;
            calRgbColor2.Blue = 0.9;
            PdfPen calRgbPen = new PdfPen(calRgbColor1, 4);
            PdfBrush calRgbBrush = new PdfBrush(calRgbColor2);
            page.Graphics.DrawRectangle(calRgbPen, calRgbBrush, 340, 345, 250, 100);

            page.Graphics.DrawString("L*a*b", sectionFont, brush, 20, 460);
            PdfLabColorSpace labColorSpace = new PdfLabColorSpace();
            PdfLabColor labColor1 = new PdfLabColor(labColorSpace);
            labColor1.L = 90;
            labColor1.A = -40;
            labColor1.B = 120;
            PdfLabColor labColor2 = new PdfLabColor(labColorSpace);
            labColor2.L = 45;
            labColor2.A = 90;
            labColor2.B = -34;
            PdfPen labPen = new PdfPen(labColor1, 4);
            PdfBrush labBrush = new PdfBrush(labColor2);
            page.Graphics.DrawRectangle(labPen, labBrush, 20, 475, 250, 100);

            page.Graphics.DrawString("Icc", sectionFont, brush, 340, 460);
            PdfIccColorSpace iccColorSpace = new PdfIccColorSpace();
            byte[] iccData = new byte[iccStream.Length];
            iccStream.Read(iccData, 0, iccData.Length);
            iccColorSpace.IccProfile = iccData;
            iccColorSpace.AlternateColorSpace = new PdfRgbColorSpace();
            iccColorSpace.ColorComponents = 3;
            PdfIccColor iccColor1 = new PdfIccColor(iccColorSpace);
            iccColor1.ColorComponents = new double[] { 0.45, 0.1, 0.22 };
            PdfIccColor iccColor2 = new PdfIccColor(iccColorSpace);
            iccColor2.ColorComponents = new double[] { 0.21, 0.76, 0.31 };
            PdfPen iccPen = new PdfPen(iccColor1, 4);
            PdfBrush iccBrush = new PdfBrush(iccColor2);
            page.Graphics.DrawRectangle(iccPen, iccBrush, 340, 475, 250, 100);

            page.Graphics.DrawString("Separation", sectionFont, brush, 20, 590);
            PdfExponentialFunction tintTransform = new PdfExponentialFunction();
            tintTransform.Domain = new double[] { 0, 1 };
            tintTransform.Range = new double[] { 0, 1, 0, 1, 0, 1, 0, 1 };
            tintTransform.Exponent = 1;
            tintTransform.C0 = new double[] { 0, 0, 0, 0 };
            tintTransform.C1 = new double[] { 1, 0.5, 0, 0.1 };

            PdfSeparationColorSpace separationColorSpace = new PdfSeparationColorSpace();
            separationColorSpace.AlternateColorSpace = new PdfCmykColorSpace();
            separationColorSpace.Colorant = "Custom Blue";
            separationColorSpace.TintTransform = tintTransform;

            PdfSeparationColor separationColor1 = new PdfSeparationColor(separationColorSpace);
            separationColor1.Tint = 0.23;
            PdfSeparationColor separationColor2 = new PdfSeparationColor(separationColorSpace);
            separationColor2.Tint = 0.74;

            PdfPen separationPen = new PdfPen(separationColor1, 4);
            PdfBrush separationBrush = new PdfBrush(separationColor2);
            page.Graphics.DrawRectangle(separationPen, separationBrush, 20, 605, 250, 100);

            page.Graphics.DrawString("Pantone", sectionFont, brush, 340, 590);
            PdfPen pantonePen = new PdfPen(PdfPantoneColor.ReflexBlue, 4);
            PdfBrush pantoneBrush = new PdfBrush(PdfPantoneColor.RhodamineRed);
            page.Graphics.DrawRectangle(pantonePen, pantoneBrush, 340, 605, 250, 100);

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 36
0
        private static void DrawRoundRectangles(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

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

            page.Graphics.DrawLine(blackPen, 20, 150, 300, 150);
            page.Graphics.DrawLine(blackPen, 80, 70, 80, 350);
            page.Graphics.DrawRoundRectangle(redPen, 80, 150, 180, 100, 20, 20);

            page.Graphics.DrawLine(blackPen, 320, 150, 600, 150);
            page.Graphics.DrawLine(blackPen, 380, 70, 380, 350);
            page.Graphics.DrawRoundRectangle(redPen, 380, 150, 180, 100, 20, 20, 30);

            page.Graphics.DrawString("Random round rectangles clipped to view", sectionFont, brush, 20, 385);
            PdfPath roundRectPath = new PdfPath();
            roundRectPath.AddRoundRectangle(20, 400, 570, 300, 20, 20);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(roundRectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int mode = rnd.Next(3);
                double left = rnd.NextDouble() * page.Width;
                double top = 380 + rnd.NextDouble() * 350;
                double width = rnd.NextDouble() * page.Width;
                double height = rnd.NextDouble() * 250;
                double orientation = rnd.Next(360);
                switch (mode)
                {
                    case 0:
                        // Stroke rectangle outline
                        page.Graphics.DrawRoundRectangle(randomPen, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                    case 1:
                        // Fill rectangle interior
                        page.Graphics.DrawRoundRectangle(randomBrush, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                    case 2:
                        // Stroke and fill rectangle
                        page.Graphics.DrawRoundRectangle(randomPen, randomBrush, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, roundRectPath);

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 37
0
        private static void DrawLines(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen bluePen = new PdfPen(PdfRgbColor.LightBlue, 16);

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

            page.Graphics.DrawString("Line styles:", sectionFont, brush, 20, 70);
            page.Graphics.DrawString("Solid", sectionFont, brush, 20, 90);
            page.Graphics.DrawLine(blackPen, 100, 95, 400, 95);
            page.Graphics.DrawString("Dashed", sectionFont, brush, 20, 110);
            blackPen.DashPattern = new double[] { 3, 3 };
            page.Graphics.DrawLine(blackPen, 100, 115, 400, 115);

            page.Graphics.DrawString("Line cap styles:", sectionFont, brush, 20, 150);
            page.Graphics.DrawString("Flat", sectionFont, brush, 20, 175);
            page.Graphics.DrawLine(bluePen, 100, 180, 400, 180);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 180, 400, 180);
            page.Graphics.DrawString("Square", sectionFont, brush, 20, 195);
            bluePen.LineCap = PdfLineCap.Square;
            page.Graphics.DrawLine(bluePen, 100, 200, 400, 200);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 200, 400, 200);
            page.Graphics.DrawString("Round", sectionFont, brush, 20, 215);
            bluePen.LineCap = PdfLineCap.Round;
            page.Graphics.DrawLine(bluePen, 100, 220, 400, 220);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 220, 400, 220);

            page.Graphics.DrawString("Line join styles:", sectionFont, brush, 20, 250);
            page.Graphics.DrawString("Miter", sectionFont, brush, 20, 280);
            PdfPath miterPath = new PdfPath();
            miterPath.StartSubpath(150, 320);
            miterPath.AddLineTo(250, 260);
            miterPath.AddLineTo(350, 320);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Miter;
            page.Graphics.DrawPath(bluePen, miterPath);

            page.Graphics.DrawString("Bevel", sectionFont, brush, 20, 360);
            PdfPath bevelPath = new PdfPath();
            bevelPath.StartSubpath(150, 400);
            bevelPath.AddLineTo(250, 340);
            bevelPath.AddLineTo(350, 400);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Bevel;
            page.Graphics.DrawPath(bluePen, bevelPath);

            page.Graphics.DrawString("Round", sectionFont, brush, 20, 440);
            PdfPath roundPath = new PdfPath();
            roundPath.StartSubpath(150, 480);
            roundPath.AddLineTo(250, 420);
            roundPath.AddLineTo(350, 480);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Round;
            page.Graphics.DrawPath(bluePen, roundPath);

            page.Graphics.DrawString("Random lines clipped to rectangle", sectionFont, brush, 20, 520);
            PdfPath clipPath = new PdfPath();
            clipPath.AddRectangle(20, 550, 570, 230);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(clipPath);

            PdfRgbColor randomColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomColor, 1);
            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomColor.R = (byte)rnd.Next(256);
                randomColor.G = (byte)rnd.Next(256);
                randomColor.B = (byte)rnd.Next(256);

                page.Graphics.DrawLine(randomPen, rnd.NextDouble() * page.Width, 550 + rnd.NextDouble() * 250, rnd.NextDouble() * page.Width, 550 + rnd.NextDouble() * 250);
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, clipPath);

            page.Graphics.CompressAndClose();
        }
Ejemplo n.º 38
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkWithTransparency(PdfPage page)
        {
            PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0));
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 36);

            // The page graphics is located by default on top of existing page content.
            //page.SetGraphicsPosition(PdfPageGraphicsPosition.OverExistingPageContent);

            page.Graphics.SaveGraphicsState();

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = redBrush;
            sao.Font = helvetica;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.X = 130;
            slo.Y = 670;
            slo.Rotation = 60;

            // Draw the watermark over page content but setting the transparency to a value lower than 1.
            // The page content will be partially visible through the watermark.
            PdfExtendedGraphicState gs1 = new PdfExtendedGraphicState();
            gs1.FillAlpha = 0.3;
            page.Graphics.SetExtendedGraphicState(gs1);
            page.Graphics.DrawString("Sample watermark over page content", sao, slo);

            page.Graphics.RestoreGraphicsState();
        }
 private iText.Kernel.Pdf.Navigation.PdfExplicitDestination Add(PdfPage page)
 {
     // Explicitly using object indirect reference here in order to correctly process released objects.
     ((PdfArray)GetPdfObject()).Add(page.GetPdfObject().GetIndirectReference());
     return(this);
 }
Ejemplo n.º 40
0
 private static void SetHeader(Tournament i_tnmt, XFont i_font, PdfPage i_page, XGraphics i_graph)
 {
     i_graph.DrawString("Rangliste " + i_tnmt.tnmtName, i_font, XBrushes.Black, new XRect(10, 10, i_page.Width.Point, i_page.Height.Point), XStringFormats.TopCenter);
 }
Ejemplo n.º 41
0
        private static void DrawShadings(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

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

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

            PdfAxialShading horizontalShading = new PdfAxialShading();
            horizontalShading.StartColor = new PdfRgbColor(255, 0, 0);
            horizontalShading.EndColor = new PdfRgbColor(0, 0, 255);
            horizontalShading.StartPoint = new PdfPoint(25, 90);
            horizontalShading.EndPoint = new PdfPoint(175, 90);

            // Clip the shading to desired area.
            PdfPath hsArea = new PdfPath();
            hsArea.AddRectangle(25, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(hsArea);
            page.Graphics.DrawShading(horizontalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Vertical", sectionFont, brush, 225, 70);

            PdfAxialShading verticalShading = new PdfAxialShading();
            verticalShading.StartColor = new PdfRgbColor(255, 0, 0);
            verticalShading.EndColor = new PdfRgbColor(0, 0, 255);
            verticalShading.StartPoint = new PdfPoint(225, 90);
            verticalShading.EndPoint = new PdfPoint(225, 240);

            // Clip the shading to desired area.
            PdfPath vsArea = new PdfPath();
            vsArea.AddRectangle(225, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(vsArea);
            page.Graphics.DrawShading(verticalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Diagonal", sectionFont, brush, 425, 70);

            PdfAxialShading diagonalShading = new PdfAxialShading();
            diagonalShading.StartColor = new PdfRgbColor(255, 0, 0);
            diagonalShading.EndColor = new PdfRgbColor(0, 0, 255);
            diagonalShading.StartPoint = new PdfPoint(425, 90);
            diagonalShading.EndPoint = new PdfPoint(575, 240);

            // Clip the shading to desired area.
            PdfPath dsArea = new PdfPath();
            dsArea.AddRectangle(425, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(dsArea);
            page.Graphics.DrawShading(diagonalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Extended shading", sectionFont, brush, 25, 260);

            PdfAxialShading extendedShading = new PdfAxialShading();
            extendedShading.StartColor = new PdfRgbColor(255, 0, 0);
            extendedShading.EndColor = new PdfRgbColor(0, 0, 255);
            extendedShading.StartPoint = new PdfPoint(225, 280);
            extendedShading.EndPoint = new PdfPoint(375, 280);
            extendedShading.ExtendStart = true;
            extendedShading.ExtendEnd = true;

            // Clip the shading to desired area.
            PdfPath esArea = new PdfPath();
            esArea.AddRectangle(25, 280, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(esArea);
            page.Graphics.DrawShading(extendedShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, esArea);

            page.Graphics.DrawString("Limited shading", sectionFont, brush, 25, 330);

            PdfAxialShading limitedShading = new PdfAxialShading();
            limitedShading.StartColor = new PdfRgbColor(255, 0, 0);
            limitedShading.EndColor = new PdfRgbColor(0, 0, 255);
            limitedShading.StartPoint = new PdfPoint(225, 350);
            limitedShading.EndPoint = new PdfPoint(375, 350);
            limitedShading.ExtendStart = false;
            limitedShading.ExtendEnd = false;

            // Clip the shading to desired area.
            PdfPath lsArea = new PdfPath();
            lsArea.AddRectangle(25, 350, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(lsArea);
            page.Graphics.DrawShading(limitedShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, lsArea);

            page.Graphics.DrawString("Multi-stop shading", sectionFont, brush, 25, 400);
            // Multi-stop shadings use a stitching function to combine the functions that define each gradient part.
            // Function for red to blue shading.
            PdfExponentialFunction redToBlueFunc = new PdfExponentialFunction();
            // Linear function
            redToBlueFunc.Exponent = 1;
            redToBlueFunc.Domain = new double[] { 0, 1 };
            // Red color for start
            redToBlueFunc.C0 = new double[] { 1, 0, 0 };
            // Blue color for start
            redToBlueFunc.C1 = new double[] { 0, 0, 1 };
            // Function for blue to green shading.
            PdfExponentialFunction blueToGreenFunc = new PdfExponentialFunction();
            // Linear function
            blueToGreenFunc.Exponent = 1;
            blueToGreenFunc.Domain = new double[] { 0, 1 };
            // Blue color for start
            blueToGreenFunc.C0 = new double[] { 0, 0, 1 };
            // Green color for start
            blueToGreenFunc.C1 = new double[] { 0, 1, 0 };

            //Stitching function for the shading.
            PdfStitchingFunction shadingFunction = new PdfStitchingFunction();
            shadingFunction.Functions.Add(redToBlueFunc);
            shadingFunction.Functions.Add(blueToGreenFunc);
            shadingFunction.Domain = new double[] { 0, 1 };
            shadingFunction.Encode = new double[] { 0, 1, 0, 1 };

            // Entire shading goes from 0 to 1 (100%).
            // We set the first shading (red->blue) to cover 30% (0 - 0.3) and
            // the second shading to cover 70% (0.3 - 1).
            shadingFunction.Bounds = new double[] { 0.3 };
            // The multistop shading
            PdfAxialShading multiStopShading = new PdfAxialShading();
            multiStopShading.StartPoint = new PdfPoint(25, 420);
            multiStopShading.EndPoint = new PdfPoint(575, 420);
            // The colorspace must match the colors specified in C0 & C1
            multiStopShading.ColorSpace = new PdfRgbColorSpace();
            multiStopShading.Function = shadingFunction;

            // Clip the shading to desired area.
            PdfPath mssArea = new PdfPath();
            mssArea.AddRectangle(25, 420, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(mssArea);
            page.Graphics.DrawShading(multiStopShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, lsArea);

            page.Graphics.DrawString("Radial shading", sectionFont, brush, 25, 470);

            PdfRadialShading rs1 = new PdfRadialShading();
            rs1.StartColor = new PdfRgbColor(0, 255, 0);
            rs1.EndColor = new PdfRgbColor(255, 0, 255);
            rs1.StartCircleCenter = new PdfPoint(50, 500);
            rs1.StartCircleRadius = 10;
            rs1.EndCircleCenter = new PdfPoint(500, 570);
            rs1.EndCircleRadius = 100;

            page.Graphics.DrawShading(rs1);

            PdfRadialShading rs2 = new PdfRadialShading();
            rs2.StartColor = new PdfRgbColor(0, 255, 0);
            rs2.EndColor = new PdfRgbColor(255, 0, 255);
            rs2.StartCircleCenter = new PdfPoint(80, 600);
            rs2.StartCircleRadius = 10;
            rs2.EndCircleCenter = new PdfPoint(110, 690);
            rs2.EndCircleRadius = 100;

            page.Graphics.DrawShading(rs2);

            page.Graphics.CompressAndClose();
        }
 public static iText.Kernel.Pdf.Navigation.PdfExplicitDestination CreateXYZ(PdfPage page, float left, float
                                                                            top, float zoom)
 {
     return(Create(page, PdfName.XYZ, left, float.NaN, float.NaN, top, zoom));
 }
Ejemplo n.º 43
0
        public ActionResult CreatePdf(IFormCollection collection)
        {
            // Create a PDF document
            Document pdfDocument = new Document();

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            try
            {
                // The titles font used to mark various sections of the PDF document
                PdfFont titleFont    = pdfDocument.AddFont(new Font("Times New Roman", 10, FontStyle.Bold, GraphicsUnit.Point));
                PdfFont subtitleFont = pdfDocument.AddFont(new Font("Times New Roman", 8, FontStyle.Regular, GraphicsUnit.Point));

                // The links text font
                PdfFont linkTextFont = pdfDocument.AddFont(new Font("Times New Roman", 8, FontStyle.Bold, GraphicsUnit.Point));
                linkTextFont.IsUnderline = true;

                float xLocation = 5;
                float yLocation = 5;

                // Add document title
                TextElement      titleTextElement = new TextElement(xLocation, yLocation, "Create URI Links in PDF Document", titleFont);
                AddElementResult addElementResult = pdfPage.AddElement(titleTextElement);

                yLocation = addElementResult.EndPageBounds.Bottom + 15;

                // Make a text in PDF a link to a web page

                // Add the text element
                string      text            = "Click this text to open a web page!";
                float       textWidth       = linkTextFont.GetTextWidth(text);
                TextElement linkTextElement = new TextElement(xLocation, yLocation, text, linkTextFont);
                linkTextElement.ForeColor = Color.Navy;
                addElementResult          = pdfPage.AddElement(linkTextElement);

                // Create the URI link element having the size of the text element
                RectangleF     linkRectangle = new RectangleF(xLocation, yLocation, textWidth, addElementResult.EndPageBounds.Height);
                string         url           = "http://www.evopdf.com";
                LinkUrlElement uriLink       = new LinkUrlElement(linkRectangle, url);

                // Add the URI link to PDF document
                pdfPage.AddElement(uriLink);

                yLocation = addElementResult.EndPageBounds.Bottom + 10;

                // Make an image in PDF a link to a web page

                TextElement subtitleTextElement = new TextElement(xLocation, yLocation, "Click the image below to open a web page:", subtitleFont);
                addElementResult = pdfPage.AddElement(subtitleTextElement);

                yLocation = addElementResult.EndPageBounds.Bottom + 5;

                // Add the image element
                ImageElement linkImageElement = new ImageElement(xLocation, yLocation, 120, m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Images/logo.jpg");
                addElementResult = pdfPage.AddElement(linkImageElement);

                // Create the URI link element having the size of the image element
                linkRectangle = addElementResult.EndPageBounds;
                uriLink       = new LinkUrlElement(linkRectangle, url);

                // Add the URI link to PDF document
                pdfPage.AddElement(uriLink);

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "URI_Links.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                pdfDocument.Close();
            }
        }
 public static iText.Kernel.Pdf.Navigation.PdfExplicitDestination CreateFit(PdfPage page)
 {
     return(Create(page, PdfName.Fit, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN));
 }
Ejemplo n.º 45
0
 private async void RenderPdfPageToImageAsync(PdfPage page, Image image) {
     var stream = new InMemoryRandomAccessStream();
     await page.RenderToStreamAsync(stream);
     BitmapImage src = new BitmapImage();
     image.Source = src;
     await src.SetSourceAsync(stream);
 }
Ejemplo n.º 46
0
        public ActionResult AnnotationFlatten(string InsideBrowser, string checkboxFlatten)
        {
            //Creates a new PDF document.
            PdfDocument document = new PdfDocument();

            //Creates a new page
            PdfPage page = document.Pages.Add();

            document.PageSettings.SetMargins(0);

            PdfFont  font  = new PdfStandardFont(PdfFontFamily.Helvetica, 10f);
            PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.Black);
            string   text  = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

            page.Graphics.DrawString("Annotation with Comments and Reviews", font, brush, new PointF(30, 10));
            page.Graphics.DrawString(text, font, brush, new RectangleF(30, 40, page.GetClientSize().Width - 60, 60));

            string markupText = "North American, European and Asian commercial markets";
            PdfTextMarkupAnnotation textMarkupAnnot = new PdfTextMarkupAnnotation("sample", "Highlight", markupText, new PointF(147, 63.5f), font);

            textMarkupAnnot.Author                   = "Annotation";
            textMarkupAnnot.Opacity                  = 1.0f;
            textMarkupAnnot.Subject                  = "Comments and Reviews";
            textMarkupAnnot.ModifiedDate             = new DateTime(2015, 1, 18);
            textMarkupAnnot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
            textMarkupAnnot.TextMarkupColor          = new PdfColor(Color.Yellow);
            textMarkupAnnot.InnerColor               = new PdfColor(Color.Red);
            textMarkupAnnot.Color = new PdfColor(Color.Yellow);
            if (checkboxFlatten == "Flatten")
            {
                textMarkupAnnot.Flatten = true;
            }
            //Create a new comment.
            PdfPopupAnnotation userQuery = new PdfPopupAnnotation();

            userQuery.Author       = "John";
            userQuery.Text         = "Can you please change South Asian to Asian?";
            userQuery.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userQuery);

            //Creates a new comment
            PdfPopupAnnotation userAnswer = new PdfPopupAnnotation();

            userAnswer.Author       = "Smith";
            userAnswer.Text         = "South Asian has changed as Asian";
            userAnswer.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userAnswer);

            //Creates a new review
            PdfPopupAnnotation userAnswerReview = new PdfPopupAnnotation();

            userAnswerReview.Author       = "Smith";
            userAnswerReview.State        = PdfAnnotationState.Completed;
            userAnswerReview.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReview.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReview);

            //Creates a new review
            PdfPopupAnnotation userAnswerReviewJohn = new PdfPopupAnnotation();

            userAnswerReviewJohn.Author       = "John";
            userAnswerReviewJohn.State        = PdfAnnotationState.Accepted;
            userAnswerReviewJohn.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReviewJohn.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReviewJohn);

            //Add annotation to the page
            page.Annotations.Add(textMarkupAnnot);

            RectangleF bounds = new RectangleF(350, 170, 80, 80);
            //Creates a new Circle annotation.
            PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds);

            circleannotation.InnerColor      = new PdfColor(Color.Yellow);
            circleannotation.Color           = new PdfColor(Color.Red);
            circleannotation.AnnotationFlags = PdfAnnotationFlags.Default;
            circleannotation.Author          = "Syncfusion";
            circleannotation.Subject         = "CircleAnnotation";
            circleannotation.ModifiedDate    = new DateTime(2015, 1, 18);
            page.Annotations.Add(circleannotation);
            page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 130));

            //Creates a new Ellipse annotation.
            PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 150, 50, 100), "Ellipse Annotation");

            ellipseannotation.Color      = new PdfColor(Color.Red);
            ellipseannotation.InnerColor = new PdfColor(Color.Yellow);
            page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 130));
            page.Annotations.Add(ellipseannotation);

            //Creates a new Square annotation.
            PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 300, 80, 80));

            squareannotation.Text       = "SquareAnnotation";
            squareannotation.InnerColor = new PdfColor(Color.Red);
            squareannotation.Color      = new PdfColor(Color.Yellow);
            page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 280));
            page.Annotations.Add(squareannotation);

            //Creates a new Rectangle annotation.
            RectangleF             rectannot           = new RectangleF(350, 320, 100, 50);
            PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation");

            rectangleannotation.InnerColor = new PdfColor(Color.Red);
            rectangleannotation.Color      = new PdfColor(Color.Yellow);
            page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 280));
            page.Annotations.Add(rectangleannotation);

            //Creates a new Line annotation.
            int[]             points         = new int[] { 400, 350, 550, 350 };
            PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type...");

            lineAnnotation.Author       = "Syncfusion";
            lineAnnotation.Subject      = "LineAnnotation";
            lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18);
            lineAnnotation.Text         = "PdfLineAnnotation";
            lineAnnotation.BackColor    = new PdfColor(Color.Red);
            page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 420));
            page.Annotations.Add(lineAnnotation);

            //Creates a new Polygon annotation.
            int[] polypoints = new int[] { 50, 298, 100, 325, 200, 355, 300, 230, 180, 230 };
            PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation");

            polygonannotation.Bounds = new RectangleF(30, 210, 300, 200);
            PdfPen pen = new PdfPen(Color.Red);

            polygonannotation.Text       = "polygon";
            polygonannotation.Color      = new PdfColor(Color.Red);
            polygonannotation.InnerColor = new PdfColor(Color.LightPink);
            page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 420));
            page.Annotations.Add(polygonannotation);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect = new RectangleF(405, 645, 80, 30);
            PdfFreeTextAnnotation freeText     = new PdfFreeTextAnnotation(freetextrect);

            freeText.MarkupText      = "Free Text with Callouts";
            freeText.TextMarkupColor = new PdfColor(Color.Green);
            freeText.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText.BorderColor     = new PdfColor(Color.Blue);
            freeText.Border          = new PdfAnnotationBorder(.5f);
            freeText.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText.Text            = "Free Text";
            freeText.Color           = new PdfColor(Color.Yellow);
            PointF[] Freetextpoints = { new PointF(365, 700), new PointF(379, 654), new PointF(405, 654) };
            freeText.CalloutLines = Freetextpoints;
            page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 610));
            page.Annotations.Add(freeText);

            //Creates a new Ink annotation.
            List <float> linePoints = new List <float> {
                72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f
            };
            RectangleF       rectangle     = new RectangleF(30, 580, 300, 400);
            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints);

            inkAnnotation.Bounds = rectangle;
            inkAnnotation.Color  = new PdfColor(Color.Red);
            page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610));
            page.Annotations.Add(inkAnnotation);

            PdfPage secondPage = document.Pages.Add();

            //Creates a new TextMarkup annotation.
            string s = "This is TextMarkup annotation!!!";

            secondPage.Graphics.DrawString(s, font, brush, new PointF(30, 70));
            PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Strikeout", s, new PointF(30, 70), font);

            textannot.Author                   = "Annotation";
            textannot.Opacity                  = 1.0f;
            textannot.Subject                  = "pdftextmarkupannotation";
            textannot.ModifiedDate             = new DateTime(2015, 1, 18);
            textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut;
            textannot.TextMarkupColor          = new PdfColor(Color.Yellow);
            textannot.InnerColor               = new PdfColor(Color.Red);
            textannot.Color = new PdfColor(Color.Yellow);
            if (checkboxFlatten == "Flatten")
            {
                textannot.Flatten = true;
            }
            secondPage.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 40));
            secondPage.Annotations.Add(textannot);

            //Creates a new popup annotation.
            RectangleF         popupRect       = new RectangleF(430, 70, 30, 30);
            PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation();

            popupAnnotation.Border.Width            = 4;
            popupAnnotation.Border.HorizontalRadius = 20;
            popupAnnotation.Border.VerticalRadius   = 30;
            popupAnnotation.Opacity    = 1;
            popupAnnotation.Open       = true;
            popupAnnotation.Text       = "Popup Annotation";
            popupAnnotation.Color      = Color.Green;
            popupAnnotation.InnerColor = Color.Blue;
            popupAnnotation.Bounds     = popupRect;
            if (checkboxFlatten == "Flatten")
            {
                popupAnnotation.FlattenPopUps = true;
                popupAnnotation.Flatten       = true;
            }
            secondPage.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 40));
            secondPage.Annotations.Add(popupAnnotation);

            //Creates a new Line measurement annotation.
            points = new int[] { 400, 630, 550, 630 };
            PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points);

            lineMeasureAnnot.Author                 = "Syncfusion";
            lineMeasureAnnot.Subject                = "LineAnnotation";
            lineMeasureAnnot.ModifiedDate           = new DateTime(2015, 1, 18);
            lineMeasureAnnot.Unit                   = PdfMeasurementUnit.Inch;
            lineMeasureAnnot.lineBorder.BorderWidth = 2;
            lineMeasureAnnot.Font                   = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);
            lineMeasureAnnot.Color                  = new PdfColor(Color.Red);
            if (checkboxFlatten == "Flatten")
            {
                lineMeasureAnnot.Flatten = true;
            }
            secondPage.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 130));
            secondPage.Annotations.Add(lineMeasureAnnot);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect0 = new RectangleF(80, 160, 100, 50);
            PdfFreeTextAnnotation freeText0     = new PdfFreeTextAnnotation(freetextrect0);

            freeText0.MarkupText      = "Free Text with Callouts";
            freeText0.TextMarkupColor = new PdfColor(Color.Green);
            freeText0.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText0.BorderColor     = new PdfColor(Color.Blue);
            freeText0.Border          = new PdfAnnotationBorder(.5f);
            freeText0.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText0.Text            = "Free Text";
            freeText0.Rotate          = PdfAnnotationRotateAngle.RotateAngle90;
            freeText0.Color           = new PdfColor(Color.Yellow);
            PointF[] Freetextpoints0 = { new PointF(45, 220), new PointF(60, 175), new PointF(80, 175) };
            freeText0.CalloutLines = Freetextpoints0;
            secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 130));
            if (checkboxFlatten == "Flatten")
            {
                freeText0.Flatten = true;
            }
            secondPage.Annotations.Add(freeText0);

            MemoryStream SourceStream = new MemoryStream();

            document.Save(SourceStream);
            document.Close(true);

            //Creates a new Loaded document.
            PdfLoadedDocument lDoc   = new PdfLoadedDocument(SourceStream);
            PdfLoadedPage     lpage1 = lDoc.Pages[0] as PdfLoadedPage;
            PdfLoadedPage     lpage2 = lDoc.Pages[1] as PdfLoadedPage;

            if (checkboxFlatten == "Flatten")
            {
                lpage1.Annotations.Flatten = true;
                lpage2.Annotations.Flatten = true;
            }

            //Save to disk
            if (InsideBrowser == "Browser")
            {
                return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Gets the orientation of a page, either portrait, landscape or square.
        /// </summary>
        /// <param name="page">The page to check.</param>
        /// <returns>The PdfPageOrientation of the page.</returns>
        private PdfPageOrientation GetPageOrientation(PdfPage page) {
            if(page == null) {
                throw new ArgumentNullException("page", "The page parameter cannot be null.");
            }
            double height = page.Dimensions.MediaBox.Height;
            double width = page.Dimensions.MediaBox.Width;

            if(height == width) {
                return PdfPageOrientation.Square;
            }
            return width > height ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait;
        }
Ejemplo n.º 48
0
        public void DrawImage(PdfPage page, string picPath)
        {
            XImage image = XImage.FromFile(picPath);

            if (image.PixelWidth > image.PixelHeight)
            {
                page.Orientation = PdfSharp.PageOrientation.Landscape;
            }

            if (image.PixelWidth > page.Width.Point || image.PixelHeight > page.Height.Point)
            {
                page.Size = PdfSharp.PageSize.A3;
            }

            if (image.PixelWidth > page.Width.Point || image.PixelHeight > page.Height.Point)
            {
                page.Size = PdfSharp.PageSize.A2;
            }

            if (image.PixelWidth > page.Width.Point || image.PixelHeight > page.Height.Point)
            {
                page.Size = PdfSharp.PageSize.A1;
            }

            if (image.PixelWidth > page.Width.Point || image.PixelHeight > page.Height.Point)
            {
                page.Size = PdfSharp.PageSize.A0;
            }

            XGraphics gfx = XGraphics.FromPdfPage(page);

            //double x = (gfx.PageSize.Width - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
            //double y = (gfx.PageSize.Height - image.PixelHeight * 72 / image.VerticalResolution) / 2;

            double xscale = (double)image.PixelWidth / (double)image.PixelHeight;
            double yscale = (double)image.PixelHeight / (double)image.PixelWidth;

            double width  = 0;
            double height = 0;
            double x      = 0;
            double y      = 0;

            if (image.PixelWidth > image.PixelHeight)
            {
                width  = gfx.PageSize.Width - 10;
                height = width * yscale;
                x      = 5;
                y      = (gfx.PageSize.Height - height) / 2 - 1;
            }
            else
            {
                height = gfx.PageSize.Height - 10;
                width  = height * xscale;
                x      = (gfx.PageSize.Width - width) / 2 - 1;
                y      = 5;
            }


            gfx.DrawImage(image, Math.Floor(x), Math.Floor(y), Math.Floor(width), Math.Floor(height));
            //gfx.DrawImage(image, x, y, width * 72 / image.HorizontalResolution, height * 72 / image.VerticalResolution);
        }
Ejemplo n.º 49
0
		/// <summary>
		/// Draw fill forms
		/// </summary>
		/// <param name="bmp"><see cref="PdfBitmap"/> object</param>
		/// <param name="page">Page to be drawn</param>
		/// <param name="actualRect">Page bounds in control coordinates</param>
		/// <remarks>
		/// Full page rendering is performed in the following order:
		/// <list type="bullet">
		/// <item><see cref="DrawPageBackColor"/></item>
		/// <item><see cref="DrawPage"/> / <see cref="DrawLoadingIcon"/></item>
		/// <item><see cref="DrawFillForms"/></item>
		/// <item><see cref="DrawPageBorder"/></item>
		/// <item><see cref="DrawFillFormsSelection"/></item>
		/// <item><see cref="DrawTextHighlight"/></item>
		/// <item><see cref="DrawTextSelection"/></item>
		/// <item><see cref="DrawCurrentPageHighlight"/></item>
		/// <item><see cref="DrawPageSeparators"/></item>
		/// </list>
		/// </remarks>
		protected virtual void DrawFillForms(PdfBitmap bmp, PdfPage page, Rect actualRect)
		{
			int x = Helpers.PointsToPixels(actualRect.X);
			int y = Helpers.PointsToPixels(actualRect.Y);
			int width = Helpers.PointsToPixels(actualRect.Width);
			int height = Helpers.PointsToPixels(actualRect.Height);

			//Draw fillforms to bitmap
			page.RenderForms(bmp, x, y, width, height, PageRotation(page), RenderFlags);
		}
Ejemplo n.º 50
0
 /// <summary>
 /// Initializes a new instance of FormSelector from a PdfPage.
 /// </summary>
 public Selector(PdfPage page)
 {
     PdfDocument owner = page.Owner;
     _path = "*" + owner.Guid.ToString("B");
     _path = _path.ToLowerInvariant();
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Adds the specified outline entry.
 /// </summary>
 /// <param name="title">The outline text.</param>
 /// <param name="destinationPage">The destination page.</param>
 /// <param name="opened">Specifies whether the node is displayed expanded (opened) or collapsed.</param>
 /// <param name="style">The font style used to draw the outline text.</param>
 public PdfOutline Add(string title, PdfPage destinationPage, bool opened, PdfOutlineStyle style)
 {
   PdfOutline outline = new PdfOutline(title, destinationPage, opened, style);
   Add(outline);
   return outline;
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Fixes the /P element in imported annotation.
 /// </summary>
 internal static void FixImportedAnnotation(PdfPage page)
 {
   PdfArray annots = page.Elements.GetArray(PdfPage.Keys.Annots);
   if (annots != null)
   {
     int count = annots.Elements.Count;
     for (int idx=0;idx<count;idx++)
     {
       PdfDictionary annot = annots.Elements.GetDictionary(idx);
       if (annot != null && annot.Elements.Contains("/P"))
         annot.Elements["/P"] = page.Reference;
     }
   }
 }
Ejemplo n.º 53
0
        public ActionResult CreateDocument(string id, string vrsta, string znak)
        {
            PdfFont font    = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            PdfBrush    brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
            PdfDocument doc   = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            PdfGrid     pdfGrid  = new PdfGrid();

            //Load the image as stream.
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 200, 200);

            //Draw the image
            Syncfusion.Drawing.RectangleF bounds    = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement        header    = new PdfPageTemplateElement(bounds);
            PdfCompositeField             compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o natjecajima");

            compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0));

            //Add the header at the top.

            doc.Template.Top = header;
            //Save the PDF document to stream
            //Create a Page template that can be used as footer.


            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);



            //Create page number field.

            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field.

            PdfPageCountField count = new PdfPageCountField(font, brush);

            //Add the fields in composite fields.

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.

            compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40));

            //Add the footer template at the bottom.

            doc.Template.Bottom = footer;

            MemoryStream stream = new MemoryStream();
            //Add values to list
            List <object> data = new List <object>();

            switch (vrsta)
            {
            case "Naziv":

                var oprema = _context.Oprema
                             .AsNoTracking()
                             .Where(n => n.Naziv.Equals(id))
                             .OrderBy(o => o.Id)
                             .ToList();
                ispisi(oprema, data);

                break;

            case "Status":
                oprema = _context.Oprema
                         .AsNoTracking()
                         .Where(n => n.Status.Equals(id))
                         .OrderBy(o => o.Id)
                         .ToList();
                ispisi(oprema, data);


                break;

            case "Dostupnost":
                bool stanje = bool.Parse(id);
                oprema = _context.Oprema
                         .AsNoTracking()
                         .Where(n => n.Dostupnost.Equals(id))
                         .OrderBy(o => o.Id)
                         .ToList();
                ispisi(oprema, data);


                break;

            default:
                Console.WriteLine("Niste unijeli string");
                break;
            }



            //Add list to IEnumerable
            IEnumerable <object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50));

            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Oprema-Reports.pdf";

            return(File(stream, contentType, fileName));
        }
        private void CrearPDF()
        {
            PdfWriter   pdfWriter = new PdfWriter("Reporte.pdf");
            PdfDocument pdf       = new PdfDocument(pdfWriter);
            Document    document  = new Document(pdf, PageSize.LETTER);

            document.SetMargins(60, 20, 55, 20);
            //var parrafo = new Paragraph("Hola mundo");
            //document.Add(parrafo);

            PdfFont fontColumnas  = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            PdfFont fontContenido = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

            string[] columnas = { "Numero de ingreso", "Usuario", "Fecha y Hora" };//Id_Bitacora,Id_Usr,HORA
            float[]  tamanos  = { 4, 4, 4 };
            Table    tabla    = new Table(UnitValue.CreatePercentArray(tamanos));

            tabla.SetWidth(UnitValue.CreatePercentValue(100));
            foreach (string columna in columnas)
            {
                tabla.AddHeaderCell(new Cell().Add(new Paragraph(columna).SetFont(fontColumnas)));
            }
            string sql = "SELECT p.Id_Bitacora,p.Id_Usuario,p.HORA FROM bitacora AS p ";

            cn.Open();
            MySqlCommand    comando = new MySqlCommand(sql, cn);
            MySqlDataReader reader  = comando.ExecuteReader();

            while (reader.Read())
            {
                //for(int x = 1; x < 100; x++) {
                tabla.AddCell(new Cell().Add(new Paragraph(reader["Id_Bitacora"].ToString()).SetFont(fontContenido)));
                tabla.AddCell(new Cell().Add(new Paragraph(reader["Id_Usuario"].ToString()).SetFont(fontContenido)));
                tabla.AddCell(new Cell().Add(new Paragraph(reader["HORA"].ToString()).SetFont(fontContenido)));
                //}
            }
            document.Add(tabla);
            document.Close();
            var logo   = new iText.Layout.Element.Image(ImageDataFactory.Create("logo.png")).SetWidth(50);
            var plogo  = new Paragraph("").Add(logo);
            var titulo = new Paragraph("Reporte de ingresos al sistema");

            titulo.SetTextAlignment(TextAlignment.CENTER);
            titulo.SetFontSize(14);
            var dfecha = DateTime.Now.ToString("dd-MM-yyyy");
            var dhora  = DateTime.Now.ToString("hh:mm:ss");
            var fecha  = new Paragraph("Fecha: " + dfecha + " Hora: " + dhora);

            fecha.SetFontSize(8);
            PdfDocument pdfDoc  = new PdfDocument(new PdfReader("Reporte.pdf"), new PdfWriter("Reportefechado.pdf"));
            Document    doc     = new Document(pdfDoc);
            int         numeros = pdfDoc.GetNumberOfPages();

            for (int i = 1; i <= numeros; i++)
            {
                PdfPage pagina = pdfDoc.GetPage(i);
                float   y      = (pdfDoc.GetPage(i).GetPageSize().GetTop() - 15);
                doc.ShowTextAligned(plogo, 40, y, i, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
                doc.ShowTextAligned(titulo, 150, y, i, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
                doc.ShowTextAligned(fecha, 520, y, i, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
                doc.ShowTextAligned(new Paragraph(String.Format("Página {0} de {1}", i, numeros)), pdfDoc.GetPage(i).GetPageSize().GetWidth() / 2, pdfDoc.GetPage(i).GetPageSize().GetBottom() + 30, i, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
            }
            doc.Close();
        }
Ejemplo n.º 55
0
 /// <summary>
 /// Gets the imported object table.
 /// </summary>
 public PdfImportedObjectTable GetImportedObjectTable(PdfPage page)
 {
     // Is the external PDF file from which is imported already known for the current document?
     Selector selector = new Selector(page);
     PdfImportedObjectTable importedObjectTable;
     if (!_forms.TryGetValue(selector, out importedObjectTable))
     {
         importedObjectTable = new PdfImportedObjectTable(Owner, page.Owner);
         _forms[selector] = importedObjectTable;
     }
     return importedObjectTable;
 }
Ejemplo n.º 56
0
        public ActionResult CreateDocumentWithoutFilter()
        {
            PdfFont font    = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            PdfBrush    brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
            PdfDocument doc   = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            PdfGrid     pdfGrid  = new PdfGrid();

            //Load the image as stream.
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 200, 200);

            //Draw the image
            Syncfusion.Drawing.RectangleF bounds    = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement        header    = new PdfPageTemplateElement(bounds);
            PdfCompositeField             compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o opremi");

            compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0));

            //Add the header at the top.

            doc.Template.Top = header;
            //Save the PDF document to stream
            //Create a Page template that can be used as footer.


            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);



            //Create page number field.

            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field.

            PdfPageCountField count = new PdfPageCountField(font, brush);

            //Add the fields in composite fields.

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.

            compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40));

            //Add the footer template at the bottom.

            doc.Template.Bottom = footer;

            MemoryStream  stream = new MemoryStream();
            List <object> data   = new List <object>();

            var oprema = _context.Oprema
                         .AsNoTracking()
                         .OrderBy(o => o.Id)
                         .ToList();

            foreach (var komad in oprema)
            {
                var row = new
                {
                    Naziv      = komad.Naziv,
                    Status     = komad.Status,
                    Dostupnost = komad.Dostupnost
                };
                data.Add(row);
            }



            //Add list to IEnumerable
            IEnumerable <object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50));
            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Oprema-Reports.pdf";

            return(File(stream, contentType, fileName));
        }
Ejemplo n.º 57
0
		private PageRotate PageRotation(PdfPage pdfPage)
		{
			int rot = pdfPage.Rotation - pdfPage.OriginalRotation;
			if (rot < 0)
				rot = 4 + rot;
			return (PageRotate)rot;
		}
Ejemplo n.º 58
0
        private void DrawCoolblueHeaderLogo(PdfPage page, XGraphics gfx)
        {
            XImage image = XImage.FromFile(@"image\Coolblue500corner.jpg");

            gfx.DrawImage(image, -40, -60, 250, 250);
        }
Ejemplo n.º 59
0
        public void RunPages(Pages pgs)	// this does all the work
        {
            foreach (Page p in pgs)
            {
                //Create a Page Dictionary representing a visible page
                page = new PdfPage(anchor);
                content = new PdfContent(anchor);

                PdfPageSize pSize = new PdfPageSize((int)r.ReportDefinition.PageWidth.ToPoints(),
                                    (int)r.ReportDefinition.PageHeight.ToPoints());
                _pSize = pSize;
                page.CreatePage(pageTree.objectNum, pSize);
                pageTree.AddPage(page.objectNum);
                if (r.ItextPDF)
                {
                    //Itextsharp pdf handler, set pagesize
                    pdfdocument.SetPageSize(new iTextSharp.text.Rectangle(r.ReportDefinition.PageWidth.ToPoints(), r.ReportDefinition.PageHeight.ToPoints()));
                    pdfdocument.NewPage();
                }
                //Create object that presents the elements in the page
                elements = new PdfElements(page, pSize);

                ProcessPage(pgs, p);

                // after a page
                content.SetStream(elements.EndElements());

                page.AddResource(fonts, content.objectNum);
                page.AddResource(patterns, content.objectNum);
                //get the pattern colorspace...
                PatternObj po = new PatternObj(anchor);
                page.AddResource(po, content.objectNum);
                if (r.ItextPDF == false)
                {
                    int size = 0;
                    tw.Write(page.GetPageDict(filesize, out size), 0, size);
                    filesize += size;

                    tw.Write(content.GetContentDict(filesize, out size), 0, size);
                    filesize += size;

                    tw.Write(po.GetPatternObj(filesize, out size), 0, size);
                    filesize += size;
                }
            }
            return;
        }
Ejemplo n.º 60
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Create a new PDF Document. The pdfDoc object represents the PDF document.
            //This document has one page by default and additional pages have to be added.
            PdfDocument pdfDoc = new PdfDocument();
            PdfPage     page   = pdfDoc.Pages.Add();

            // Get xmp object.
            XmpMetadata xmp = pdfDoc.DocumentInformation.XmpMetadata;


            // XMP Basic Schema.
            BasicSchema basic = xmp.BasicSchema;

            basic.Advisory.Add("advisory");
            basic.BaseURL     = new Uri("http://google.com");
            basic.CreateDate  = DateTime.Now;
            basic.CreatorTool = "creator tool";
            basic.Identifier.Add("identifier");
            basic.Label        = "label";
            basic.MetadataDate = DateTime.Now;
            basic.ModifyDate   = DateTime.Now;
            basic.Nickname     = "nickname";
            basic.Rating.Add(-25);

            //Setting various Document properties.
            pdfDoc.DocumentInformation.Title        = "Document Properties Information";
            pdfDoc.DocumentInformation.Author       = "Syncfusion";
            pdfDoc.DocumentInformation.Keywords     = "PDF";
            pdfDoc.DocumentInformation.Subject      = "PDF demo";
            pdfDoc.DocumentInformation.Producer     = "Syncfusion Software";
            pdfDoc.DocumentInformation.CreationDate = DateTime.Now;

            PdfFont  font     = new PdfStandardFont(PdfFontFamily.Helvetica, 10f);
            PdfFont  boldFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            PdfBrush brush    = PdfBrushes.Black;

            PdfGraphics     g      = page.Graphics;
            PdfStringFormat format = new PdfStringFormat();

            format.LineSpacing = 10f;

            g.DrawString("Press Ctrl+D to see Document Properties", boldFont, brush, 10, 10);
            g.DrawString("Basic Schema Xml:", boldFont, brush, 10, 50);
            g.DrawString(basic.XmlData.OuterXml, font, brush, new RectangleF(10, 70, 500, 500), format);

            //Defines and set values for Custom metadata and add them to the Pdf document
            CustomSchema custom = new CustomSchema(xmp, "custom", "http://www.syncfusion.com/");

            custom["Company"] = "Syncfusion";
            custom["Website"] = "http://www.syncfusion.com/";
            custom["Product"] = "Essential PDF";


            //Save the PDF Document to disk.
            pdfDoc.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }