/// <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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
        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);
        }
Пример #5
0
        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);
        }
        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 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));
        }
Пример #8
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));
                }
            }
        }
 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));
 }
Пример #10
0
        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 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));
        }
Пример #12
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));
        }
Пример #13
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));
        }
Пример #14
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 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));
        }
Пример #16
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);
        }
        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 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));
        }
Пример #19
0
        private void SetPageFooter(FixedContentEditor editor)
        {
            Block block = new Block();

            this.SetTextProperties(block, new RgbColor(0, 0, 0), 22, FontsRepository.TimesItalic);
            block.InsertText("Powered by Jeffrey");
            if (FooterSize == Size.Empty)
            {
                FooterSize = block.Measure();
            }

            editor.Position.Translate(PageWidth - FooterSize.Width - offset, PageHeight - FooterSize.Height - offset);
            editor.DrawBlock(block, new Size(PageWidth, PageHeight));
        }
Пример #20
0
        private void SetPageHeader(FixedContentEditor editor)
        {
            Block block = new Block();

            this.SetTextProperties(block, new RgbColor(0, 0, 0), 30, FontsRepository.TimesBold);
            block.InsertText("四则运算习题册");
            if (HeaderSize == Size.Empty)
            {
                HeaderSize = block.Measure();
            }

            editor.Position.Translate((PageWidth - HeaderSize.Width) / 2, offset);
            editor.DrawBlock(block, new Size(PageWidth, PageHeight));
        }
        private static void Footer(FixedContentEditor editor, double maxWidth)
        {
            Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = new Telerik.Windows.Documents.Flow.Model.RadFlowDocument();
            document.Sections.AddSection();

            document.Sections.First().Footers.Add();
            document.Sections.First().Footers.Add(Telerik.Windows.Documents.Flow.Model.HeaderFooterType.First);
            document.Sections.First().Footers.Add(Telerik.Windows.Documents.Flow.Model.HeaderFooterType.Even);

            double WriteWhere = 650;

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

            Block block = new Block();

            block.TextProperties.Font     = FontsRepository.TimesRoman;
            block.TextProperties.FontSize = 10;
            block.InsertText("Certificate of Conformance Statement");

            editor.DrawBlock(block);

            WriteWhere += AnchoDeLinea * 1.5;                       //Salto de linea al editor
            editor.Position.Translate(MargenIzquierdo, WriteWhere); //Traslada el editor al nuevo punto de escritura

            block = new Block();
            block.TextProperties.FontSize = 10;
            block.InsertText(new FontFamily("Calibri"), "We hereby certify that all products listed above have been produced, assembled, inspected, and tested in full accordance with all specifications, drawings, and quality requirements.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));

            WriteWhere += AnchoDeLinea * 3;                         //Salto de linea al editor
            editor.Position.Translate(MargenIzquierdo, WriteWhere); //Traslada el editor al nuevo punto de escritura

            block = new Block();
            block.TextProperties.FontSize = 10;
            block.InsertText(new FontFamily("Calibri"), "Certificamos por este medio todos los productos arriba mencionados se han producido, ensamblado, examinados, y probados de acuerdo a todas las especificaciones, dibujos, y requisitos de calidad.");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));
        }
Пример #22
0
        private double AddEmployeeNameToPage(FixedContentEditor editor, double width)
        {
            Block block = new Block();

            block.GraphicProperties.FillColor = new RgbColor(0, 0, 255);
            block.HorizontalAlignment         = (Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment)HorizontalAlignment.Left;
            block.TextProperties.FontSize     = 30;
            block.TextProperties.TrySetFont(new FontFamily("Calibri"), FontStyles.Italic, FontWeights.Bold);
            block.InsertText(SelectedEmployee.FullName);


            editor.DrawBlock(block, new Size(width, double.PositiveInfinity));
            Size size = block.Measure();

            return(size.Height);
        }
Пример #23
0
        private static void AddWatermarkText(RadFixedPage page, string text, byte transparency)
        {
            FixedContentEditor editor = new FixedContentEditor(page);

            Block block = new Block();

            block.TextProperties.FontSize = 80;
            block.TextProperties.TrySetFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold);
            block.HorizontalAlignment         = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.GraphicProperties.FillColor = new RgbColor(transparency, 255, 0, 0);
            block.InsertText(text);

            double angle = -45;

            editor.Position.Rotate(angle);
            editor.Position.Translate(0, page.Size.Width);
            editor.DrawBlock(block, new Size(page.Size.Width / Math.Abs(Math.Sin(angle)), double.MaxValue));
        }
