private static Size MeasureText(FixedContentEditor editor, string text)
        {
            Block block = CreateBlock(editor);
            block.InsertText(text);

            return block.Measure();
        }
 private static void DrawText(FixedContentEditor editor, string text, double width = double.PositiveInfinity, HorizontalAlignment alignment = HorizontalAlignment.Left)
 {
     Block block = CreateBlock(editor);
     block.HorizontalAlignment = alignment;
     block.InsertText(text);
     editor.DrawBlock(block, new Size(width, double.PositiveInfinity));
 }
        internal static IDisposable SaveClip(FixedContentEditor drawingSurface, Rect rectangle)
        {
            PathGeometry geometry    = MathHelper.TransformRectangle(drawingSurface.Position.Matrix, rectangle);
            var          pdfGeometry = PdfGeometryHelper.ConvertPathGeometry(geometry);

            return(drawingSurface.PushClipping(pdfGeometry));
        }
        public RadFixedDocument CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage page = document.Pages.AddPage();
            page.Size = new Size(600, 800);
            this.editor = new FixedContentEditor(page);
            this.editor.Position.Translate(40, 50);
            using (Stream stream = FileHelper.GetSampleResourceStream("banner.png"))
            {
                ImageSource imageSource = new ImageSource(stream, ImageQuality.High);
                editor.DrawImage(imageSource, new Size(530, 80));
            }

            editor.Position.Translate(ExampleDocumentSizes.DefaultLeftIndent, 160);
            double maxWidth = page.Size.Width - ExampleDocumentSizes.DefaultLeftIndent * 2;

            this.DrawDescription(maxWidth);

            using (editor.SaveProperties())
            {
                using (editor.SavePosition())
                {
                    this.DrawFunnelFigure();
                }
            }

            return document;
        }
        private static void ExportTextShape(RadDiagramTextShape shape, Rect enclosingBounds, RadFixedPage page)
        {
            var bounds = new Rect(shape.Bounds.X - enclosingBounds.X, shape.Bounds.Y - enclosingBounds.Y, shape.Bounds.Width, shape.Bounds.Height);

            var transformGroup = new TransformGroup();

            transformGroup.Children.Add(new RotateTransform()
            {
                Angle = shape.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2
            });
            transformGroup.Children.Add(new TranslateTransform()
            {
                X = bounds.X, Y = bounds.Y
            });

            var position = new MatrixPosition(transformGroup.Value);

            FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle), true);

            containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize()));

            if (shape.Content != null)
            {
                var center = bounds.Center();
                ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return(new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2)); });
            }
        }
示例#6
0
        private void AddPageWithImage()
        {
            RadFixedPage page = this.document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.GraphicProperties.StrokeThickness = 0;
            editor.GraphicProperties.IsStroked       = false;
            editor.GraphicProperties.FillColor       = new RgbColor(200, 200, 200);
            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            Margins margins = new Margins();

            editor.Position.Translate(margins.Left, margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText("Image converted from PNG to JPG");
            block.InsertLineBreak();
            block.InsertText(string.Format("when ImageQuality set to {0}", this.imageQuality));
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(margins.Left, blockSize.Height + margins.Top + 20);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = HorizontalAlignment.Center;
            imageBlock.InsertImage(this.imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
示例#7
0
        private void SubmitChangesAndRemoveTextBox(object sender)
        {
            TextBox textBox = (TextBox)sender;

            textBox.LostFocus -= this.TextBox_LostFocus;
            textBox.KeyDown   -= this.TextBox_KeyDown;

            this.canvas.Children.Remove(textBox);

            string text = textBox.Text;

            RadFixedPage page = this.context.Page;

            FixedContentEditor editor = new FixedContentEditor(page);

            editor.Position.Translate(this.mouseLocation.X, this.mouseLocation.Y);
            editor.DrawText(text);

            RadPdfViewer viewer = this.context.Presenter.Owner as RadPdfViewer;

            if (viewer != null)
            {
                viewer.InvalidatePageUI(page);
            }

            this.hasActiveTextBox = false;
        }
        private static void ExportConnection(RadDiagramConnection connection, Rect enclosingBounds, RadFixedPage page)
        {
            var bounds = new Rect(connection.Bounds.X - enclosingBounds.X, connection.Bounds.Y - enclosingBounds.Y, connection.Bounds.Width, connection.Bounds.Height);

            var pathGeometry = connection.Geometry as PathGeometry;
            var pathBounds   = connection.ConnectionType == ConnectionType.Bezier ? pathGeometry.Bounds : new Rect();

            var transformGroup = new TransformGroup();

            transformGroup.Children.Add(new TranslateTransform()
            {
                X = bounds.X - pathBounds.X, Y = bounds.Y - pathBounds.Y
            });
            var position = new MatrixPosition(transformGroup.Value);

            EditorInfo         info         = new EditorInfo(page, position, connection, bounds, connection.Stroke, 0);
            FixedContentEditor editor       = CreateEditor(info, false);
            FixedContentEditor filledEditor = CreateEditor(info, true);

            ExportGeometry(editor, filledEditor, pathGeometry, true);

            if (connection.Content != null)
            {
                var center = bounds.Center();
                ExportContent(connection, bounds, 0, page, (s) => { return(new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2)); });
            }
        }
示例#9
0
        private void CreatePageWithImage(RadFixedDocument document, string imageExtension, EncodedImageData imageData)
        {
            RadFixedPage page = document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(string.Format("This is {0} image in {1} color space encoded with {2} filter.", imageExtension, imageData.ColorSpace, imageData.Filters.FirstOrDefault() ?? "None"));
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 50);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(new ImageSource(imageData), new Size(imageData.Width, imageData.Height));
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
        /// <summary>
        /// Creates a RadFixedDocument using an image from uploaded content
        /// </summary>
        /// <param name="value">the content to use</param>
        /// <returns>FixedDocument that can be exported asa PDF file</returns>
        private static RadFixedDocument GenerateImageDocument(MyPdfContent value)
        {
            // Load the image data into an ImageSource object
            Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource imageSource;

            using (var imgStream = new MemoryStream(Convert.FromBase64String(value.ImageBase64)))
            {
                imageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(imgStream);
            }

            // instantiate the document and add a page
            var document = new RadFixedDocument();
            var page     = document.Pages.AddPage();

            page.Size = PageSize;

            // instantiate an editor, this is what writes all the content to the page
            var editor = new FixedContentEditor(page);

            editor.GraphicProperties.StrokeThickness = 0;
            editor.GraphicProperties.IsStroked       = false;

            try
            {
                // use the uploaded value for background color
                var bgColor = (Color)ColorConverter.ConvertFromString(value.BackgroundColor);
                editor.GraphicProperties.FillColor = new RgbColor(bgColor.R, bgColor.G, bgColor.B);
            }
            catch
            {
                editor.GraphicProperties.FillColor = new RgbColor(255, 255, 255);
            }

            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            editor.Position.Translate(Margins.Left, Margins.Top);

            // Description text
            var block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;

            // use the uploaded content for the title
            block.InsertText(value.Title);

            var blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 20);

            // NOTE - This is where the ImageSource is used and drawn onto the document
            var imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);

            return(document);
        }
        private void AddPageWithImage(string description, ImageSource imageSource)
        {
            RadFixedPage page = this.document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.GraphicProperties.StrokeThickness = 0;
            editor.GraphicProperties.IsStroked       = false;
            editor.GraphicProperties.FillColor       = new RgbColor(200, 200, 200);
            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(description);
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 20);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
        public RadFixedDocument CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage     page     = document.Pages.AddPage();

            page.Size   = new Size(600, 800);
            this.editor = new FixedContentEditor(page);
            this.editor.Position.Translate(40, 50);

            using (Stream stream = this.resourceService.GetResourceStream("banner.jpg"))
            {
                this.editor.DrawImage(stream, new Size(530, 80));
            }

            this.editor.Position.Translate(ExampleDocumentSizes.DefaultLeftIndent, 160);
            double maxWidth = page.Size.Width - ExampleDocumentSizes.DefaultLeftIndent * 2;

            this.DrawDescription(maxWidth);

            using (this.editor.SaveProperties())
            {
                using (this.editor.SavePosition())
                {
                    this.DrawFunnelFigure();
                }
            }

            return(document);
        }
        private RadFixedDocument CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage page = document.Pages.AddPage();
            page.Size = new Size(600, 750);
            FixedContentEditor editor = new FixedContentEditor(page);
            editor.Position.Translate(defaultLeftIndent, 50);
            using (Stream stream = FileHelper.GetSampleResourceStream("pdfProcessingSilverlight.jpg"))
            {
                editor.DrawImage(stream);
            }
            double currentTopOffset = 110;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.TextProperties.FontSize = 14;
            double maxWidth = page.Size.Width - defaultLeftIndent * 2;

            this.DrawDescription(editor, maxWidth);

            currentTopOffset += defaultLineHeight * 4;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.SaveProperties())
            {
                this.DrawFunnelFigure(editor);
            }

            editor.Position.Translate(defaultLeftIndent * 4, page.Size.Height - 100);
            using (Stream stream = FileHelper.GetSampleResourceStream("telerik.jpg"))
            {
                editor.DrawImage(stream);
            }

            this.DrawText(editor, maxWidth);

            return document;
        }
        private static void DrawHeaderAndFooterToPage(RadFixedPage page, int pageNumber, int numberOfPages)
        {
            FixedContentEditor pageEditor = new FixedContentEditor(page);

            Block       header      = new Block();
            ImageSource imageSource = ImportImage(InputLogoFile);
            Size        imageSize   = new Size(168, 50);

            header.InsertImage(imageSource, imageSize);
            header.Measure();

            double headerOffsetX = (page.Size.Width / 2) - (header.DesiredSize.Width / 2);
            double headerOffsetY = 50;

            pageEditor.Position.Translate(headerOffsetX, headerOffsetY);
            pageEditor.DrawBlock(header);

            Block footer = new Block();

            footer.InsertText(String.Format("Page {0} of {1}", pageNumber, numberOfPages));
            footer.Measure();

            double footerOffsetX = (page.Size.Width / 2) - (footer.DesiredSize.Width / 2);
            double fotterOffsetY = page.Size.Height - 50 - footer.DesiredSize.Height;

            pageEditor.Position.Translate(footerOffsetX, fotterOffsetY);
            pageEditor.DrawBlock(footer);
        }
