public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithGradient();
            // Create new XPS Document
            XpsDocument doc = new XpsDocument();
            // Initialize List of XpsGradentStop
            List <XpsGradientStop> stops = new List <XpsGradientStop>();

            // Add Colors to Gradient
            stops.Add(doc.CreateGradientStop(doc.CreateColor(0, 142, 4), 0f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 202, 0), 0.144531f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 250, 0), 0.264648f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 0, 0), 0.414063f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(233, 0, 255), 0.544922f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(107, 27, 190), 0.694336f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(63, 0, 255), 0.844727f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(0, 199, 80), 1f));
            // Create new path by defining geometery in abbreviation form
            XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 10,10 L 228,10 228,100 10,100"));

            path.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 20f, 70f);
            path.Fill            = doc.CreateLinearGradientBrush(new PointF(10f, 10f), new PointF(228f, 100f));
            ((XpsGradientBrush)path.Fill).GradientStops.AddRange(stops);
            // Save resultant XPS document
            doc.Save(dataDir + "AddLinearGradient_out.xps");
            // ExEnd:1
        }
예제 #2
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithGradient();
            // Create new XPS Document
            XpsDocument doc = new XpsDocument();
            // Initialize List of XpsGradentStop
            List <XpsGradientStop> stops = new List <XpsGradientStop>();

            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 244, 253, 225), 0.0673828f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 251, 240, 23), 0.314453f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 252, 209, 0), 0.482422f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 241, 254, 161), 0.634766f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 53, 253, 255), 0.915039f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(255, 12, 91, 248), 1f));
            // Create new path by defining geometery in abbreviation form
            XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 10,210 L 228,210 228,300 10,300"));

            path.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 20f, 70f);
            path.Fill            = doc.CreateLinearGradientBrush(new PointF(10f, 0f), new PointF(228f, 0f));
            ((XpsGradientBrush)path.Fill).GradientStops.AddRange(stops);
            // Save resultant XPS document
            doc.Save(dataDir + "AddHorizontalGradient_out.xps");
            // ExEnd:1
        }
예제 #3
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithGradient();
            // Create new XPS Document
            XpsDocument doc = new XpsDocument();
            // Initialize List of XpsGradentStop
            List <XpsGradientStop> stops = new List <XpsGradientStop>();

            stops.Add(doc.CreateGradientStop(doc.CreateColor(253, 255, 12, 0), 0f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(252, 255, 154, 0), 0.359375f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(252, 255, 56, 0), 0.424805f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(253, 255, 229, 0), 0.879883f));
            stops.Add(doc.CreateGradientStop(doc.CreateColor(252, 255, 255, 234), 1f));
            // Create new path by defining geometery in abbreviation form
            XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 10,110 L 228,110 228,200 10,200"));

            path.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 20f, 70f);
            path.Fill            = doc.CreateLinearGradientBrush(new PointF(10f, 110f), new PointF(10f, 200f));
            ((XpsGradientBrush)path.Fill).GradientStops.AddRange(stops);
            // Save resultant XPS document
            doc.Save(dataDir + "AddVerticalGradient_out.xps");
            // ExEnd:1
        }
예제 #4
0
        private void AddImage(AsposePageDocumentInfo doc, string imageFile)
        {
            XpsDocument document = doc.Document as XpsDocument;

            string signatureImageName = imageFile;

            XpsPath path = document.AddPath(document.CreatePathGeometry("M 413.65,0 L 611.95,0 L 611.95,99.15 L 413.65,99.15 Z"));

            path.Clip = document.CreatePathGeometry("M 0.000008454,0 L 612,0 L 612,792 L 0.000008454,792 Z ");
            var imageBrush = document.CreateImageBrush(signatureImageName, new RectangleF(0, 0, 350.05f, 150.02f), new RectangleF(0, 0, 1f, 1f));

            imageBrush.Transform = document.CreateMatrix(198.3f, 0, 0, 99.15f, 413.65f, 0);
            imageBrush.TileMode  = XpsTileMode.None;
            path.Fill            = imageBrush;
        }