Пример #24
0
        private static void DrawNextWidgetWithDescription(FixedContentEditor editor, string description, Action <FixedContentEditor> drawWidgetWithEditor)
        {
            double padding = 20;

            drawWidgetWithEditor(editor);

            Size   annotationSize = editor.Root.Annotations[editor.Root.Annotations.Count - 1].Rect.Size;
            double x = editor.Position.Matrix.OffsetX;
            double y = editor.Position.Matrix.OffsetY;

            Block block = new Block();

            block.TextProperties.FontSize = 20;
            block.VerticalAlignment       = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.VerticalAlignment.Center;
            block.InsertText(description);
            editor.Position.Translate(x + annotationSize.Width + padding, y);
            editor.DrawBlock(block, new Size(editor.Root.Size.Width, annotationSize.Height));

            editor.Position.Translate(x, y + annotationSize.Height + padding);
        }
Пример #25
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);
        }
Пример #26
0
        private static RadFixedPage GenerateForegroundTextContent(string text)
        {
            Block block = new Block();

            block.BackgroundColor             = new RgbColor(50, 0, 0, 0);
            block.GraphicProperties.FillColor = new RgbColor(255, 0, 0);
            block.TextProperties.FontSize     = 120;
            block.InsertText(text);
            Size   horizontalTextSize    = block.Measure();
            double rotatedTextSquareSize = (horizontalTextSize.Width + horizontalTextSize.Height) / Math.Sqrt(2);

            RadFixedPage foregroundContentOwner = new RadFixedPage();

            foregroundContentOwner.Size = new Size(rotatedTextSquareSize, rotatedTextSquareSize);
            FixedContentEditor foregroundEditor = new FixedContentEditor(foregroundContentOwner);

            foregroundEditor.Position.Translate(horizontalTextSize.Height / Math.Sqrt(2), 0);
            foregroundEditor.Position.Rotate(45);
            foregroundEditor.DrawBlock(block);

            return(foregroundContentOwner);
        }
Пример #27
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);
        }
Пример #28
0
        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 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 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 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 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));
        }