示例#15
0
        // This is the method which will be called when the internal logic of the PdfFormatProvider reaches a chart which has to be rendered.
        public void RenderChart(FixedContentEditor editor, FloatingChartShape chart)
        {
            BitmapSource source = this.chartToImageConverter.GetBitmapSourceFromFloatingChartShape(chart, 300d, 300d);

            // The editor draws the image in the PDF.
            editor.DrawImage(this.StreamFromBitmapSource(source), new Size(chart.Width, chart.Height));
        }
示例#16
0
 private void DrawBlock(Block block, FixedContentEditor fixedContentEditor)
 {
     #region radpdfprocessing-editing-block_4
     Rect boundingRect = new Rect(new Point(0, 0), new Size(200, 300));
     block.Draw(fixedContentEditor, boundingRect);
     #endregion
 }
示例#17
0
        private void SetExpressions(FixedContentEditor editor)
        {
            double expressionTotalHeight = PageHeight - HeaderSize.Height - offset * 2 - FooterSize.Height - offset * 2;
            double expressionTotalWidth  = PageWidth - DefaultLeftIndent * 2;

            if (ExpressionSize == Size.Empty)
            {
                ExpressionSize = GetExpressionSize();
            }

            double expressionWidth  = ExpressionSize.Width * 1.2;
            double expressionHeight = ExpressionSize.Height + 10d;

            int    howManyExpressionsPerLine = Convert.ToInt32(Math.Floor(expressionTotalWidth / expressionWidth));
            double calculatedExpressionWidth = expressionTotalWidth / howManyExpressionsPerLine;
            int    howManyExpressionLines    = Convert.ToInt32(Math.Floor(expressionTotalHeight / expressionHeight));

            for (int i = 0; i < howManyExpressionLines; i++)
            {
                for (int j = 0; j < howManyExpressionsPerLine; j++)
                {
                    editor.Position.Translate(j * calculatedExpressionWidth + DefaultLeftIndent, i * expressionHeight + HeaderSize.Height + offset * 2);
                    Block block = new Block();

                    this.SetTextProperties(block, new RgbColor(0, 0, 0), 22, FontsRepository.Helvetica);
                    block.InsertText(GetExpression());
                    editor.DrawBlock(block, new Size(PageWidth, PageHeight));
                }
            }
        }
示例#18
0
        internal static IDisposable SaveClip(FixedContentEditor drawingSurface, UIElement element)
        {
            Geometry         clip             = null;
            FrameworkElement frameworkElement = element as FrameworkElement;

            if (frameworkElement != null)
            {
                clip = System.Windows.Controls.Primitives.LayoutInformation.GetLayoutClip(frameworkElement);
            }
            if (clip == null)
            {
                clip = element.Clip;
            }

            RectangleGeometry rectangleClip = clip as RectangleGeometry;

            if (rectangleClip == null)
            {
                return(null);
            }

            PathGeometry geometry    = MathHelper.TransformRectangle(drawingSurface.Position.Matrix, rectangleClip.Rect);
            var          pdfGeometry = PdfGeometryHelper.ConvertPathGeometry(geometry);

            return(drawingSurface.PushClipping(pdfGeometry));
        }
        /// <summary>
        /// Creates a same RadFixedDocument using details text from uploaded content
        /// </summary>
        /// <param name="value">the content to use</param>
        /// <returns>FixedDocument that can be exported asa PDF file</returns>
        private static RadFixedDocument GenerateSampleDocument(MyPdfContent value)
        {
            double defaultLeftIndent = 50;
            double defaultLineHeight = 16;

            var document = new RadFixedDocument();
            var page     = document.Pages.AddPage();

            page.Size = PageSize;

            var editor = new FixedContentEditor(page);

            editor.Position.Translate(defaultLeftIndent, 50);

            double currentTopOffset = 110;

            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            double maxWidth = page.Size.Width - defaultLeftIndent * 2;

            DocumentHelpers.DrawDescription(editor, maxWidth);

            currentTopOffset += defaultLineHeight * 4;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);

            using (editor.SaveProperties())
            {
                DocumentHelpers.DrawFunnelFigure(editor);
            }

            // use the uploaded text
            DocumentHelpers.DrawText(editor, maxWidth, value);

            return(document);
        }