예제 #5
0
        private void AddDrawing(AsposePageDocumentInfo doc, string signatureImageStr, string outPath)
        {
            byte[] imageBytes             = Convert.FromBase64String(signatureImageStr);
            var    signatureImageFileName = outPath.Replace("xps", "png");

            System.IO.File.WriteAllBytes(signatureImageFileName, imageBytes);

            XpsDocument document = doc.Document as XpsDocument;
            XpsPath     path     = document.AddPath(document.CreatePathGeometry("M 413.65,0 L 611.95,0 L 611.95,99.15 L 413.65,99.15 Z"));

            path.Clip = document.CreatePathGeometry("M 0.000008454,0 L 612,0 L 612,792 L 0.000008454,792 Z ");
            var imageBrush = document.CreateImageBrush(signatureImageFileName, new RectangleF(0, 0, 350.05f, 150.02f), new RectangleF(0, 0, 1f, 1f));

            imageBrush.Transform = document.CreateMatrix(198.3f, 0, 0, 99.15f, 413.65f, 0);
            imageBrush.TileMode  = XpsTileMode.None;
            path.Fill            = imageBrush;
        }
예제 #6
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithImages();
            // Create new XPS Document
            XpsDocument doc = new XpsDocument();
            // Add Image
            XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));

            //Creating a matrix is optional, it can be used for proper positioning
            path.RenderTransform = doc.CreateMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f);
            //Create Image Brush
            path.Fill = doc.CreateImageBrush(dataDir + "QL_logo_color.tif", new RectangleF(0f, 0f, 258.24f, 56.64f), new RectangleF(50f, 20f, 193.68f, 42.48f));
            // Save resultant XPS document
            doc.Save(dataDir + "AddImage_out.xps");
            // ExEnd:1
        }