Пример #33
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 DrawBarChartContent(FixedContentEditor editor)
        {
            editor.GraphicProperties.IsFilled = false;
            this.DrawCompanyLogo(editor);

            double leftMargin = this.GetLeftMargin(editor.Root.Size.Width);
            double offsetX;
            double offsetY;

            this.DrawChartFrame(leftMargin, editor, out offsetX, out offsetY);

            double offset = 20;
            double textWidth = 0;
            double rectMargin = 2;

            for (int i = 0; i < this.ExportedProductsCount; i++)
            {
                textWidth += rectSize + rectMargin + offset;
                textWidth += MeasureText(editor, this.products[i].Name).Width;
            }

            offsetX = leftMargin + ((chartWidth - textWidth) / 2);
            offsetY += 20;
            for (int i = 0; i < this.ExportedProductsCount; i++)
            {
                editor.Position.Translate(offsetX, offsetY);
                Tiling tiling = CreateTiling(offsetX, offsetY, rectSize, colors[i]);

                Block block = new Block();
                block.GraphicProperties.FillColor = tiling;
                block.GraphicProperties.IsStroked = false;
                block.InsertRectangle(new Rect(0, 0, rectSize, rectSize));
                block.GraphicProperties.FillColor = RgbColors.Black;
                block.InsertText(" " + this.products[i].Name);
                editor.DrawBlock(block);
                offsetX += block.DesiredSize.Width + offset;
            }

            offsetX = leftMargin;

            offsetY += 30;
            double markerHeight = (chartHeight - (offsetY - marginTop)) / markersCount;
            editor.Position.Translate(offsetX, offsetY);

            for (int i = markersCount - 1; i >= 0; i--)
            {
                DrawText(editor, string.Format("{0:C}", i * this.StepValue), markerAreaWidth, HorizontalAlignment.Right);
                if (i > 0)
                {
                    offsetY += markerHeight;
                    editor.Position.Translate(offsetX, offsetY);
                }
            }

            offsetX = leftMargin + markerAreaWidth + valuesMargin;
            double center = MeasureText(editor, "X").Height / 2;
            offsetY += center;
            double valueHeight = markerHeight / this.StepValue;
            double dataAreaWidth = chartWidth - markerAreaWidth - 2 * valuesMargin;

            double sectionWidth = dataAreaWidth / this.GetQuartersToExportCount();
            double barWidth = (sectionWidth - 2 * valuesMargin - 2 * this.ExportedProductsCount * barMargin) / this.ExportedProductsCount;
            for (int j = 0; j < this.quartersToExport.Keys.Count; j++)
            {
                if (!this.quartersToExport[j])
                {
                    continue;
                }

                editor.Position.Translate(offsetX, offsetY + 5);
                editor.GraphicProperties.FillColor = RgbColors.Black;
                DrawText(editor, string.Format("Q{0}", j + 1), sectionWidth, HorizontalAlignment.Center);
                editor.Position.Translate(0, 0);
                offsetX += valuesMargin;
                for (int i = 0; i < this.ExportedProductsCount; i++)
                {
                    Product product = this.products[i];
                    double h = product.Q[j] * valueHeight;
                    offsetX += barMargin;
                    Tiling tiling = CreateTiling(offsetX, offsetY - h, barWidth, colors[i]);
                    editor.GraphicProperties.FillColor = tiling;
                    editor.DrawRectangle(new Rect(offsetX, offsetY - h, barWidth, h));
                    offsetX += barWidth + barMargin;
                }

                offsetX += valuesMargin;
            }

            offsetX = leftMargin + markerAreaWidth + valuesMargin;
            DrawBarLine(editor, offsetX, offsetY, dataAreaWidth);
        }
Пример #35
0
        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));
        }
Пример #36
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);
        }
Пример #37
0
        public static void DrawText(FixedContentEditor editor, double maxWidth, MyPdfContent content)
        {
            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.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);

            // TO VERIFY CONTENT WAS UPLOADED THIS IS THE PASSED TEXT
            editor.DrawText(content.Body, new Size(maxWidth, double.PositiveInfinity));
        }
Пример #38
0
        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));
        }