示例#20
0
        // This is the method which will be called when the internal logic of the PdfFormatProvider reaches a chart which has to be rendered.
        public void RenderChart(FixedContentEditor editor, FloatingChartShape chart)
        {
            // The ChartModelToImageConverter object is readily available in the Telerik.Windows.Controls.Spreadsheet assembly and
            // uses internally the RadChartView control to visualize the chart and create an image.
            BitmapSource source = this.chartToImageConverter.GetBitmapSourceFromFloatingChartShape(chart, 300d, 300d);

            // The editor draws the image in the PDF.
            editor.DrawImage(this.StreamFromBitmapSource(source), new Size(chart.Width, chart.Height));
        }
示例#21
0
 private void InsertImage(FixedContentEditor editor)
 {
     #region radpdfprocessing-editing-fixedcontenteditor_4
     using (Stream stream = this.GetResourceStream("Telerik_logo.jpg"))
     {
         editor.DrawImage(stream, ImageFormat.Jpeg, new Size(118, 28));
     }
     #endregion
 }
示例#22
0
        private RadFixedPage CreatePage(System.Windows.Controls.Border element)
        {
            RadFixedPage page = new RadFixedPage();
            page.Size = new Size(1000, 1000);
            FixedContentEditor editor = new FixedContentEditor(page, Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition.Default);

            ExportHelper.ExportToPdf(element, editor);

            return page;
        }
        private static void CenterText(FixedContentEditor editor, string text)
        {
            Block block = new Block();
            block.HorizontalAlignment = HorizontalAlignment.Center;
            block.VerticalAlignment = VerticalAlignment.Center;
            block.GraphicProperties.FillColor = RgbColors.White;
            block.InsertText(text);

            editor.DrawBlock(block, new Size(96, 96));
        }
        private static void DrawDescription(FixedContentEditor editor, double maxWidth)
        {
            double WriteWhere = 0;                    //Define el actual tope del editor en 500

            editor.Position.Translate(0, WriteWhere); //Traslada el editor al nuevo punto de escritura

            //using (FileStream fss = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Images/Blank.PNG"), FileMode.Open, FileAccess.Read))
            //{ editor.DrawImage(fss); }

            WriteWhere = 20;                                              //Define el actual tope del editor en 500
            editor.Position.Translate(MargenIzquierdo + 300, WriteWhere); //Traslada el editor al nuevo punto de escritura

            using (FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Images/LogoBae.jpeg"), FileMode.Open, FileAccess.Read))
            { editor.DrawImage(fs); }
            Block block = new Block();

            WriteWhere += AnchoDeLinea * 4;
            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Traslada el editor al nuevo punto de escritura
            block.InsertText("BAE SYSTEMS");
            block.TextProperties.Font     = FontsRepository.Helvetica;
            block.TextProperties.FontSize = 13;
            editor.DrawBlock(block);
            block = new Block();
            editor.Position.Translate(450, WriteWhere);//Traslada el editor al nuevo punto de escritura
            using (block.SaveTextProperties())
            {
                block.TextProperties.Font = FontsRepository.CourierBold;
                block.InsertText(new FontFamily("Calibri"), "DATE: ");
            }
            block.InsertText(new FontFamily("Calibri"), System.DateTime.Now.ToShortDateString());
            editor.DrawBlock(block);
            WriteWhere += AnchoDeLinea * 2;
            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Traslada el editor al nuevo punto de escritura

            block = new Block();
            block.InsertText("Carretera Internacional KM.129 Salida");
            block.TextProperties.FontSize = 11;
            editor.DrawBlock(block);
            WriteWhere += AnchoDeLinea * 1.5;
            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Traslada el editor al nuevo punto de escritura

            block = new Block();
            block.InsertText("Norte Parque Industrial Roca Fuerte");
            editor.DrawBlock(block);
            block.TextProperties.FontSize = 11;
            WriteWhere += AnchoDeLinea * 1.5;
            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Traslada el editor al nuevo punto de escritura

            block = new Block();
            block.InsertText("Edificio#19 Guaymas Sonora, Mexico");
            editor.DrawBlock(block);
            block.TextProperties.FontSize = 11;
            WriteWhere += AnchoDeLinea * 2;
            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Traslada el editor al nuevo punto de escritura
        }
        private RadFixedPage CreatePage(System.Windows.Controls.Border element)
        {
            RadFixedPage page = new RadFixedPage();

            page.Size = new Size(1000, 1000);
            FixedContentEditor editor = new FixedContentEditor(page, Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition.Default);

            ExportHelper.ExportToPdf(element, editor);

            return(page);
        }
示例#26
0
        private void SetPageNumber(FixedContentEditor editor, int pageNumber)
        {
            Block block = new Block();

            this.SetTextProperties(block, new RgbColor(0, 0, 0), 15, FontsRepository.TimesRoman);
            block.InsertText("- " + pageNumber + " -");
            Size pageNumberSize = block.Measure();

            editor.Position.Translate((PageWidth - pageNumberSize.Width) / 2, PageHeight - pageNumberSize.Height - offset);
            editor.DrawBlock(block, new Size(PageWidth, PageHeight));
        }
        private static void CenterText(FixedContentEditor editor, string text)
        {
            Block block = new Block();

            block.HorizontalAlignment         = HorizontalAlignment.Center;
            block.VerticalAlignment           = VerticalAlignment.Center;
            block.GraphicProperties.FillColor = RgbColors.White;
            block.InsertText(text);

            editor.DrawBlock(block, new Size(96, 96));
        }
示例#28
0
        private static FixedContentEditor CreateEditor(EditorInfo info, bool isFilled)
        {
            FixedContentEditor geometryEditor = new FixedContentEditor(info.Page, info.Position);

            geometryEditor.GraphicProperties.IsFilled        = isFilled;
            geometryEditor.GraphicProperties.FillColor       = ColorHelper.GetColor(info.Background, info.Opacity, info.Bounds, info.Angle);
            geometryEditor.GraphicProperties.StrokeColor     = ColorHelper.GetColor(info.Stroke, info.Opacity, info.Bounds, info.Angle);
            geometryEditor.GraphicProperties.StrokeDashArray = info.StrokeDashArray;
            geometryEditor.GraphicProperties.StrokeThickness = info.StrokeThickness;
            return(geometryEditor);
        }
示例#29
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            RadFixedDocument document = new RadFixedDocument();
            FixedContentEditor editor = new FixedContentEditor(document.Pages.AddPage());
            editor.DrawText("Hello PdfProcessing!");

            PdfFormatProvider provider = new PdfFormatProvider();
            MemoryStream stream = new MemoryStream();
            provider.Export(document, stream);

            this.ViewModel.DocumentStream = stream;
        }