예제 #7
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithVisualBrush();

            XpsDocument doc = new XpsDocument();
            // Geometry for magenta grid VisualBrush
            XpsPathGeometry pathGeometry = doc.CreatePathGeometry();

            pathGeometry.AddSegment(doc.CreatePolyLineSegment(
                                        new PointF[] { new PointF(240f, 5f), new PointF(240f, 310f), new PointF(0f, 310f) }));
            pathGeometry[0].StartPoint = new PointF(0f, 5f);

            // Canvas for magenta grid VisualBrush
            XpsCanvas visualCanvas = doc.CreateCanvas();

            XpsPath visualPath = visualCanvas.AddPath(
                doc.CreatePathGeometry("M 0,4 L 4,4 4,0 6,0 6,4 10,4 10,6 6,6 6,10 4,10 4,6 0,6 Z"));

            visualPath.Fill = doc.CreateSolidColorBrush(doc.CreateColor(1f, .61f, 0.1f, 0.61f));

            XpsPath gridPath = doc.CreatePath(pathGeometry);

            //Create Visual Brush, it is specified by some XPS fragment (vector graphics and glyphs)
            gridPath.Fill = doc.CreateVisualBrush(visualCanvas,
                                                  new RectangleF(0f, 0f, 10f, 10f), new RectangleF(0f, 0f, 10f, 10f));
            ((XpsVisualBrush)gridPath.Fill).TileMode = XpsTileMode.Tile;
            // New canvas
            XpsCanvas canvas = doc.AddCanvas();

            canvas.RenderTransform = doc.CreateMatrix(1f, 0f, 0f, 1f, 268f, 70f);
            // Add grid
            canvas.AddPath(gridPath);
            // Red transparent rectangle in the middle top
            XpsPath path = canvas.AddPath(doc.CreatePathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));

            path         = canvas.AddPath(doc.CreatePathGeometry("M 10,10 L 228,10 228,100 10,100"));
            path.Fill    = doc.CreateSolidColorBrush(doc.CreateColor(1.0f, 0.0f, 0.0f));
            path.Opacity = 0.7f;
            // Save resultant XPS document
            doc.Save(dataDir + "AddGrid_out.xps");
            // ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithTransparency();
            // Create new XPS Document
            XpsDocument doc = new XpsDocument();

            // Just to demonstrate transparency
            doc.AddPath(doc.CreatePathGeometry("M120,0 H400 v1000 H120")).Fill = doc.CreateSolidColorBrush(Color.Gray);
            doc.AddPath(doc.CreatePathGeometry("M300,120 h600 V420 h-600")).Fill = doc.CreateSolidColorBrush(Color.Gray);

            // Create path with closed rectangle geometry
            XpsPath path1 = doc.CreatePath(doc.CreatePathGeometry("M20,20 h200 v200 h-200 z"));
            // Set blue solid brush to fill path1
            path1.Fill = doc.CreateSolidColorBrush(Color.Blue);
            // Add it to the current page
            XpsPath path2 = doc.Add(path1);

            // path1 and path2 are the same as soon as path1 hasn't been placed inside any other element
            // (which means that path1 had no parent element).
            // Because of that rectangle's color on the page effectively turns to green
            path2.Fill = doc.CreateSolidColorBrush(Color.Green);

            // Now add path2 once again. Now path2 has parent. So path3 won't be the same as path2.
            // Thus a new rectangle is painted on the page ...
            XpsPath path3 = doc.Add(path2);
            // ... and we shift it 300 units lower ...
            path3.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 300);
            // ... and set red solid brush to fill it
            path3.Fill = doc.CreateSolidColorBrush(Color.Red);

            // Create new path4 with path2's geometry ...
            XpsPath path4 = doc.AddPath(path2.Data);
            // ... shift it 300 units to the right ...
            path4.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 300, 0);
            // ... and set blue solid fill
            path4.Fill = doc.CreateSolidColorBrush(Color.Blue);

            // Add path4 once again.
            XpsPath path5 = doc.Add(path4);
            // path4 and path5 are not the same again ...
            // (move path5 300 units lower)
            path5.RenderTransform = path5.RenderTransform.Clone(); // to disconnect RenderTransform value from path4 (see next comment about Fill property)
            path5.RenderTransform.Translate(0, 300);
            // ... but if we set the opacity of Fill property, it will take effect on both path5 and path4
            // because brush is a complex property value which remains the same for path5 and path4
            path5.Fill.Opacity = 0.8f;

            // Create new path6 with path2's geometry ...
            XpsPath path6 = doc.AddPath(path2.Data);
            // ... shift it 600 units to the right ...
            path6.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 600, 0);
            // ... and set yellow solid fill
            path6.Fill = doc.CreateSolidColorBrush(Color.Yellow);

            // Now add path6's clone ...
            XpsPath path7 = doc.Add(path6.Clone());
            // (move path5 300 units lower)
            path7.RenderTransform = path7.RenderTransform.Clone();
            path7.RenderTransform.Translate(0, 300);
            // ... and set opacity for path7
            path7.Fill.Opacity = 0.8f;
            // Now opacity effects independantly as soon as property values are cloned along with the element

            // The following code block is equivalent to the previous one.
            // Add path6 itself. path6 and path7 are not the same. Although their Fill property values are the same 
            //XpsPath path7 = doc.Add(path6);
            //path7.RenderTransform = path7.RenderTransform.Clone();
            //path7.RenderTransform.Translate(0, 300);
            // To "disconnect" path7's Fill property from path6's Fill property reassign it to its clone (or path6's Fill clone)
            //path7.Fill = ((XpsSolidColorBrush)path7.Fill).Clone();
            //path7.Fill.Opacity = 0.8f;

            // Save resultant XPS document
            doc.Save(dataDir + "WorkingWithTransparency_out.xps");
            // ExEnd:1
        }