Пример #39
0
        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 async void ExportButton_OnClicked(object sender, EventArgs e)
        {
            BusyIndicator.IsVisible = BusyIndicator.IsBusy = true;

            var success = await Task.Run(async() =>
            {
                try
                {
                    var imageBytes = await FileExtensions.LoadFileBytesAsync(App.EditedImageFilePath);

                    using (var jpegStream = new MemoryStream(imageBytes))
                    {
                        // Define page dimensions
                        var pageSize          = new Telerik.Documents.Primitives.Size(Telerik.Windows.Documents.Media.Unit.MmToDip(210), Telerik.Windows.Documents.Media.Unit.MmToDip(297));
                        var pageMargins       = new Telerik.Documents.Primitives.Thickness(Telerik.Windows.Documents.Media.Unit.MmToDip(10));
                        var remainingPageSize = new Telerik.Documents.Primitives.Size(pageSize.Width - pageMargins.Left - pageMargins.Right, pageSize.Height - pageMargins.Top - pageMargins.Bottom);

                        // Create in memory document
                        // 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;
                        editor.GraphicProperties.FillColor       = new RgbColor(255, 255, 255);
                        editor.DrawRectangle(new Rect(0, 0, pageSize.Width, pageSize.Height));
                        editor.Position.Translate(pageMargins.Left, pageMargins.Top);

                        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("Generated in Xamarin.Forms!");

                        var blockSize = block.Measure(remainingPageSize);
                        editor.DrawBlock(block, remainingPageSize);

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

                        // Create image that can be inserted into document using the jpeg's stream
                        // !Note - Image is of type Telerik.Windows.Documents.Fixed.Model.Objects.Image
                        var docImageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(jpegStream);

                        // Draw the image into the document
                        var imageBlock = new Block();
                        imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
                        imageBlock.InsertImage(docImageSource);
                        editor.DrawBlock(imageBlock, remainingPageSize);

                        // Export the document to Pdf
                        var provider = new PdfFormatProvider();

                        if (File.Exists(App.PdfFilePath))
                        {
                            File.Delete(App.PdfFilePath);
                        }

                        using (var fileStream = File.OpenWrite(App.PdfFilePath))
                        {
                            provider.Export(document, fileStream);
                        }

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Device.BeginInvokeOnMainThread(() => DisplayAlert("Error", ex.Message, "ok"));

                    return(false);
                }
            });

            BusyIndicator.IsVisible = BusyIndicator.IsBusy = false;

            if (success)
            {
                await Navigation.PushAsync(new DocumentViewerPage());
            }
        }
        private static void DrawData(FixedContentEditor editor, double maxWidth, decimal ParametroFedex)
        {
            EnsamblesRealizadosService      _ServiceER = new EnsamblesRealizadosService();
            MaterialShippingControlEntities BD         = new MaterialShippingControlEntities();
            double WriteWhere = 160;   //Define el actual tope del editor

            Block block = new Block(); //Declara un nuevo bloque

            //SaltoLinea

            editor.Position.Translate(MargenIzquierdo, WriteWhere);//Mueve ele editor

            using (block.SaveTextProperties())
            {
                block.TextProperties.Font = FontsRepository.CourierBold;
                block.InsertText(new FontFamily("Calibri"), "FEDEX TRACKING: ");
            }
            block.InsertText(new FontFamily("Calibri"), ParametroFedex.ToString());
            editor.DrawBlock(block);

            //SaltoLinea
            WriteWhere += AnchoDeLinea * 2;                         //Salto de linea al editor
            editor.Position.Translate(MargenIzquierdo, WriteWhere); //Mueve ele editor

            block = new Block();                                    //Declara un nuevo bloque
            using (block.SaveTextProperties()){
                block.InsertText(new FontFamily("Calibri"), "REFERENCE: ");
            }
            block.InsertText(new FontFamily("Calibri"), _ServiceER.ReadE(ParametroFedex));
            editor.DrawBlock(block);

            //SaltoLinea
            block       = new Block();                              //Declara un nuevo bloque
            WriteWhere += AnchoDeLinea * 3;                         //Salto de linea al editor
            editor.Position.Translate(MargenIzquierdo, WriteWhere); //Mueve ele editor
            block.InsertText("FINISH PRODUCT: SHIPMENTS TO THE UNITED STATES PACKING LIST");
            block.TextProperties.Font     = FontsRepository.Helvetica;
            block.TextProperties.FontSize = 11;
            editor.DrawBlock(block);

            WriteWhere += AnchoDeLinea * 2;                                            //Salto de linea al editor
            editor.Position.Translate(50, WriteWhere);                                 //Mueve ele editor

            RgbColor headerColor         = new RgbColor(196, 196, 196);                //Color de Header
            RgbColor bordersColor        = new RgbColor(255, 255, 255);                //Color de los bordes
            RgbColor alternatingRowColor = new RgbColor(224, 224, 224);                //Color de rows
            Border   border = new Border(1, Editing.BorderStyle.Single, bordersColor); //Estilo de borde

            Table table = new Table
            {
                Borders    = new TableBorders(border),                                                  //A la propiedad borders de la tabla se le agrega el estilo de borde creado
                LayoutType = TableLayoutType.FixedWidth                                                 //Tipo de dise;o
            };                                                                                          //Nuevo objeto tabla

            table.DefaultCellProperties.Borders = new TableCellBorders(border, border, border, border); //Bordes de la tabla se les da las propiedades del objeto borde
            table.DefaultCellProperties.Padding = new System.Windows.Thickness(2);                      //Padding de tabla

            TableRow NewFila = table.Rows.AddTableRow();                                                //Nuevo objeto TableRow se anade a la tabla

            /////////////////////////////////////////////////////////////////////Contenido de la tabla///////////////////////////////////////////

            TableCell ObjetoCelda = NewFila.Cells.AddTableCell();//Objeto TableCell se anade a la tabla como fila

            ObjetoCelda.PreferredWidth = 100;
            ObjetoCelda.Background     = headerColor;          //A partir de ahora se declaran celdas que se agregaran al row
            Block ObjetoBlock = ObjetoCelda.Blocks.AddBlock(); //Declara un objeto de clase Block

            ObjetoBlock.TextProperties.FontSize = 11;
            ObjetoBlock.HorizontalAlignment     = HorizontalAlignment.Center; //Le da la alineacion
            ObjetoBlock.VerticalAlignment       = VerticalAlignment.Center;
            ObjetoBlock.InsertText("PACKAGING INFORMATION");                  //Agrega el texto de la primera columna

            ////----------SegundaColumna
            TableCell ObjetoCelda2 = NewFila.Cells.AddTableCell(); //Objeto TableCell se anade a la tabla como fila

            ObjetoCelda2.Background     = headerColor;             //Toma el color de fondo
            ObjetoCelda2.PreferredWidth = 250;
            Block ObjetoBlock2 = ObjetoCelda2.Blocks.AddBlock();   //Declara un objeto de clase Block

            ObjetoBlock2.TextProperties.FontSize = 11;
            ObjetoBlock2.HorizontalAlignment     = HorizontalAlignment.Center; //Le da la alineacion
            ObjetoBlock2.VerticalAlignment       = VerticalAlignment.Center;
            ObjetoBlock2.InsertText("PART NUMBER");                            //Le agrega el texto en el formato dado

            ////----------TerceraColumna
            TableCell ObjetoCelda3 = NewFila.Cells.AddTableCell(); //Objeto TableCell se anade a la tabla como fila

            ObjetoCelda3.Background     = headerColor;             //Toma el color de fondo
            ObjetoCelda3.PreferredWidth = 100;
            Block ObjetoBlock3 = ObjetoCelda3.Blocks.AddBlock();   //Declara un objeto de clase Block

            ObjetoBlock3.TextProperties.FontSize = 11;
            ObjetoBlock3.VerticalAlignment       = VerticalAlignment.Center;
            ObjetoBlock3.HorizontalAlignment     = HorizontalAlignment.Center; //Le da la alineacion
            ObjetoBlock3.InsertText("QUANTITY SHIPPED");                       //Le agrega el texto en el formato dado

            int i = 0;

            foreach (var sel in _ServiceER.ReadD(ParametroFedex))
            {
                i++;
                TableRow FilaContent = table.Rows.AddTableRow();                           //Nuevo objeto TableRow se anade a la tabla
                RgbColor rowColor    = i % 2 == 0 ? alternatingRowColor : RgbColors.White; // Alterna el color de la tabla obteniendo el residuo de la variable del ciclo

                //1erCampo
                TableCell ObjetoContenido = FilaContent.Cells.AddTableCell(); //Objeto TableCell se anade a la tabla como fila
                ObjetoContenido.Background = rowColor;                        //Toma el color de fondo
                Block amountBlock = ObjetoContenido.Blocks.AddBlock();
                amountBlock.TextProperties.FontSize = 8;
                amountBlock.HorizontalAlignment     = HorizontalAlignment.Center;
                amountBlock.InsertText(sel.RecordPieceBoxNo.ToString());

                //SegundoCampo
                TableCell ObjetoContenido2 = FilaContent.Cells.AddTableCell(); //Objeto TableCell se anade a la tabla como fila
                ObjetoContenido2.Background = rowColor;                        //Toma el color de fondo
                Block amountBlock2 = ObjetoContenido2.Blocks.AddBlock();
                amountBlock2.TextProperties.FontSize = 8;
                amountBlock2.HorizontalAlignment     = HorizontalAlignment.Center;
                amountBlock2.InsertText(sel.ProductName);

                //3er Campo
                TableCell ObjetoContenido3 = FilaContent.Cells.AddTableCell(); //Objeto TableCell se anade a la tabla como fila
                ObjetoContenido3.Background = rowColor;                        //Toma el color de fondo
                Block amountBlock3 = ObjetoContenido3.Blocks.AddBlock();
                amountBlock3.TextProperties.FontSize = 8;
                amountBlock3.HorizontalAlignment     = HorizontalAlignment.Center;
                amountBlock3.InsertText(sel.RecordCantidad.ToString());
            }
            ////////////////////////////////////////////////////////////////////Contenido de la tabla///////////////////////////////////////////
            editor.DrawTable(table);
        }