示例#30
0
        public static void CenterText(FixedContentEditor editor, string text)
        {
            Block block = new Block();

            block.TextProperties.TrySetFont(new FontFamily("Calibri"));
            block.HorizontalAlignment         = HorizontalAlignment.Center;
            block.VerticalAlignment           = VerticalAlignment.Center;
            block.GraphicProperties.FillColor = RgbColors.White;
            block.InsertText(text);

            editor.DrawBlock(block, new Size(96, 96));
        }
示例#31
0
        private static void ExportContainerShape(RadDiagramContainerShape container, Rect enclosingBounds, RadFixedPage page)
        {
            var bounds = new Rect(container.Bounds.X - enclosingBounds.X, container.Bounds.Y - enclosingBounds.Y, container.Bounds.Width, container.Bounds.Height);

            var transformGroup = new TransformGroup();

            transformGroup.Children.Add(new RotateTransform()
            {
                Angle = container.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2
            });
            transformGroup.Children.Add(new TranslateTransform()
            {
                X = bounds.X, Y = bounds.Y
            });

            var position = new MatrixPosition(transformGroup.Value);

            FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, container, bounds, container.BorderBrush, container.RotationAngle), true);

            containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize()));

            containerEditor.GraphicProperties.StrokeThickness = 0.5;
            var headerHeight = container.ContentBounds.Y - container.Bounds.Y - DiagramConstants.ContainerMargin;

            containerEditor.DrawRectangle(new Rect(new Point(0, headerHeight), new Size(bounds.Width, 0.5)));

            if (container.IsCollapsible)
            {
                var buttonTop  = headerHeight / 2 - 2.5;
                var buttonLeft = bounds.Width - 20;
                if (container.IsCollapsed)
                {
                    containerEditor.DrawLine(new Point(buttonLeft, buttonTop), new Point(buttonLeft + 4, buttonTop + 4));
                    containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop + 4), new Point(buttonLeft + 8, buttonTop));
                    if (container.CollapsedContent != null)
                    {
                        var contentHeight = container.ActualHeight - headerHeight;
                        ExportContent(container, bounds, container.RotationAngle, page, (s) => { return(new Point(bounds.Center().X - s.Width / 2, bounds.Bottom - contentHeight / 2 - s.Height / 2)); }, container.CollapsedContent.ToString());
                    }
                }
                else
                {
                    containerEditor.DrawLine(new Point(buttonLeft, buttonTop + 4), new Point(buttonLeft + 4, buttonTop));
                    containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop), new Point(buttonLeft + 8, buttonTop + 4));
                }
            }

            if (container.Content != null)
            {
                ExportContent(container, bounds, container.RotationAngle, page, (s) => { return(new Point(bounds.Center().X - s.Width / 2, bounds.Top + headerHeight / 2 - s.Height / 2)); });
            }
        }
示例#32
0
        private void InsertTextFragment(FixedContentEditor editor)
        {
            #region radpdfprocessing-editing-fixedcontenteditor_2
            editor.DrawText("First text fragment.");
            #endregion

            #region radpdfprocessing-editing-fixedcontenteditor_3
            Block block = new Block();
            block.InsertText("First sentence.");
            block.InsertText("Second sentence.");
            editor.DrawBlock(block);
            #endregion
        }
        private static void DrawCenteredText(FixedContentEditor editor, string text, Size size)
        {
            Block block = new Block();

            block.TextProperties.TrySetFont(new FontFamily("Arial"));
            block.HorizontalAlignment         = HorizontalAlignment.Center;
            block.VerticalAlignment           = VerticalAlignment.Center;
            block.GraphicProperties.FillColor = RgbColors.White;
            block.TextProperties.FontSize     = 16;
            block.InsertText(text);

            editor.DrawBlock(block, size);
        }
示例#34
0
        private void InsertClipping(FixedContentEditor editor)
        {
            #region radpdfprocessing-editing-fixedcontenteditor_6
            string visibleText       = "The last word in this text is";
            string text              = string.Format("{0} clipped.", visibleText); //The last word in this text is clipped.
            Size   visisibleTextSize = editor.MeasureText(visibleText);

            using (editor.PushClipping(new Rect(new Point(0, 0), visisibleTextSize)))
            {
                editor.DrawText(text);
            }
            #endregion
        }
        private static RadFixedPage GenerateBackgroundImageContent(string watermarkImage)
        {
            using (Stream imageStream = File.OpenRead(watermarkImage))
            {
                ImageSource  image = new ImageSource(imageStream);
                RadFixedPage backgroundContentOwner = new RadFixedPage();
                backgroundContentOwner.Size = new Size(image.Width, image.Height);
                FixedContentEditor imagePageEditor = new FixedContentEditor(backgroundContentOwner);
                imagePageEditor.DrawImage(image);

                return(backgroundContentOwner);
            }
        }
示例#36
0
        private double AddImageToPage(FixedContentEditor editor, string fileName, double width)
        {
            Block block = new Block();

            using (Stream stream = File.OpenRead(fileName))
            {
                block.InsertImage(stream);
            }
            editor.DrawBlock(block, new Size(width, double.PositiveInfinity));
            Size size = block.Measure();

            return(size.Height);
        }
示例#37
0
 private void Positioning(FixedContentEditor editor)
 {
     #region radpdfprocessing-editing-fixedcontenteditor_7
     editor.Position.Scale(1.5, 0.5);
     editor.Position.Rotate(10);
     editor.DrawText("Image:");
     editor.Position.Translate(0, 20);
     using (Stream stream = this.GetResourceStream("Telerik_logo.jpg"))
     {
         editor.DrawImage(stream, ImageFormat.Jpeg, new Size(118, 28));
     }
     #endregion
 }
示例#38
0
        internal static IDisposable SaveMatrixPosition(FixedContentEditor drawingSurface, FrameworkElement element)
        {
            if (element == null)
            {
                return null;
            }

            GeneralTransform transform = MathHelper.GetGeneralTransform(element);
            Matrix matrix = MathHelper.CreateMatrix(transform);
            if (matrix.IsIdentity)
            {
                return null;
            }

            matrix = MathHelper.Multiply(matrix, drawingSurface.Position.Matrix);
            IDisposable savePosition = drawingSurface.SavePosition();
            drawingSurface.Position = new Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition(matrix);
            return savePosition;
        }
示例#39
0
        private void CreatePageWithImage(RadFixedDocument document, string imageExtension, EncodedImageData imageData)
        {
            RadFixedPage page = document.Pages.AddPage();
            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);
            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();
            block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(string.Format("This is {0} image in {1} color space encoded with {2} filter.", imageExtension, imageData.ColorSpace, imageData.Filters.FirstOrDefault() ?? "None"));
            Size blockSize = block.Measure(RemainingPageSize);
            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 50);

            Block imageBlock = new Block();
            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(new ImageSource(imageData), new Size(imageData.Width, imageData.Height));
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
示例#40
0
        internal static IDisposable SaveClip(FixedContentEditor drawingSurface, UIElement element)
        {
            Geometry clip = null;
            FrameworkElement frameworkElement = element as FrameworkElement;
            if (frameworkElement != null)
            {
                clip = System.Windows.Controls.Primitives.LayoutInformation.GetLayoutClip(frameworkElement);
            }            
            if (clip == null)
            {
                clip = element.Clip;
            }

            RectangleGeometry rectangleClip = clip as RectangleGeometry;
            if (rectangleClip == null)
            {
                return null;
            }

            PathGeometry geometry = MathHelper.TransformRectangle(drawingSurface.Position.Matrix, rectangleClip.Rect);
            var pdfGeometry = PdfGeometryHelper.ConvertPathGeometry(geometry);
            return drawingSurface.PushClipping(pdfGeometry);
        }
        private void DrawFunnelFigure(FixedContentEditor editor)
        {
            editor.GraphicProperties.IsStroked = false;
            editor.GraphicProperties.FillColor = new RgbColor(231, 238, 247);
            editor.DrawEllipse(new Point(250, 70), 136, 48);

            editor.GraphicProperties.IsStroked = true;
            editor.GraphicProperties.StrokeColor = RgbColors.White;
            editor.GraphicProperties.StrokeThickness = 1;
            editor.GraphicProperties.FillColor = new RgbColor(91, 155, 223);
            editor.DrawEllipse(new Point(289, 77), 48, 48);

            editor.Position.Translate(291, 204);
            CenterText(editor, "Fonts");

            editor.Position.Translate(0, 0);
            editor.DrawEllipse(new Point(238, 274), 48, 48);
            editor.Position.Translate(190, 226);
            CenterText(editor, "Images");

            editor.Position.Translate(0, 0);
            editor.DrawEllipse(new Point(307, 347), 48, 48);
            editor.Position.Translate(259, 299);
            CenterText(editor, "Shapes");

            editor.Position.Translate(0, 0);
            PathGeometry arrow = new PathGeometry();
            PathFigure figure = arrow.Figures.AddPathFigure();
            figure.StartPoint = new Point(287, 422);
            figure.IsClosed = true;
            figure.Segments.AddLineSegment(new Point(287, 438));
            figure.Segments.AddLineSegment(new Point(278, 438));
            figure.Segments.AddLineSegment(new Point(300, 454));
            figure.Segments.AddLineSegment(new Point(322, 438));
            figure.Segments.AddLineSegment(new Point(313, 438));
            figure.Segments.AddLineSegment(new Point(313, 422));

            editor.DrawPath(arrow);

            editor.GraphicProperties.FillColor = new RgbColor(80, 255, 255, 255);
            editor.GraphicProperties.IsStroked = true;
            editor.GraphicProperties.StrokeThickness = 1;
            editor.GraphicProperties.StrokeColor = new RgbColor(91, 155, 223);

            PathGeometry funnel = new PathGeometry();
            funnel.FillRule = FillRule.EvenOdd;
            figure = funnel.Figures.AddPathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point(164, 245);
            figure.Segments.AddArcSegment(new Point(436, 245), 136, 48);
            figure.Segments.AddArcSegment(new Point(164, 245), 136, 48);

            figure = funnel.Figures.AddPathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point(151, 245);
            figure.Segments.AddArcSegment(new Point(449, 245), 149, 61);
            figure.Segments.AddLineSegment(new Point(332, 415)); figure.Segments.AddArcSegment(new Point(268, 415), 16, 4);

            editor.DrawPath(funnel);

            editor.Position.Translate(164, 455);
            Block block = new Block();
            block.TextProperties.Font = editor.TextProperties.Font;
            block.GraphicProperties.FillColor = RgbColors.Black;
            block.HorizontalAlignment = HorizontalAlignment.Center;
            block.VerticalAlignment = VerticalAlignment.Top;
            block.TextProperties.FontSize = 18;
            block.InsertText("PDF");
            editor.DrawBlock(block, new Size(272, double.PositiveInfinity));
        }
        private void DrawDescription(FixedContentEditor editor, double maxWidth)
        {
            Block block = new Block();
            block.GraphicProperties.FillColor = RgbColors.Black;
            block.HorizontalAlignment = HorizontalAlignment.Left;
            block.TextProperties.FontSize = 14;
            block.TextProperties.TrySetFont(new FontFamily("Calibri"), FontStyles.Italic, FontWeights.Bold);
            block.InsertText("RadPdfProcessing");
            block.TextProperties.TrySetFont(new System.Windows.Media.FontFamily("Calibri"));
            block.InsertText(" is a document processing library that enables your application to import and export files to and from PDF format. The document model is entirely independent from UI and allows you to generate sleek documents with differently formatted text, images, shapes and more.");

            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));
        }
        private void DrawText(FixedContentEditor editor, double maxWidth)
        {
            double currentTopOffset = 470;
            currentTopOffset += defaultLineHeight * 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.TextProperties.FontSize = 11;

            Block block = new Block();
            block.TextProperties.FontSize = 11;
            block.TextProperties.TrySetFont(new FontFamily("Arial"));
            block.InsertText("A wizard's job is to vex ");
            using (block.GraphicProperties.Save())
            {
                block.GraphicProperties.FillColor = new RgbColor(255, 146, 208, 80);
                block.InsertText("chumps");
            }

            block.InsertText(" quickly in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);

            block = new Block();
            block.TextProperties.FontSize = 11;
            block.TextProperties.TrySetFont(new FontFamily("Trebuchet MS"));
            block.InsertText("A wizard's job is to vex chumps ");
            using (block.TextProperties.Save())
            {
                block.TextProperties.UnderlinePattern = UnderlinePattern.Single;
                block.TextProperties.UnderlineColor = editor.GraphicProperties.FillColor;
                block.InsertText("quickly");
            }

            block.InsertText(" in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            block = new Block();
            block.TextProperties.FontSize = 11;
            block.TextProperties.TrySetFont(new FontFamily("Algerian"));
            block.InsertText("A ");
            using (block.TextProperties.Save())
            {
                block.TextProperties.UnderlinePattern = UnderlinePattern.Single;
                block.TextProperties.UnderlineColor = editor.GraphicProperties.FillColor;
                block.InsertText("wizard's");
            }

            block.InsertText(" job is to vex chumps quickly in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);

            editor.TextProperties.TrySetFont(new FontFamily("Lucida Calligraphy"));
            editor.DrawText("A wizard's job is to vex chumps quickly in fog.", new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight + 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            block = new Block();
            block.TextProperties.FontSize = 11;
            block.TextProperties.TrySetFont(new FontFamily("Consolas"));
            block.InsertText("A wizard's job is to vex chumps ");
            using (block.TextProperties.Save())
            {
                block.TextProperties.TrySetFont(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Bold);
                block.InsertText("quickly");
            }

            block.InsertText(" in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.TextProperties.TrySetFont(new FontFamily("Arial"));
            editor.DrawText("Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός.", new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.DrawText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.DrawText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío; añoraba a su querido cachorro.", new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);

            editor.TextProperties.TrySetFont(new FontFamily("Malgun Gothic"));
            editor.DrawText("키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다.", new Size(maxWidth, double.PositiveInfinity));
        }
        private static void DrawCenteredText(FixedContentEditor editor, string text, Size size)
        {
            Block block = new Block();

            block.TextProperties.TrySetFont(new FontFamily("Arial"));
            block.HorizontalAlignment = HorizontalAlignment.Center;
            block.VerticalAlignment = VerticalAlignment.Center;
            block.GraphicProperties.FillColor = RgbColors.White;
            block.TextProperties.FontSize = 16;
            block.InsertText(text);

            editor.DrawBlock(block, size);
        }
        private static Tiling CreateTiling(double offsetX, double offsetY, double width, SimpleColor color)
        {
            Tiling tiling = new Tiling(new Rect(0, 0, width, 2));
            tiling.Position.Translate(offsetX, offsetY);
            var tilingEditor = new FixedContentEditor(tiling);
            tilingEditor.GraphicProperties.IsStroked = false;
            tilingEditor.GraphicProperties.FillColor = color;
            tilingEditor.DrawRectangle(new Rect(0, 0, width, 1));
            LinearGradient gradient = new LinearGradient(new Point(0, 0), new Point(width, 0));
            gradient.GradientStops.Add(new GradientStop(color, 0));
            gradient.GradientStops.Add(new GradientStop(RgbColors.White, .5));
            gradient.GradientStops.Add(new GradientStop(color, 1));
            tilingEditor.GraphicProperties.FillColor = gradient;
            tilingEditor.DrawRectangle(new Rect(0, 1, width, 1));

            return tiling;
        }
示例#46
0
 private static FixedContentEditor CreateEditor(EditorInfo info, bool isFilled)
 {
     FixedContentEditor geometryEditor = new FixedContentEditor(info.Page, info.Position);
     geometryEditor.GraphicProperties.IsFilled = isFilled;
     geometryEditor.GraphicProperties.FillColor = ColorHelper.GetColor(info.Background, info.Opacity, info.Bounds, info.Angle);
     geometryEditor.GraphicProperties.StrokeColor = ColorHelper.GetColor(info.Stroke, info.Opacity, info.Bounds, info.Angle);
     geometryEditor.GraphicProperties.StrokeDashArray = info.StrokeDashArray;
     geometryEditor.GraphicProperties.StrokeThickness = info.StrokeThickness;
     return geometryEditor;
 }
 private static void DrawBarLine(FixedContentEditor editor, double offsetX, double offsetY, double width)
 {
     editor.GraphicProperties.FillColor = RgbColors.Black;
     editor.GraphicProperties.StrokeThickness = 1;
     editor.GraphicProperties.IsFilled = false;
     editor.GraphicProperties.IsStroked = true;
     editor.DrawLine(new Point(offsetX, offsetY), new Point(offsetX + width, offsetY));
 }
        private void DrawFunnelFigure(FixedContentEditor editor)
        {
            editor.GraphicProperties.IsStroked = false;
            editor.GraphicProperties.FillColor = new RgbColor(231, 238, 247);
            editor.DrawEllipse(new Point(250, 70), 136, 48);

            editor.GraphicProperties.IsStroked = true;
            editor.GraphicProperties.StrokeColor = RgbColors.White;
            editor.GraphicProperties.StrokeThickness = 1;
            editor.GraphicProperties.FillColor = new RgbColor(91, 155, 223);
            editor.DrawEllipse(new Point(289, 77), 48, 48);
            editor.TextProperties.Font = FontsRepository.Helvetica;
            editor.TextProperties.HorizontalAlignment = HorizontalTextAlignment.Center;
            editor.TextProperties.VerticalAlignment = VerticalTextAlignment.Center;
            editor.TextProperties.TextBlockWidth = 96;
            editor.TextProperties.TextBlockHeight = 96;
            using (editor.SaveGraphicProperties())
            {
                editor.Position.Translate(291, 229);
                editor.GraphicProperties.FillColor = RgbColors.White;
                editor.DrawText("Fonts");
            }

            editor.Position.Translate(0, 0);
            editor.DrawEllipse(new Point(238, 299), 48, 48);
            using (editor.SaveGraphicProperties())
            {
                editor.Position.Translate(190, 251);
                editor.GraphicProperties.FillColor = RgbColors.White;
                editor.DrawText("Images");
            }

            editor.Position.Translate(0, 0);
            editor.DrawEllipse(new Point(307, 372), 48, 48);
            using (editor.SaveGraphicProperties())
            {
                editor.Position.Translate(259, 324);
                editor.GraphicProperties.FillColor = RgbColors.White;
                editor.DrawText("Shapes");
            }

            editor.Position.Translate(0, 0);
            PathGeometry arrow = new PathGeometry();
            PathFigure figure = arrow.Figures.AddPathFigure();
            figure.StartPoint = new Point(287, 447);
            figure.IsClosed = true;
            figure.Segments.AddLineSegment(new Point(287, 463));
            figure.Segments.AddLineSegment(new Point(278, 463));
            figure.Segments.AddLineSegment(new Point(300, 479));
            figure.Segments.AddLineSegment(new Point(322, 463));
            figure.Segments.AddLineSegment(new Point(313, 463));
            figure.Segments.AddLineSegment(new Point(313, 447));

            editor.DrawPath(arrow);

            editor.GraphicProperties.FillColor = new RgbColor(80, 255, 255, 255);
            editor.GraphicProperties.IsStroked = true;
            editor.GraphicProperties.StrokeThickness = 1;
            editor.GraphicProperties.StrokeColor = new RgbColor(91, 155, 223);

            PathGeometry funnel = new PathGeometry();
            funnel.FillRule = FillRule.EvenOdd;
            figure = funnel.Figures.AddPathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point(164, 270);
            figure.Segments.AddArcSegment(new Point(436, 270), 136, 48);
            figure.Segments.AddArcSegment(new Point(164, 270), 136, 48);

            figure = funnel.Figures.AddPathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point(151, 270);
            figure.Segments.AddArcSegment(new Point(449, 270), 149, 61);
            figure.Segments.AddLineSegment(new Point(332, 440));
            figure.Segments.AddArcSegment(new Point(268, 440), 16, 4);

            editor.DrawPath(funnel);

            using (editor.SaveGraphicProperties())
            {
                using (editor.SaveTextProperties())
                {
                    editor.Position.Translate(164, 484);
                    editor.GraphicProperties.FillColor = RgbColors.Black;
                    editor.TextProperties.HorizontalAlignment = HorizontalTextAlignment.Center;
                    editor.TextProperties.VerticalAlignment = VerticalTextAlignment.Top;
                    editor.TextProperties.TextBlockWidth = 272;
                    editor.TextProperties.FontSize = 18;
                    editor.DrawText("PDF");
                }
            }
        }
        private void DrawText(FixedContentEditor editor, double maxWidth)
        {
            double currentTopOffset = 500;
            currentTopOffset += defaultLineHeight * 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            Block block = new Block();
            block.TextProperties.Font = FontsRepository.Helvetica;
            block.InsertText("A wizard's job is to vex ");
            using (block.GraphicProperties.Save())
            {
                block.GraphicProperties.FillColor = new RgbColor(255, 146, 208, 80);
                block.InsertText("chumps");
            }

            block.InsertText(" quickly in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            block = new Block();
            block.TextProperties.Font = FontsRepository.TimesRoman;
            block.InsertText("A wizard's job is to vex chumps ");
            using (block.TextProperties.Save())
            {
                block.TextProperties.UnderlinePattern = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.UnderlinePattern.Single;
                block.TextProperties.UnderlineColor = editor.GraphicProperties.FillColor;
                block.InsertText("quickly");
            }

            block.InsertText(" in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            block = new Block();
            block.TextProperties.Font = FontsRepository.Courier;
            block.InsertText("A ");
            using (block.TextProperties.Save())
            {
                block.TextProperties.Font = FontsRepository.CourierBoldOblique;
                block.TextProperties.UnderlinePattern = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.UnderlinePattern.Single;
                block.TextProperties.UnderlineColor = editor.GraphicProperties.FillColor;
                block.InsertText("wizard's");
            }

            block.InsertText(" job is to vex chumps quickly in fog.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));
        }
示例#50
0
        private void AddPageWithImage(string description, ImageSource imageSource)
        {
            RadFixedPage page = this.document.Pages.AddPage();
            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);
            editor.GraphicProperties.FillColor = new RgbColor(200, 200, 200);
            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();
            block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(description);
            Size blockSize = block.Measure(RemainingPageSize);
            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 20);

            Block imageBlock = new Block();
            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
        private void DrawChartFrame(double leftMargin, FixedContentEditor editor, out double offsetX, out double offsetY)
        {
            offsetX = leftMargin;
            offsetY = marginTop;
            editor.DrawRectangle(new Rect(offsetX, offsetY, chartWidth, chartHeight));
            offsetY += 10;
            editor.Position.Translate(offsetX, offsetY);

            editor.TextProperties.FontSize = 18;
            editor.TextProperties.TrySetFont(new System.Windows.Media.FontFamily("Calibri"), FontStyles.Normal, FontWeights.Bold);
            DrawText(editor, "2013", chartWidth, HorizontalAlignment.Center);

            offsetY += 30;
            editor.Position.Translate(offsetX, offsetY);

            editor.TextProperties.TrySetFont(new System.Windows.Media.FontFamily("Calibri"));
            editor.TextProperties.FontSize = 10;
            editor.GraphicProperties.IsFilled = true;
            editor.GraphicProperties.IsStroked = false;
        }
        private void DrawText(FixedContentEditor editor)
        {
            double currentTopOffset = 500;
            currentTopOffset += defaultLineHeight * 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.Font = FontsRepository.Helvetica;
                editor.DrawText("A wizard's job is to vex ");
                using (editor.SaveGraphicProperties())
                {
                    editor.GraphicProperties.FillColor = new RgbColor(255, 146, 208, 80);
                    editor.DrawText("chumps");
                }
                editor.DrawText(" quickly in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.Font = FontsRepository.TimesRoman;
                editor.DrawText("A wizard's job is to vex chumps ");
                using (editor.SaveTextProperties())
                {
                    editor.TextProperties.TextDecoration = Telerik.Windows.Documents.Fixed.Model.Text.TextDecorations.Underline;
                    editor.DrawText("quickly");
                }
                editor.DrawText(" in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.Font = FontsRepository.Courier;
                editor.DrawText("A ");
                using (editor.SaveTextProperties())
                {
                    editor.TextProperties.Font = FontsRepository.CourierBoldOblique;
                    editor.TextProperties.TextDecoration = Telerik.Windows.Documents.Fixed.Model.Text.TextDecorations.Underline;
                    editor.DrawText("wizard's");
                }
                editor.DrawText(" job is to vex chumps quickly in fog.");
            }
        }
 private void DrawDescription(FixedContentEditor editor, double maxWidth)
 {
     editor.GraphicProperties.FillColor = RgbColors.Black;
     editor.TextProperties.HorizontalAlignment = HorizontalTextAlignment.Left;
     editor.TextProperties.TextBlockWidth = maxWidth;
     using (editor.BeginText())
     {
         editor.TextProperties.Font = FontsRepository.HelveticaBoldOblique;
         editor.DrawText("RadPdfProcessing");
         editor.TextProperties.Font = FontsRepository.Helvetica;
         editor.DrawText(" is a document processing library that enables your application to import and export files to and from PDF format. The document model is entirely independent from UI and allows you to generate sleek documents with differently formatted text, images, shapes and more.");
     }
 }
示例#54
0
        private static void ExportContent(ContentControl control, Rect bounds, double angle, RadFixedPage page, Func<Size, Point> positionFunc, string contentString = null)
        {
            string text = contentString ?? control.Content.ToString();
            if (string.IsNullOrWhiteSpace(text)) return;
            FixedContentEditor textEditor = new FixedContentEditor(page);
            var block = new Block();

            // Set the text and graphic properties.
            block.TextProperties.FontSize = control.FontSize;
            block.TextProperties.RenderingMode = RenderingMode.Fill;
            block.TextProperties.TrySetFont(control.FontFamily, control.FontStyle, control.FontWeight);
            block.GraphicProperties.FillColor = ColorHelper.GetColor(control.Foreground, control.Opacity, bounds);
            block.GraphicProperties.StrokeColor = block.GraphicProperties.FillColor;

            // Measure the text.
            block.InsertText(text);
            var boundsSize = bounds.ToSize();
            var availableSize = new Size(boundsSize.Width - control.Padding.Left - control.Padding.Right, boundsSize.Width - control.Padding.Top - control.Padding.Bottom);
            var textSize = block.Measure(availableSize);
            var position = positionFunc(textSize);
            var textGroup = new TransformGroup();
            textGroup.Children.Add(new RotateTransform() { Angle = angle, CenterX = textSize.Width / 2, CenterY = textSize.Height / 2 });
            textGroup.Children.Add(new TranslateTransform() { X = position.X, Y = position.Y });
            textEditor.Position = new MatrixPosition(textGroup.Value);

            textEditor.DrawBlock(block, availableSize);
        }
        private void DrawText(FixedContentEditor editor, double maxWidth)
        {
            double currentTopOffset = 470;
            currentTopOffset += defaultLineHeight * 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.TextProperties.FontSize = 11;
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Arial"));
                editor.DrawText("A wizard's job is to vex ");
                using (editor.SaveGraphicProperties())
                {
                    editor.GraphicProperties.FillColor = new RgbColor(255, 146, 208, 80);
                    editor.DrawText("chumps");
                }
                editor.DrawText(" quickly in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Trebuchet MS"));
                editor.DrawText("A wizard's job is to vex chumps ");
                using (editor.SaveTextProperties())
                {
                    editor.TextProperties.TextDecoration = Telerik.Windows.Documents.Fixed.Model.Text.TextDecorations.Underline;
                    editor.DrawText("quickly");
                }
                editor.DrawText(" in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Algerian"));
                editor.DrawText("A ");
                using (editor.SaveTextProperties())
                {
                    editor.TextProperties.TextDecoration = Telerik.Windows.Documents.Fixed.Model.Text.TextDecorations.Underline;
                    editor.DrawText("wizard's");
                }
                editor.DrawText(" job is to vex chumps quickly in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Lucida Calligraphy"));
                editor.DrawText("A wizard's job is to vex chumps quickly in fog.");
            }

            currentTopOffset += defaultLineHeight + 2;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Consolas"));
                editor.DrawText("A wizard's job is to vex chumps ");
                using (editor.SaveTextProperties())
                {
                    editor.TextProperties.TrySetFont(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Bold);
                    editor.DrawText("quickly");
                }
                editor.DrawText(" in fog.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Arial"));
                editor.DrawText("Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            using (editor.BeginText())
            {
                editor.DrawText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);
            editor.TextProperties.TextBlockWidth = maxWidth;
            using (editor.BeginText())
            {
                editor.DrawText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío; añoraba a su querido cachorro.");
            }

            currentTopOffset += defaultLineHeight;
            editor.Position.Translate(defaultLeftIndent, currentTopOffset);

            using (editor.BeginText())
            {
                editor.TextProperties.TrySetFont(new FontFamily("Malgun Gothic"));
                editor.DrawText("키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다.");
            }
        }
        private static Block CreateBlock(FixedContentEditor editor)
        {
            Block block = new Block();
            block.TextProperties.CopyFrom(editor.TextProperties);
            block.GraphicProperties.CopyFrom(editor.GraphicProperties);

            return block;
        }
示例#57
0
 public static void ExportToPdf(UIElement element, FixedContentEditor drawingSurface)
 {
     pdfRenderer.Render(element, drawingSurface);
 }
示例#58
0
        private static void ExportGeometry(FixedContentEditor editor, FixedContentEditor filledEditor, Geometry geometry, bool isConnection = false)
        {
            // We need two editors because there might be filled and not filled figures.
#if WPF
            var pathGeometry = geometry as PathGeometry;
#else
            var pathGeometry = GeometryParser.GetGeometry(geometry.ToString()) as PathGeometry;
#endif
            if (pathGeometry != null)
            {
                var path = new G.PathGeometry();
                var filledPath = new G.PathGeometry();
                for (int i = 0; i < pathGeometry.Figures.Count; i++)
                {
                    var figure = pathGeometry.Figures[i];
                    var newFigure = new G.PathFigure();
                    newFigure.StartPoint = figure.StartPoint;
                    newFigure.IsClosed = figure.IsClosed;
                    foreach (var segment in figure.Segments)
                    {
                        var arc = segment as ArcSegment;
                        if (arc != null)
                        {
                            var newS = new G.ArcSegment();
                            newS.Point = arc.Point;
                            newS.RadiusX = arc.Size.Width;
                            newS.RadiusY = arc.Size.Height;
                            newS.RotationAngle = arc.RotationAngle;
                            // why new enum ?
                            if (arc.SweepDirection == SweepDirection.Clockwise)
                                newS.SweepDirection = G.SweepDirection.Clockwise;
                            else
                                newS.SweepDirection = G.SweepDirection.Counterclockwise;
                            newS.IsLargeArc = arc.IsLargeArc;
                            newFigure.Segments.Add(newS);
                            continue;
                        }

                        var bezier = segment as BezierSegment;
                        if (bezier != null)
                        {
                            var newS = new G.BezierSegment();
                            newS.Point1 = bezier.Point1;
                            newS.Point2 = bezier.Point2;
                            newS.Point3 = bezier.Point3;
                            newFigure.StartPoint = newFigure.StartPoint;
                            newFigure.Segments.Add(newS);
                            continue;
                        }

                        var polyLine = segment as PolyLineSegment;
                        if (polyLine != null)
                        {
                            foreach (var point in polyLine.Points)
                            {
                                var newS = new G.LineSegment();
                                newS.Point = point;
                                newFigure.Segments.Add(newS);
                            }
                            continue;
                        }

                        var line = segment as LineSegment;
                        if (line != null)
                        {
                            var newS = new G.LineSegment();
                            newS.Point = line.Point;
                            newFigure.Segments.Add(newS);
                            continue;
                        }

                        var quadraticBezier = segment as QuadraticBezierSegment;
                        if (quadraticBezier != null)
                        {
                            var newS = new G.QuadraticBezierSegment();
                            newS.Point1 = quadraticBezier.Point1;
                            newS.Point2 = quadraticBezier.Point2;
                            newFigure.Segments.Add(newS);
                            continue;
                        }
                    }
#if SILVERLIGHT
                    if (isConnection)
                    {
                        var realGeometry = geometry as PathGeometry;
                        if (realGeometry != null && realGeometry.Figures.Count > i)
                        {
                            if (realGeometry.Figures[i].IsFilled)
                                filledPath.Figures.Add(newFigure);
                            else
                                path.Figures.Add(newFigure);
                            continue;
                        }
                    }
#endif
                    if (figure.IsFilled)
                        filledPath.Figures.Add(newFigure);
                    else
                        path.Figures.Add(newFigure);
                }

                // why new enum ?
                if (pathGeometry.FillRule == FillRule.EvenOdd)
                {
                    path.FillRule = G.FillRule.EvenOdd;
                    filledPath.FillRule = G.FillRule.EvenOdd;
                }
                else
                {
                    path.FillRule = G.FillRule.Nonzero;
                    filledPath.FillRule = G.FillRule.Nonzero;
                }

                if (filledPath.Figures.Count > 0)
                    filledEditor.DrawPath(filledPath);
                if (path.Figures.Count > 0)
                    editor.DrawPath(path);
            }
        }
示例#59
0
 internal PdfRenderContext(FixedContentEditor drawingSurface, PdfRenderer facade)
 {
     this.drawingSurface = drawingSurface;
     this.facade = facade;
     this.opacity = 1;
 }
        private void DrawDescription(FixedContentEditor editor, double maxWidth)
        {
            Block block = new Block();
            block.GraphicProperties.FillColor = RgbColors.Black;
            block.HorizontalAlignment = HorizontalAlignment.Left;
            block.TextProperties.Font = FontsRepository.HelveticaBoldOblique;
            block.InsertText("RadPdfProcessing");
            block.TextProperties.Font = FontsRepository.Helvetica;
            block.InsertText(" is a document processing library that enables your application to import and export files to and from PDF format. The document model is entirely independent from UI and allows you to generate sleek documents with differently formatted text, images, shapes and more.");

            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));
        }