public async Task <Option <RichFormatting> > Answer(Request request)
        {
            try
            {
                var rich       = new RichFormatting();
                var paragraphs = ReadParagraphs(path);
                if (paragraphs != null)
                {
                    await paragraphs.Where(paragraph => paragraph.Contains(request.QueryText)).ForEachAsync(paragraph =>
                    {
                        var text = new TextParagraph(
                            StringExt.HighlightWords(paragraph, request.QueryText)
                            .Select(p => new Text(p.text, emphasis: p.highlight)));
                        rich.Paragraphs.Add(text);
                    });

                    return(Option.Some(rich));
                }
            }
            catch (FileNotFoundException)
            {
                var text = "This data source looks for a custom_notes.txt file in the data directory. Currently no such file exists.";
                var rich = new RichFormatting(
                    EnumerableExt.OfSingle(
                        new TextParagraph(
                            EnumerableExt.OfSingle(
                                new Text(text)))));
                return(Option.Some(rich));
            }

            return(Option.None <RichFormatting>());
        }
Esempio n. 2
0
        public static void Text2(Document pdfDocument)
        {
            Page pdfPage = pdfDocument.Pages.Add();

            int pos = 0;
            for (int i = 1; i <= 100; i++)
            {
                TextParagraph textParagraph = new TextParagraph();

                TextFragment textFragment1 = new TextFragment("Text Fragment (1) " + i + " ");
                //textFragment.Margin.Top = 8;
                //textFragment1.IsInLineParagraph = true;

                TextFragment textFragment2 = new TextFragment("Text Fragment (2) " + i + " ");
                //textFragment2.IsInLineParagraph = true;

                textParagraph.AppendLine(textFragment1/*, textState*/);
                //textParagraph.AppendLine(textFragment2/*, textState*/);
                textParagraph.Position = new Position(20, pdfDocument.PageInfo.Height - (i - pos) * (textFragment1.Rectangle.Height + 8));

                if (textParagraph.Position.YIndent < 0)
                {
                    pdfPage = pdfDocument.Pages.Add();
                    pos = i - 1;
                    textParagraph.Position = new Position(20, pdfDocument.PageInfo.Height - (i - pos) * (textFragment1.Rectangle.Height + 8));
                }


                TextBuilder textBuilder = new TextBuilder(pdfPage);
                textBuilder.AppendParagraph(textParagraph);

                
            }

        }
Esempio n. 3
0
 // ------------------------------------------------------------------
 // Constructor.
 //
 //      PtsContext - Context
 //      TextParagraphCache - Contained line break
 // ------------------------------------------------------------------
 internal OptimalBreakSession(TextParagraph textParagraph, TextParaClient textParaClient, TextParagraphCache TextParagraphCache, OptimalTextSource optimalTextSource) : base(textParagraph.PtsContext)
 {
     _textParagraph = textParagraph;
     _textParaClient = textParaClient;
     _textParagraphCache = TextParagraphCache;
     _optimalTextSource = optimalTextSource;
 }
        public static void UsingTextBuilderAndParagraph()
        {
            // ExStart:UsingTextBuilderAndParagraph
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            // Create Document instance
            Document pdfDocument = new Document();
            // Add page to pages collection of Document
            Page page = pdfDocument.Pages.Add();
            // Create TextBuilder instance
            TextBuilder builder = new TextBuilder(pdfDocument.Pages[1]);
            // Instantiate TextParagraph instance
            TextParagraph paragraph = new TextParagraph();
            // Create TextState instance to specify font name and size
            TextState state = new TextState("Arial", 12);

            // Specify the character spacing
            state.CharacterSpacing = 1.5f;
            // Append text to TextParagraph object
            paragraph.AppendLine("This is paragraph with character spacing", state);
            // Specify the position for TextParagraph
            paragraph.Position = new Position(100, 550);
            // Append TextParagraph to TextBuilder instance
            builder.AppendParagraph(paragraph);

            dataDir = dataDir + "CharacterSpacingUsingTextBuilderAndParagraph_out_.pdf";
            // Save resulting PDF document.
            pdfDocument.Save(dataDir);
            // ExEnd:UsingTextBuilderAndParagraph
            Console.WriteLine("\nCharacter spacing specified successfully using Text builder and paragraph.\nFile saved at " + dataDir);
        }
Esempio n. 5
0
        internal static Brush GetRichTextFill(List <TextParagraph> richText, Workbook workbook)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);
            Brush         brush          = null;
            IFillFormat   fillFormat     = null;

            if (firstRun != null)
            {
                fillFormat = firstRun.FillFormat;
            }
            if ((fillFormat == null) && (firstParagraph != null))
            {
                fillFormat = firstParagraph.FillFormat;
            }
            if (fillFormat != null)
            {
                object fill = ExcelChartExtension.GetFill(fillFormat, workbook);
                SpreadDrawingColorSettings spreadDrawingColorSettings = ExcelChartExtension.GetSpreadDrawingColorSettings(fillFormat);
                if (fill is string)
                {
                    if (workbook != null)
                    {
                        Windows.UI.Color color = Dt.Cells.Data.ColorHelper.UpdateColor(workbook.GetThemeColor((string)(fill as string)), spreadDrawingColorSettings, false);
                        return(new SolidColorBrush(color));
                    }
                    return(brush);
                }
                if (fill is Brush)
                {
                    brush = fill as Brush;
                }
            }
            return(brush);
        }
        private void btnRun_Click(object sender, EventArgs e)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string     ImageFile = @"..\..\..\..\..\..\Data\bg.png";
            RectangleF rect      = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);

            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //add title
            RectangleF rec_title   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 200, 70, 400, 50);
            IAutoShape shape_title = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec_title);

            shape_title.ShapeStyle.LineColor.Color = Color.White;
            shape_title.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
            TextParagraph para_title = new TextParagraph();

            para_title.Text      = "Background";
            para_title.Alignment = TextAlignmentType.Center;
            para_title.TextRanges[0].LatinFont             = new TextFont("Myriad Pro Light");
            para_title.TextRanges[0].FontHeight            = 36;
            para_title.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
            para_title.TextRanges[0].Fill.SolidColor.Color = Color.Black;
            shape_title.TextFrame.Paragraphs.Append(para_title);

            //add new shape to PPT document
            RectangleF rec   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 300, 155, 600, 300);
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec);

            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("Spire.Presentation for .NET is a professional PowerPoint compatible component that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET) platform. As an independent PowerPoint .NET component, Spire.Presentation for .NET doesn't need Microsoft PowerPoint installed on the machine.");

            TextParagraph para = new TextParagraph();

            para.Text = "Spire.Presentation for .NET support PPT, PPS, PPTX and PPSX presentation formats. It provides functions such as managing text, image, shapes, tables, animations, audio and video on slides. It also support exporting presentation slides to EMF, JPG, TIFF, PDF format etc.";
            shape.TextFrame.Paragraphs.Append(para);

            //set the font and fill style of text
            foreach (TextParagraph paragraph in shape.TextFrame.Paragraphs)
            {
                paragraph.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
                paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                paragraph.TextRanges[0].FontHeight            = 20;
                paragraph.TextRanges[0].LatinFont             = new TextFont("Myriad Pro");
                paragraph.Alignment = TextAlignmentType.Left;
            }

            //set spacing after
            shape.TextFrame.Paragraphs[0].SpaceAfter = 80;

            //save the document
            presentation.SaveToFile("background.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("background.pptx");
        }
 // Token: 0x06006661 RID: 26209 RVA: 0x001CC214 File Offset: 0x001CA414
 internal double CalcLineAdvanceForTextParagraph(TextParagraph textParagraph, int dcp, double lineAdvance)
 {
     if (!DoubleUtil.IsNaN(this._lineHeight))
     {
         LineStackingStrategy lineStackingStrategy = this.LineStackingStrategy;
         if (lineStackingStrategy != LineStackingStrategy.BlockLineHeight)
         {
             if (lineStackingStrategy != LineStackingStrategy.MaxHeight)
             {
             }
             if (dcp == 0 && textParagraph.HasFiguresOrFloaters() && textParagraph.GetLastDcpAttachedObjectBeforeLine(0) + textParagraph.ParagraphStartCharacterPosition == textParagraph.ParagraphEndCharacterPosition)
             {
                 lineAdvance = this._lineHeight;
             }
             else
             {
                 lineAdvance = Math.Max(lineAdvance, this._lineHeight);
             }
         }
         else
         {
             lineAdvance = this._lineHeight;
         }
     }
     return(lineAdvance);
 }
        public static void UsingTextBuilderAndParagraph()
        {
            // ExStart:UsingTextBuilderAndParagraph
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            // Create Document instance
            Document pdfDocument = new Document();
            // Add page to pages collection of Document
            Page page = pdfDocument.Pages.Add();
            // Create TextBuilder instance
            TextBuilder builder = new TextBuilder(pdfDocument.Pages[1]);
            // Instantiate TextParagraph instance
            TextParagraph paragraph = new TextParagraph();
            // Create TextState instance to specify font name and size
            TextState state = new TextState("Arial", 12);
            // Specify the character spacing
            state.CharacterSpacing = 1.5f;
            // Append text to TextParagraph object
            paragraph.AppendLine("This is paragraph with character spacing", state);
            // Specify the position for TextParagraph
            paragraph.Position = new Position(100, 550);
            // Append TextParagraph to TextBuilder instance
            builder.AppendParagraph(paragraph);

            dataDir = dataDir + "CharacterSpacingUsingTextBuilderAndParagraph_out.pdf";
            // Save resulting PDF document.
            pdfDocument.Save(dataDir);
            // ExEnd:UsingTextBuilderAndParagraph
            Console.WriteLine("\nCharacter spacing specified successfully using Text builder and paragraph.\nFile saved at " + dataDir);
        }
Esempio n. 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cch">Number of text position in the text array occupied by the inline object.</param>
        /// <param name="element">UIElement representing the inline object.</param>
        /// <param name="textProps">Text run properties for the inline object.</param>
        /// <param name="host">Paragraph - the host of the inline object.</param>
        internal InlineObjectRun(int cch, UIElement element, TextRunProperties textProps, TextParagraph host)
        {
            _cch = cch;
            _textProps = textProps;
            _host = host;

            _inlineUIContainer = (InlineUIContainer)LogicalTreeHelper.GetParent(element);
        }
        private void btnRun_Click(object sender, EventArgs e)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string     ImageFile = @"..\..\..\..\..\..\Data\bg.png";
            RectangleF rect      = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);

            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //add title
            RectangleF rec_title   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 200, 70, 400, 50);
            IAutoShape shape_title = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec_title);

            shape_title.ShapeStyle.LineColor.Color = Color.White;
            shape_title.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
            TextParagraph para_title = new TextParagraph();

            para_title.Text      = "Video";
            para_title.Alignment = TextAlignmentType.Center;
            para_title.TextRanges[0].LatinFont             = new TextFont("Myriad Pro Light");
            para_title.TextRanges[0].FontHeight            = 36;
            para_title.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
            para_title.TextRanges[0].Fill.SolidColor.Color = Color.Black;
            shape_title.TextFrame.Paragraphs.Append(para_title);

            //insert video into the document
            RectangleF videoRect = new RectangleF(100, 130, 100, 100);
            IVideo     video     = presentation.Slides[0].Shapes.AppendVideoMedia(Path.GetFullPath(@"..\..\..\..\..\..\Data\Spire.Doc Word to HTML.mp4"), videoRect);

            video.PictureFill.Picture.Url = @"..\..\..\..\..\..\Data\video.bmp";

            //add new shape to PPT document
            RectangleF rec   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 300, 255, 600, 150);
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec);

            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("Spire.Presentation for .NET is a professional PowerPoint compatible component that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET) platform. As an independent PowerPoint .NET component, Spire.Presentation for .NET doesn't need Microsoft PowerPoint installed on the machine.");

            //set the font
            TextParagraph paragraph = shape.TextFrame.Paragraphs[0];

            paragraph.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
            paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
            paragraph.TextRanges[0].FontHeight            = 20;
            paragraph.TextRanges[0].LatinFont             = new TextFont("Myriad Pro");
            paragraph.Alignment = TextAlignmentType.Left;

            //save the document
            presentation.SaveToFile("video.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("video.pptx");
        }
Esempio n. 11
0
        internal static void SetFontFamily(List <TextParagraph> richText, string fontFamily)
        {
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstParagraph != null) && !string.IsNullOrEmpty(fontFamily))
            {
                firstParagraph.LatinFontFamily = fontFamily;
            }
        }
        private void btnRun_Click(object sender, EventArgs e)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string     ImageFile = @"..\..\..\..\..\..\Data\bg.png";
            RectangleF rect      = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);

            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //add title
            RectangleF rec_title   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 200, 70, 400, 50);
            IAutoShape shape_title = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec_title);

            shape_title.ShapeStyle.LineColor.Color = Color.White;
            shape_title.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
            TextParagraph para_title = new TextParagraph();

            para_title.Text      = "Print";
            para_title.Alignment = TextAlignmentType.Center;
            para_title.TextRanges[0].LatinFont             = new TextFont("Myriad Pro Light");
            para_title.TextRanges[0].FontHeight            = 36;
            para_title.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
            para_title.TextRanges[0].Fill.SolidColor.Color = Color.Black;
            shape_title.TextFrame.Paragraphs.Append(para_title);

            //append new shape
            RectangleF rect2 = new RectangleF(presentation.SlideSize.Size.Width / 2 - 300, 155, 600, 270);
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect2);

            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("This sample demonstrates how to Print PPT file.");

            //add new paragraph
            shape.TextFrame.Paragraphs.Append(new TextParagraph());

            //add text to paragraph
            shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("Spire.Presentation for .NET is a professional PowerPoint compatible component that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET) platform. As an independent PowerPoint .NET component, Spire.Presentation for .NET doesn't need Microsoft PowerPoint installed on the machine. Spire.Presentation for .NET support PPT, PPS, PPTX and PPSX presentation formats. It provides functions such as managing text, image, shapes, tables, animations, audio and video on slides. It also support exporting presentation slides to EMF, JPG, TIFF, PDF format etc."));

            //set the Font
            foreach (TextParagraph para in shape.TextFrame.Paragraphs)
            {
                para.TextRanges[0].LatinFont             = new TextFont("Arial Rounded MT Bold");
                para.TextRanges[0].Fill.FillType         = FillFormatType.Solid;
                para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                para.Alignment = TextAlignmentType.Left;
            }

            //print
            PrinterSettings printerSettings = new PrinterSettings();

            presentation.Print(printerSettings);
        }
Esempio n. 13
0
 /// <summary>
 /// Create the radio button.
 /// </summary>
 /// <param name="text">Radio button label text.</param>
 /// <param name="anchor">Position anchor.</param>
 /// <param name="size">Radio button size.</param>
 /// <param name="offset">Offset from anchor position.</param>
 /// <param name="isChecked">If true, radio button will be created as checked.</param>
 public RadioButton(string text, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null, bool isChecked = false) :
     base(text, anchor, size, offset, isChecked)
 {
     UpdateStyle(DefaultStyle);
     if (TextParagraph != null)
     {
         TextParagraph.UpdateStyle(DefaultParagraphStyle);
     }
 }
Esempio n. 14
0
        public Task <Option <RichFormatting> > Answer(Request request)
        {
            var entry = jdict.Lookup(request.Word.RawWord.Trim());
            var rich  = new RichFormatting();

            var(greedyEntry, greedyWord) = GreedyLookup(request);
            if (greedyEntry != null && greedyWord != request.Word.RawWord)
            {
                rich.Paragraphs.Add(new TextParagraph(new[]
                {
                    new Text("The entries below are a result of the greedy lookup: "),
                    new Text(greedyWord, emphasis: true)
                }));
                var p = new TextParagraph();
                p.Content.Add(new Text(string.Join("\n\n", greedyEntry.Select(e => e.ToString()))));
                rich.Paragraphs.Add(p);
            }

            if (entry != null)
            {
                if (greedyEntry != null && greedyWord != request.Word.RawWord)
                {
                    rich.Paragraphs.Add(new TextParagraph(new[]
                    {
                        new Text("The entries below are a result of the regular lookup: "),
                        new Text(request.Word.RawWord, emphasis: true)
                    }));
                }
                var p = new TextParagraph();
                p.Content.Add(new Text(string.Join("\n\n", entry.Select(e => e.ToString()))));
                rich.Paragraphs.Add(p);
            }

            if (request.NotInflected != null && request.NotInflected != request.Word.RawWord)
            {
                entry = jdict.Lookup(request.NotInflected);
                if (entry != null)
                {
                    rich.Paragraphs.Add(new TextParagraph(new[]
                    {
                        new Text("The entries below are a result of lookup on the base form: "),
                        new Text(request.NotInflected, emphasis: true)
                    }));
                    var p = new TextParagraph();
                    p.Content.Add(new Text(string.Join("\n\n", entry.Select(e => e.ToString()))));
                    rich.Paragraphs.Add(p);
                }
            }

            if (rich.Paragraphs.Count == 0)
            {
                return(Task.FromResult(Option.None <RichFormatting>()));
            }

            return(Task.FromResult(Option.Some(rich)));
        }
Esempio n. 15
0
        public Task <Option <RichFormatting> > Answer(Request request, CancellationToken token)
        {
            var entry = lookup.LookupWords(request.Word.RawWord.Trim());
            var rich  = new RichFormatting();
            var p     = new TextParagraph();

            p.Content.Add(new Text(string.Join("\n", entry.OrderByDescending(m => list.RateFrequency(m)).Distinct()), fontSize: FontSize.Large));
            rich.Paragraphs.Add(p);
            return(Task.FromResult(Option.Some(rich)));
        }
Esempio n. 16
0
        internal static FontFamily GetRichTextFamily(List <TextParagraph> richText)
        {
            GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstParagraph != null) && !string.IsNullOrWhiteSpace(firstParagraph.LatinFontFamily))
            {
                return(new FontFamily(firstParagraph.LatinFontFamily));
            }
            return(DefaultStyleCollection.DefaultFontFamily);
        }
        public Task <Option <RichFormatting> > Answer(Request request, CancellationToken token)
        {
            var rich = new RichFormatting();
            var p    = new TextParagraph();

            var text = romaji.ToRomaji(request.AllText());

            p.Content.Add(new Text(text));
            rich.Paragraphs.Add(p);
            return(Task.FromResult(Option.Some(rich)));
        }
Esempio n. 18
0
 internal static TextRun GetFirstRun(List <TextParagraph> richText)
 {
     if ((richText != null) && (richText.Count > 0))
     {
         TextParagraph paragraph = richText[0];
         if ((paragraph != null) && (paragraph.TextRuns.Count > 0))
         {
             return(paragraph.TextRuns[0]);
         }
     }
     return(null);
 }
Esempio n. 19
0
        internal static void SetRichTextFontSize(List <TextParagraph> richText, double fontSize)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstRun != null) && (fontSize > 0.0))
            {
                firstRun.FontSize = new double?(UnitHelper.PixelToPoint(fontSize));
            }
            else if ((firstParagraph != null) && (fontSize > 0.0))
            {
                firstParagraph.FontSize = new double?(UnitHelper.PixelToPoint(fontSize));
            }
        }
Esempio n. 20
0
        private void debug_createP(string fileFullName)
        {
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
            Aspose.Pdf.Page     pdfPage     = (Aspose.Pdf.Page)pdfDocument.Pages.Add();

            Console.WriteLine("pdfPage.Rect = " + pdfPage.Rect);
            Console.WriteLine("pdfPage.PageInfo: Width - Height - PureHeight = " + pdfPage.PageInfo.Width + " - " + pdfPage.PageInfo.Height + " - " + pdfPage.PageInfo.PureHeight);
            Console.WriteLine("pdfPage.PageInfo: Margin.Top - Right - Bottom - Left = " + pdfPage.PageInfo.Margin.Top + " - " + pdfPage.PageInfo.Margin.Right + " - " + pdfPage.PageInfo.Margin.Bottom + " - " + pdfPage.PageInfo.Margin.Left);

            TextParagraph paragraph = new TextParagraph();

            // append string lines
            paragraph.AppendLine("the quick brown fox jumps over the lazy dog");
            paragraph.AppendLine("line2");
            paragraph.AppendLine("line3");


            Console.WriteLine("paragraph.Rectangle = " + paragraph.Rectangle);
            Console.WriteLine("paragraph.TextRectangle = " + paragraph.TextRectangle);



            // Create Graph instance
            Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)pdfPage.Rect.Width, (float)pdfPage.Rect.Height);
            // Add graph object to paragraphs collection of page instance
            pdfPage.Paragraphs.Add(graph);
            // Create Rectangle instance
            //Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 120);

            Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle((float)paragraph.Rectangle.LLX, (float)paragraph.Rectangle.LLY, (float)paragraph.Rectangle.Width, (float)paragraph.Rectangle.Height);
            //Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle((float)paragraph.TextRectangle.LLX, (float)paragraph.TextRectangle.LLY, (float)paragraph.TextRectangle.Width, (float)paragraph.TextRectangle.Height);

            // Specify fill color for Graph object

            //rect.GraphInfo.FillColor = Aspose.Pdf.Color.Red;
            rect.GraphInfo.LineWidth = 2;
            rect.GraphInfo.Color     = Aspose.Pdf.Color.Brown;

            // Add rectangle object to shapes collection of Graph object
            graph.Shapes.Add(rect);



            TextBuilder textBuilder = new TextBuilder(pdfPage);

            textBuilder.AppendParagraph(paragraph);


            pdfDocument.Save(fileFullName);
        }
Esempio n. 21
0
        internal static void SetRichTextFontStyle(List <TextParagraph> richText, bool italics)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstRun != null) && italics)
            {
                firstRun.Italics = new bool?(italics);
            }
            else if ((firstParagraph != null) && italics)
            {
                firstParagraph.Italics = new bool?(italics);
            }
        }
Esempio n. 22
0
        internal static void SetRichTextFill(List <TextParagraph> richText, Brush fillBrush)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstRun != null) && (fillBrush != null))
            {
                firstRun.FillFormat = fillBrush.ToExcelFillFormat();
            }
            else if ((firstParagraph != null) && (fillBrush != null))
            {
                firstParagraph.FillFormat = fillBrush.ToExcelFillFormat();
            }
        }
Esempio n. 23
0
        public static void Run()
        {
            // ExStart:RotateTextUsingTextParagraphAndBuilder
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            // Initialize document object
            Document pdfDocument = new Document();
            // Get particular page
            Page pdfPage = (Page)pdfDocument.Pages.Add();

            for (int i = 0; i < 4; i++)
            {
                TextParagraph paragraph = new TextParagraph();
                paragraph.Position = new Position(200, 600);
                // Specify rotation
                paragraph.Rotation = i * 90 + 45;
                // Create text fragment
                TextFragment textFragment1 = new TextFragment("Paragraph Text");
                // Create text fragment
                textFragment1.TextState.FontSize        = 12;
                textFragment1.TextState.Font            = FontRepository.FindFont("TimesNewRoman");
                textFragment1.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
                textFragment1.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
                // Create text fragment
                TextFragment textFragment2 = new TextFragment("Second line of text");
                // Set text properties
                textFragment2.TextState.FontSize        = 12;
                textFragment2.TextState.Font            = FontRepository.FindFont("TimesNewRoman");
                textFragment2.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
                textFragment2.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
                // Create text fragment
                TextFragment textFragment3 = new TextFragment("And some more text...");
                // Set text properties
                textFragment3.TextState.FontSize        = 12;
                textFragment3.TextState.Font            = FontRepository.FindFont("TimesNewRoman");
                textFragment3.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
                textFragment3.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
                textFragment3.TextState.Underline       = true;
                paragraph.AppendLine(textFragment1);
                paragraph.AppendLine(textFragment2);
                paragraph.AppendLine(textFragment3);
                // Create TextBuilder object
                TextBuilder textBuilder = new TextBuilder(pdfPage);
                // Append the text fragment to the PDF page
                textBuilder.AppendParagraph(paragraph);
            }
            // Save document
            pdfDocument.Save(dataDir + "TextFragmentTests_Rotated4_out.pdf");
            // ExEnd:RotateTextUsingTextParagraphAndBuilder
        }
Esempio n. 24
0
        internal static void SetRichtTextFontWeight(List <TextParagraph> richText, bool bold)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);
            FontWeight    normal         = FontWeights.Normal;

            if (firstRun != null)
            {
                firstRun.Bold = new bool?(bold);
            }
            else if (firstParagraph != null)
            {
                firstParagraph.Bold = new bool?(bold);
            }
        }
Esempio n. 25
0
    public async Task <Option <RichFormatting> > Answer(Request request, CancellationToken token)
    {
        var api = this.memApiAccessor();

        if (api == null)
        {
            return(Option.Some(new RichFormatting(new Paragraph[]
            {
                new TextParagraph(new Text[]
                {
                    new Text("The address to the DidacticalEnigma.Mem server is not configured")
                })
            })));
        }

        var response = await api.QueryWithHttpMessagesAsync(
            query : request.Word.RawWord,
            cancellationToken : token,
            translatedOnly : true);

        var rich = new RichFormatting();

        if (response.Response.IsSuccessStatusCode)
        {
            QueryTranslationsResult result = response.Body;
            foreach (var tl in result.Translations)
            {
                var highlights    = MarkHighlights(tl.Source, tl.HighlighterSequence);
                var textParagraph = new TextParagraph(
                    highlights
                    .Select(t => new Text(t.fragment, emphasis: t.highlight)));
                textParagraph.Content.Add(new Text("\n"));
                textParagraph.Content.Add(new Text(tl.Target));
                rich.Paragraphs.Add(textParagraph);
            }
        }
        else
        {
            rich.Paragraphs.Add(
                new TextParagraph(
                    new Text[]
            {
                new Text($"Error: {response.Response.StatusCode}")
            }));
        }

        return(rich.Some());
    }
Esempio n. 26
0
        internal static FontWeight GetRichTextFontWeight(List <TextParagraph> richText, FontWeight defaultFontWeight)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);
            FontWeight    bold           = defaultFontWeight;

            if (((firstRun != null) && firstRun.Bold.HasValue) && firstRun.Bold.Value)
            {
                return(FontWeights.Bold);
            }
            if (((firstParagraph != null) && firstParagraph.Bold.HasValue) && firstParagraph.Bold.Value)
            {
                bold = FontWeights.Bold;
            }
            return(bold);
        }
Esempio n. 27
0
        internal static double?GetRichTextFontSize(List <TextParagraph> richText)
        {
            double?       nullable       = null;
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);

            if ((firstRun != null) && firstRun.FontSize.HasValue)
            {
                return(new double?(UnitHelper.PointToPixel(firstRun.FontSize.Value)));
            }
            if ((firstParagraph != null) && firstParagraph.FontSize.HasValue)
            {
                nullable = new double?(UnitHelper.PointToPixel(firstParagraph.FontSize.Value));
            }
            return(nullable);
        }
Esempio n. 28
0
        internal static FontStyle GetRichTextFontStyle(List <TextParagraph> richText)
        {
            TextRun       firstRun       = GetFirstRun(richText);
            TextParagraph firstParagraph = GetFirstParagraph(richText);
            FontStyle     normal         = FontStyle.Normal;

            if (((firstRun != null) && firstRun.Italics.HasValue) && firstRun.Italics.Value)
            {
                return(FontStyle.Italic);
            }
            if (((firstParagraph != null) && firstParagraph.Italics.HasValue) && firstParagraph.Italics.Value)
            {
                normal = FontStyle.Italic;
            }
            return(normal);
        }
Esempio n. 29
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // Load source PDF form
            Aspose.Pdf.Facades.Form form1  = new Aspose.Pdf.Facades.Form(dataDir + "RadioButtonField.pdf");
            Document PDF_Template_PDF_HTML = new Document(dataDir + "RadioButtonField.pdf");

            foreach (var item in form1.FieldNames)
            {
                Console.WriteLine(item.ToString());
                Dictionary <string, string> radioOptions = form1.GetButtonOptionValues(item);
                if (item.Contains("radio1"))
                {
                    Aspose.Pdf.Forms.RadioButtonField       field0      = PDF_Template_PDF_HTML.Form[item] as Aspose.Pdf.Forms.RadioButtonField;
                    Aspose.Pdf.Forms.RadioButtonOptionField fieldoption = new Aspose.Pdf.Forms.RadioButtonOptionField();
                    fieldoption.OptionName  = "Yes";
                    fieldoption.PartialName = "Yesname";

                    var updatedFragment = new Aspose.Pdf.Text.TextFragment("test123");
                    updatedFragment.TextState.Font        = FontRepository.FindFont("Arial");
                    updatedFragment.TextState.FontSize    = 10;
                    updatedFragment.TextState.LineSpacing = 6.32f;

                    // Create TextParagraph object
                    TextParagraph par = new TextParagraph();

                    // Set paragraph position
                    par.Position = new Position(field0.Rect.LLX, field0.Rect.LLY + updatedFragment.TextState.FontSize);
                    // Specify word wraping mode
                    par.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;

                    // Add new TextFragment to paragraph
                    par.AppendLine(updatedFragment);

                    // Add the TextParagraph using TextBuilder
                    TextBuilder textBuilder = new TextBuilder(PDF_Template_PDF_HTML.Pages[1]);
                    textBuilder.AppendParagraph(par);

                    field0.DeleteOption("item1");
                }
            }
            PDF_Template_PDF_HTML.Save(dataDir + "RadioButtonField_out.pdf");
            // ExEnd:1
        }
Esempio n. 30
0
        public static void AddNewLineFeed()
        {
            try
            {
                // ExStart:AddNewLineFeed
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
                Aspose.Pdf.Document pdfApplicationDoc    = new Aspose.Pdf.Document();
                Aspose.Pdf.Page     applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add();

                // Initialize new TextFragment with text containing required newline markers
                Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe");

                // Set text fragment properties if necessary
                textFragment.TextState.FontSize        = 12;
                textFragment.TextState.Font            = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman");
                textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
                textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

                // Create TextParagraph object
                TextParagraph par = new TextParagraph();

                // Add new TextFragment to paragraph
                par.AppendLine(textFragment);

                // Set paragraph position
                par.Position = new Aspose.Pdf.Text.Position(100, 600);

                // Create TextBuilder object
                TextBuilder textBuilder = new TextBuilder(applicationFirstPage);
                // Add the TextParagraph using TextBuilder
                textBuilder.AppendParagraph(par);


                dataDir = dataDir + "AddNewLineFeed_out.pdf";

                // Save resulting PDF document.
                pdfApplicationDoc.Save(dataDir);
                // ExEnd:AddNewLineFeed
                Console.WriteLine("\nNew line feed added successfully.\nFile saved at " + dataDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            // ExStart:RotateTextUsingParagraph
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            // Initialize document object
            Document pdfDocument = new Document();
            // Get particular page
            Page          pdfPage   = (Page)pdfDocument.Pages.Add();
            TextParagraph paragraph = new TextParagraph();

            paragraph.Position = new Position(200, 600);
            // Create text fragment
            TextFragment textFragment1 = new TextFragment("rotated text");

            // Set text properties
            textFragment1.TextState.FontSize = 12;
            textFragment1.TextState.Font     = FontRepository.FindFont("TimesNewRoman");
            // Set rotation
            textFragment1.TextState.Rotation = 45;
            // Create text fragment
            TextFragment textFragment2 = new TextFragment("main text");

            // Set text properties
            textFragment2.TextState.FontSize = 12;
            textFragment2.TextState.Font     = FontRepository.FindFont("TimesNewRoman");
            // Create text fragment
            TextFragment textFragment3 = new TextFragment("another rotated text");

            // Set text properties
            textFragment3.TextState.FontSize = 12;
            textFragment3.TextState.Font     = FontRepository.FindFont("TimesNewRoman");
            // Set rotation
            textFragment3.TextState.Rotation = -45;
            // Append the text fragments to the paragraph
            paragraph.AppendLine(textFragment1);
            paragraph.AppendLine(textFragment2);
            paragraph.AppendLine(textFragment3);
            // Create TextBuilder object
            TextBuilder textBuilder = new TextBuilder(pdfPage);

            // Append the text paragraph to the PDF page
            textBuilder.AppendParagraph(paragraph);
            // Save document
            pdfDocument.Save(dataDir + "TextFragmentTests_Rotated2_out.pdf");
            // ExEnd:RotateTextUsingParagraph
        }
        public Task <Option <RichFormatting> > Answer(Request request, CancellationToken token)
        {
            var rich   = new RichFormatting();
            var lookup = LookAhead(request);

            foreach (var l in lookup)
            {
                var textParagraph = new TextParagraph(
                    l.RenderedHighlights
                    .Select(t => new Text(t.fragment, emphasis: t.highlight)));
                textParagraph.Content.Add(new Text("\n"));
                textParagraph.Content.Add(new Text(l.SentencePair.EnglishSentence));
                rich.Paragraphs.Add(textParagraph);
            }

            return(Task.FromResult(Option.Some(rich)));
        }
Esempio n. 33
0
 /// <summary>Creates a result card from text paragraph widget.</summary>
 public static Card CreateCard(TextParagraph textParagraph) =>
 new Card
 {
     Sections = new[]
     {
         new Section
         {
             Widgets = new[]
             {
                 new WidgetMarkup
                 {
                     TextParagraph = textParagraph
                 }
             }
         }
     }
 };
        public static void Run()
        {
            // ExStart:RenderingReplaceableSymbols
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document();
            Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add();

            // Initialize new TextFragment with text containing required newline markers
            Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe");

            // Set text fragment properties if necessary
            textFragment.TextState.FontSize = 12;
            textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman");
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

            // Create TextParagraph object
            TextParagraph par = new TextParagraph();

            // Add new TextFragment to paragraph
            par.AppendLine(textFragment);

            // Set paragraph position
            par.Position = new Aspose.Pdf.Text.Position(100, 600);

            // Create TextBuilder object
            TextBuilder textBuilder = new TextBuilder(applicationFirstPage);
            // Add the TextParagraph using TextBuilder
            textBuilder.AppendParagraph(par);

            dataDir = dataDir + "RenderingReplaceableSymbols_out.pdf";
            pdfApplicationDoc.Save(dataDir);
            // ExEnd:RenderingReplaceableSymbols            
            Console.WriteLine("\nReplaceable symbols render successfully duing pdf creation.\nFile saved at " + dataDir);
        }
        /// <summary>
        /// Calculate line advance for TextParagraphs - this method has special casing in case the LineHeight property on the Paragraph element
        /// needs to be respected
        /// </summary>
        /// <param name="textParagraph">
        /// TextParagraph that owns the line
        /// </param>
        /// <param name="dcp">
        /// Dcp of the line
        /// </param>
        /// <param name="lineAdvance">
        /// Calculated height of the line
        /// </param>
        internal double CalcLineAdvanceForTextParagraph(TextParagraph textParagraph, int dcp, double lineAdvance)
        {
            if (!DoubleUtil.IsNaN(_lineHeight))
            {
                switch (LineStackingStrategy)
                {
                    case LineStackingStrategy.BlockLineHeight:
                        lineAdvance = _lineHeight;
                        break;

                    case LineStackingStrategy.MaxHeight:
                    default:
                        if (dcp == 0 && textParagraph.HasFiguresOrFloaters() &&
                           ((textParagraph.GetLastDcpAttachedObjectBeforeLine(0) + textParagraph.ParagraphStartCharacterPosition)
                             == textParagraph.ParagraphEndCharacterPosition))
                        {
                            // The Paragraph element contains only figures and floaters and has LineHeight set. In this case LineHeight
                            // should be respected
                            lineAdvance = _lineHeight;
                        }
                        else
                        {
                            lineAdvance = Math.Max(lineAdvance, _lineHeight);
                        }
                        break;
                    //    case LineStackingStrategy.InlineLineHeight:
                    //        // Inline uses the height of the line just processed.
                    //        break;

                    //    case LineStackingStrategy.GridHeight:
                    //        lineAdvance = (((TextDpi.ToTextDpi(lineAdvance) - 1) / TextDpi.ToTextDpi(_lineHeight)) + 1) * _lineHeight;
                    //        break;
                    //}
                }
            }
            return lineAdvance;
        }
Esempio n. 36
0
 // ------------------------------------------------------------------
 // Constructor.
 // 
 //      paragraph - Paragraph associated with this object.
 // ----------------------------------------------------------------- 
 internal TextParaClient(TextParagraph paragraph) : base(paragraph) 
 {
 } 
Esempio n. 37
0
        public static void AddTextUsingTextParagraph()
        {
            // ExStart:AddTextUsingTextParagraph
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            // Open document
            Document doc = new Document();
            // Add page to pages collection of Document object
            Page page = doc.Pages.Add();
            TextBuilder builder = new TextBuilder(page);
            // Create text paragraph
            TextParagraph paragraph = new TextParagraph();
            // Set subsequent lines indent
            paragraph.SubsequentLinesIndent = 20;
            // Specify the location to add TextParagraph
            paragraph.Rectangle = new Aspose.Pdf.Rectangle(100, 300, 200, 700);
            // Specify word wraping mode
            paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
            // Create text fragment
            TextFragment fragment1 = new TextFragment("the quick brown fox jumps over the lazy dog");
            fragment1.TextState.Font = FontRepository.FindFont("Times New Roman");
            fragment1.TextState.FontSize = 12;
            // Add fragment to paragraph
            paragraph.AppendLine(fragment1);
            // Add paragraph
            builder.AppendParagraph(paragraph);

            dataDir = dataDir + "AddTextUsingTextParagraph_out.pdf";

            // Save resulting PDF document.
            doc.Save(dataDir);
            
            // ExEnd:AddTextUsingTextParagraph
            Console.WriteLine("\nText using text paragraph added successfully.\nFile saved at " + dataDir);
        }
Esempio n. 38
0
    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        Document document = new Document();
            Section section = document.Sections.Add();

        //			TallComponents.PDF.Layout.Table headerTable = new TallComponents.PDF.Layout.Table();
        //
            Row row;
            Cell cell;
            TextParagraph text;
        //
        //			row = headerTable.Rows.Add();
        //
        //			// INVOICE
        //			cell = row.Cells.Add();
        //			cell.PreferredWidth = ( section.PageSize.Width - section.LeftMargin - section.RightMargin ) / 2;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( "INVOICE", TallComponents.PDF.Layout.Font.HelveticaBold ) );
        //			text.Alignment = Paragraph.HAlignment.Left;
        //			cell.Paragraphs.Add( text );
        //
        //			// COMPANY
        //			cell = row.Cells.Add();
        //			cell.PreferredWidth = ( section.PageSize.Width - section.LeftMargin - section.RightMargin ) / 2;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( companyName.Text ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			// ADDRESS
        //			row = headerTable.Rows.Add();
        //			cell = row.Cells.Add();
        //			cell.ColSpan = 2;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( companyAddress.Text ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			// POSTALCODE
        //			row = headerTable.Rows.Add();
        //			cell = row.Cells.Add();
        //			cell.ColSpan = 2;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( companyPostalCode.Text ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			// COUNTRY
        //			row = headerTable.Rows.Add();
        //			cell = row.Cells.Add();
        //			cell.ColSpan = 2;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( companyCountry.Text ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			headerTable.Border = new Border();
        //			headerTable.Border.Bottom = new TallComponents.PDF.Layout.Pen();
        //			section.Paragraphs.Add( headerTable );
        //
        //			TallComponents.PDF.Layout.Table invoiceTable = new TallComponents.PDF.Layout.Table();
        //			invoiceTable.SpacingBefore = 10;
        //
        //			// INVOICE NUMBER
        //			row = invoiceTable.Rows.Add();
        //			cell = row.Cells.Add();
        //			cell.PreferredWidth = section.PageSize.Width - section.LeftMargin - section.RightMargin;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( "Number", TallComponents.PDF.Layout.Font.HelveticaBold ) );
        //			text.Fragments.Add( new Fragment( invoiceNumber.Text, TallComponents.PDF.Layout.Font.Helvetica ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			// INVOICE DATE
        //			row = invoiceTable.Rows.Add();
        //			cell = row.Cells.Add();
        //			cell.PreferredWidth = section.PageSize.Width - section.LeftMargin - section.RightMargin;
        //			text = new TextParagraph();
        //			text.Fragments.Add( new Fragment( "Date", TallComponents.PDF.Layout.Font.HelveticaBold ) );
        //			text.Fragments.Add( new Fragment( invoiceDate.Text ) );
        //			text.Alignment = Paragraph.HAlignment.Right;
        //			cell.Paragraphs.Add( text );
        //
        //			section.Paragraphs.Add( invoiceTable );

            // INFO TABLE (contains billto and shipto tables)
            TallComponents.PDF.Layout.Table infoTable = new TallComponents.PDF.Layout.Table();
            infoTable.SpacingBefore = 20;
            section.Paragraphs.Add( infoTable );
            row = infoTable.Rows.Add();

            cell = row.Cells.Add();
            cell.PreferredWidth = ( section.PageSize.Width - section.LeftMargin - section.RightMargin ) / 2;
            cell.RightMargin = 5;
            cell.TopPadding = cell.BottomPadding = 5;
            cell.Border = new Border(Color.Black, 0.5, new TallComponents.PDF.Layout.SolidBrush( Color.LightGray ) );

            TallComponents.PDF.Layout.Table billToTable = new TallComponents.PDF.Layout.Table();
            billToTable.PreferredWidth = cell.PreferredWidth;
            cell.Paragraphs.Add( billToTable );

            cell = row.Cells.Add();
            cell.PreferredWidth = ( section.PageSize.Width - section.LeftMargin - section.RightMargin ) / 2;
            cell.LeftMargin = 5;
            cell.TopPadding = cell.BottomPadding = 5;
            cell.Border = new Border( Color.Black, 0.5, new TallComponents.PDF.Layout.SolidBrush( Color.LightGray ) );

            TallComponents.PDF.Layout.Table shipToTable = new TallComponents.PDF.Layout.Table();
            shipToTable.PreferredWidth = cell.PreferredWidth;
            cell.Paragraphs.Add( shipToTable );

            double demiPage = ( section.PageSize.Width - section.LeftMargin - section.RightMargin ) / 2;

            // BILL TO
            row = billToTable.Rows.Add();

            cell = row.Cells.Add();
            cell.LeftMargin = 5;
            cell.ColSpan = 2;

            text = new TextParagraph();
            text.Fragments.Add( new Fragment( "Bill to:", TallComponents.PDF.Layout.Font.HelveticaBold, 14 ) );
            cell.Paragraphs.Add( text );

            addItemRow( billToTable, "Name", billToName.Text );
            addItemRow( billToTable, "Address", billToAddress.Text );
            addItemRow( billToTable, "Contact person", billToContact.Text );
            addItemRow( billToTable, "Fax", billToFax.Text );

            // SHIP TO
            row = shipToTable.Rows.Add();

            cell = row.Cells.Add();
            cell.LeftMargin = 5;
            cell.ColSpan = 2;

            text = new TextParagraph();
            text.Fragments.Add( new Fragment( "Ship to:", TallComponents.PDF.Layout.Font.HelveticaBold, 14 ) );
            cell.Paragraphs.Add( text );

            addItemRow( shipToTable, "Method", shipMethod.Text );
            addItemRow( shipToTable, "Name", shipName.Text );
            addItemRow( shipToTable, "Address", shipAddress.Text );
            addItemRow( shipToTable, "Contact person", shipContact.Text );
            addItemRow( shipToTable, "E-mail", shipEmail.Text );

            TallComponents.PDF.Layout.Table itemsTable = new TallComponents.PDF.Layout.Table();
            itemsTable.SpacingBefore = 20;
            section.Paragraphs.Add(itemsTable);
            row = itemsTable.Rows.Add();
            row.Border = new Border();
            row.Border.Background = new TallComponents.PDF.Layout.SolidBrush(Color.LightGray);
            row.Border.Bottom = new TallComponents.PDF.Layout.Pen(Color.Black, 0.5);

            cell = row.Cells.Add();
            cell.PreferredWidth = (section.PageSize.Width - section.LeftMargin - section.RightMargin) / 2;
            text = new TextParagraph();
            text.Fragments.Add(new Fragment("Item"));
            cell.Paragraphs.Add(text);

            cell = row.Cells.Add();
            cell.PreferredWidth = (section.PageSize.Width - section.LeftMargin - section.RightMargin) / 6;
            text = new TextParagraph();
            text.Alignment = Paragraph.HAlignment.Right;
            text.Fragments.Add(new Fragment("Quantity"));
            cell.Paragraphs.Add(text);

            cell = row.Cells.Add();
            cell.PreferredWidth = (section.PageSize.Width - section.LeftMargin - section.RightMargin) / 6;
            text = new TextParagraph();
            text.Alignment = Paragraph.HAlignment.Right;
            text.Fragments.Add(new Fragment("Unit price"));
            cell.Paragraphs.Add(text);

            cell = row.Cells.Add();
            cell.PreferredWidth = (section.PageSize.Width - section.LeftMargin - section.RightMargin) / 6;
            text = new TextParagraph();
            text.Alignment = Paragraph.HAlignment.Right;
            text.Fragments.Add(new Fragment("Line total"));
            cell.Paragraphs.Add(text);

            double subTotal = 0;
            for (int i = 1; i < orderTable.Rows.Count && orderTable.Rows[i].Cells.Count == 4; i++)
            {
                row = new Row();
                row.TopMargin = 5;

                string item = (orderTable.Rows[i].Cells[0].Controls[0] as TextBox).Text;
                cell = row.Cells.Add();
                text = new TextParagraph();
                text.Fragments.Add(new Fragment(item));
                cell.Paragraphs.Add(text);

                int quantity = 0;
                try
                {
                    quantity = int.Parse((orderTable.Rows[i].Cells[1].Controls[0] as TextBox).Text);
                }
                catch (Exception /*ex*/ ) { }
                cell = row.Cells.Add();
                text = new TextParagraph();
                text.Fragments.Add(new Fragment(quantity.ToString()));
                text.Alignment = Paragraph.HAlignment.Right;
                cell.Paragraphs.Add(text);

                double unitPrice = 0;
                try
                {
                    unitPrice = double.Parse((orderTable.Rows[i].Cells[2].Controls[0] as TextBox).Text);
                }
                catch (Exception /*ex*/ ) { }
                cell = row.Cells.Add();
                text = new TextParagraph();
                text.Fragments.Add(new Fragment(string.Format("{0:f2}", unitPrice)));
                text.Alignment = Paragraph.HAlignment.Right;
                cell.Paragraphs.Add(text);

                double lineTotal = quantity * unitPrice;
                cell = row.Cells.Add();
                text = new TextParagraph();
                text.Fragments.Add(new Fragment(string.Format("{0:f2}", lineTotal)));
                text.Alignment = Paragraph.HAlignment.Right;
                cell.Paragraphs.Add(text);

                if (quantity > 0) itemsTable.Rows.Add(row);

                subTotal += lineTotal;
            }

            // SUBTOTAL
            row = itemsTable.Rows.Add();
            row.Border = new Border();
            row.Border.Top = new TallComponents.PDF.Layout.Pen(Color.Black, 0.5);
            row.TopPadding = 5;
            cell = row.Cells.Add();
            cell.ColSpan = 3;
            text = new TextParagraph();
            text.Fragments.Add(new Fragment("Subtotal"));
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);
            cell = row.Cells.Add();
            text = new TextParagraph();
            text.Fragments.Add(new Fragment(string.Format("{0:f2}", subTotal)));
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);

            // SHIPPING & HANDLING
            double shipping = double.Parse(shippingAndHandling.Text);
            row = itemsTable.Rows.Add();
            row.TopMargin = 5;
            cell = row.Cells.Add();
            cell.ColSpan = 3;
            text = new TextParagraph();
            text.Fragments.Add(new Fragment("Shipping & handling"));
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);
            cell = row.Cells.Add();
            text = new TextParagraph();
            text.Alignment = Paragraph.HAlignment.Right;
            if (shipping == 0)
            {
                text.Fragments.Add(new Fragment("n/a"));
            }
            else
            {
                text.Fragments.Add(new Fragment(string.Format("{0:f2}", shipping)));
            }
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);

            // VAT
            double vat = 0;

            if (chkVAT.Checked)
            {
                vat = 0.19 * (subTotal + shipping);
                row = itemsTable.Rows.Add();
                row.TopMargin = 5;
                cell = row.Cells.Add();
                cell.ColSpan = 3;
                text = new TextParagraph();
                text.Fragments.Add(new Fragment("19% VAT"));
                text.Alignment = Paragraph.HAlignment.Right;
                cell.Paragraphs.Add(text);
                cell = row.Cells.Add();
                text = new TextParagraph();
                text.Alignment = Paragraph.HAlignment.Right;
                text.Fragments.Add(new Fragment(string.Format("{0:f2}", vat)));
                text.Alignment = Paragraph.HAlignment.Right;
                cell.Paragraphs.Add(text);
            }

            // PAYMENT DUE
            row = itemsTable.Rows.Add();
            row.Border = new Border();
            row.Border.Top = new TallComponents.PDF.Layout.Pen(Color.Black, 0.5);
            row.Border.Background = new TallComponents.PDF.Layout.SolidBrush(Color.LightGray);
            row.TopMargin = 5;
            cell = row.Cells.Add();
            cell.ColSpan = 3;
            text = new TextParagraph();
            text.Fragments.Add(new Fragment("Payment due"));
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);
            cell = row.Cells.Add();
            text = new TextParagraph();
            text.Fragments.Add(new Fragment(string.Format("USD {0:f2}", subTotal + shipping + vat), TallComponents.PDF.Layout.Font.HelveticaBoldOblique));
            text.Alignment = Paragraph.HAlignment.Right;
            cell.Paragraphs.Add(text);

            // PAYMENT
            text = new TextParagraph();
            text.SpacingBefore = 20;
            text.Fragments.Add(new Fragment("Payment", TallComponents.PDF.Layout.Font.HelveticaBold, 14));
            section.Paragraphs.Add(text);

            text = new TextParagraph();
            text.SpacingBefore = 8;

            if (PaymentFull.Checked)
            {
                text.Fragments.Add(new Fragment("Paid in full"));
            }
            else if (PaymentCheck.Checked)
            {
                text.Fragments.Add(new Fragment("Send check payable to " + companyName.Text));
            }
            else if (PaymentOnline.Checked)
            {
                text.Fragments.Add(new Fragment("Purchase online using our shopping basket"));
                if (chkDiscountCoupon.Checked)
                {
                    text.Fragments.Add(new Fragment(" with discount coupon: " + discountCoupon.Text));
                }
            }

            section.Paragraphs.Add(text);

            // REMARKS
            if (remarks.Text.Trim().Length != 0)
            {
                text = new TextParagraph();
                text.SpacingBefore = 20;
                text.Fragments.Add(new Fragment("Remarks", TallComponents.PDF.Layout.Font.HelveticaBold, 14));
                section.Paragraphs.Add(text);

                text = new TextParagraph();
                text.SpacingBefore = 8;
                text.Fragments.Add(new Fragment(remarks.Text));
                section.Paragraphs.Add(text);
            }

            // Send to web client
            Response.Clear();
            document.Write( Response );
            Response.End();
    }
Esempio n. 39
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="dcp"> 
 /// Embedded object's character position.
 /// </param> 
 /// <param name="uiElementIsland"> 
 /// UIElementIsland associated with embedded object.
 /// </param> 
 /// <param name="para">
 /// TextParagraph associated with embedded object.
 /// </param>
 internal InlineObject(int dcp, UIElementIsland uiElementIsland, TextParagraph para) 
     : base(dcp)
 { 
     _para = para; 
     _uiElementIsland = uiElementIsland;
     _uiElementIsland.DesiredSizeChanged += new DesiredSizeChangedEventHandler(_para.OnUIElementDesiredSizeChanged); 
 }
Esempio n. 40
0
 void addItemRow( TallComponents.PDF.Layout.Table table, string name, string val )
 {
     Row row = table.Rows.Add();
         Cell cell = row.Cells.Add();
         //40%
         cell.PreferredWidth = (table.PreferredWidth / 10) * 4 - 5;
         cell.RightMargin = 10;
         cell.LeftMargin = 5;
         TextParagraph text = new TextParagraph();
         text.Fragments.Add( new Fragment( name, TallComponents.PDF.Layout.Font.HelveticaOblique, 9 ) );
         cell.Paragraphs.Add( text );
         cell = row.Cells.Add();
         //60%
         cell.PreferredWidth = ( table.PreferredWidth / 10 ) * 6 - 5;
         text = new TextParagraph();
         text.Fragments.Add( new Fragment( val, 9 ) );
         cell.Paragraphs.Add( text );
 }
Esempio n. 41
0
        private static void SetupIntroductionPage(Document doc, string subtitle, string author, string description, string processImagePath)
        {
			if(author == null)
				author = "";
			if(description == null)
				description = "";
			if(subtitle == null)
				subtitle = "";
			if(processImagePath == null)
				processImagePath = "";
			
            Section introPage = new Section();
            introPage.StartOnNewPage = true;

            doc.Sections.Add(introPage);

            TextParagraph tp = new TextParagraph();
            tp.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
            Fragment f = new Fragment();
            f.Text = subtitle;
            f.Font = Font.HelveticaBold;
            f.FontSize = 22;
            tp.Fragments.Add(f);

            tp.SpacingBefore = 2;
            tp.SpacingAfter = 2;

            introPage.Paragraphs.Add(tp);

            tp = new TextParagraph();
            tp.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
            f = new Fragment();
            f.Text = "Author: " + author;
            f.Font = Font.HelveticaBold;
            f.FontSize = 14;
            f.PreserveWhiteSpace = true;
            f.Bold = true;
            f.Underline = true;

            tp.Fragments.Add(f);
            tp.SpacingBefore = 2;
            tp.SpacingAfter = 20;

            introPage.Paragraphs.Add(tp);

            tp = new TextParagraph();
            tp.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Left;
            f = new Fragment();
            f.Text = description;
            f.Font = Font.HelveticaBold;
            f.FontSize = 12;
            f.PreserveWhiteSpace = true;
            tp.Fragments.Add(f);

            introPage.Paragraphs.Add(tp);

			if(processImagePath != string.Empty)
			{
				Section imagePage = new Section();
				imagePage.StartOnNewPage = true;
	
				doc.Sections.Add(imagePage);
	
				Image pi = new Image(processImagePath);
				pi.SpacingAfter = 20;
				pi.SpacingBefore = 20;
				pi.KeepAspectRatio = true;
				pi.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
				pi.FitPolicy = FitPolicy.Shrink;
				pi.Caption = "Process diagram";
	
				imagePage.Paragraphs.Add(pi);
			}

        }
        //-------------------------------------------------------------------
        //
        //  Private Methods
        //
        //-------------------------------------------------------------------

        #region Private Methods

        // ------------------------------------------------------------------
        // Determine paragraph type at the current tree position and create it.
        // If going out of scope, return null.
        //
        // Paragraph type is determined using following:
        // (1) if textPointer points to Text, TextParagraph
        // (2) if textPointer points to ElementEnd (end of TextElement):
        //     * if the same as Owner, NULL if fEmptyOk, TextPara otherwise
        // (3) if textPointer points to ElementStart (start of TextElement):
        //     * if block, ContainerParagraph
        //     * if inline, TextParagraph
        // (4) if textPointer points to UIElement:
        //     * if block, UIElementParagraph
        //     * if inline, TextParagraph
        // (5) if textPointer points to TextContainer.End, NULL
        // ------------------------------------------------------------------
        protected virtual BaseParagraph GetParagraph(ITextPointer textPointer, bool fEmptyOk)
        {
            BaseParagraph paragraph = null;

            switch (textPointer.GetPointerContext(LogicalDirection.Forward))
            {
                case TextPointerContext.Text:
                    // Text paragraph

                    // WORKAROUND FOR SCHEMA VALIDATION
                    if(textPointer.TextContainer.Start.CompareTo(textPointer) > 0)
                    {
                        if(!(Element is TextElement) || ((TextElement)Element).ContentStart != textPointer)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.TextSchema_TextIsNotAllowedInThisContext, Element.GetType().Name));
                        }
                    }

                    paragraph = new TextParagraph(Element, StructuralCache);
                    break;

                case TextPointerContext.ElementEnd:
                    // The end of TextElement
                    Invariant.Assert(textPointer is TextPointer);
                    Invariant.Assert(Element == ((TextPointer)textPointer).Parent);

                    if(!fEmptyOk)
                    {
                        paragraph = new TextParagraph(Element, StructuralCache);
                    }
                    break;

                case TextPointerContext.ElementStart:
                    // The beginning of TextElement
                    // * if block, ContainerParagraph
                    // * if inline, TextParagraph
                    Debug.Assert(textPointer is TextPointer);
                    TextElement element = ((TextPointer)textPointer).GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                    if (element is List)
                    {
                        paragraph = new ListParagraph(element, StructuralCache);
                    }
                    else if (element is Table)
                    {
                        paragraph = new TableParagraph(element, StructuralCache);
                    }
                    else if (element is BlockUIContainer)
                    {
                        paragraph = new UIElementParagraph(element, StructuralCache);
                    }
                    else if (element is Block || element is ListItem)
                    {
                        paragraph = new ContainerParagraph(element, StructuralCache);
                    }
                    else if (element is Inline) // Note this includes AnchoredBlocks - intentionally
                    {
                        paragraph = new TextParagraph(Element, StructuralCache);
                    }
                    else
                    {
                        // The only remaining TextElement classes are: TableRowGroup, TableRow, TableCell
                        // which should never go here.
                        Invariant.Assert(false);
                    }
                    break;

                case TextPointerContext.EmbeddedElement:
                    // Embedded UIElements are always part of TextParagraph.
                    // There is no possibility to make UIElement a block.
                    paragraph = new TextParagraph(Element, StructuralCache);
                    break;

                case TextPointerContext.None:
                    // End of tree case.
                    Invariant.Assert(textPointer.CompareTo(textPointer.TextContainer.End) == 0);

                    if (!fEmptyOk)
                    {
                        paragraph = new TextParagraph(Element, StructuralCache);
                    }
                    break;
            }

            if (paragraph != null)
            {
                StructuralCache.CurrentFormatContext.DependentMax = (TextPointer) textPointer;
            }

            return paragraph;
        }
Esempio n. 43
0
        public static void CreateDocument(string title, string subtitle, string description, string author, 
            string processImagePath, List<ScreenImage> images, string outputFileName, bool includeModules)
        {
            Document doc = new Document();
            
            SetupFrontPage(doc, title, subtitle);
            SetupIntroductionPage(doc, subtitle, author, description, processImagePath);

            foreach (ScreenImage si in images)
            {
                Section s = new Section();
                s.StartOnNewPage = true;
                doc.Sections.Add(s);

                TextParagraph tp = new TextParagraph();
                tp.SpacingBefore = 2;
                tp.SpacingAfter = 20;
                s.Paragraphs.Add(tp);

                Fragment f = new Fragment();
                f.Text = si.Title + Environment.NewLine; 
                f.Bold = true;
                f.Font = Font.HelveticaBold;
                f.FontSize = 14;
                f.PreserveWhiteSpace = true;
                tp.Fragments.Add(f);

                f = new Fragment();
                f.Text = "Program path: " + si.Path + Environment.NewLine ;
                f.Bold = true;
                f.Font = Font.Helvetica;
                f.FontSize = 13;
                f.PreserveWhiteSpace = true;
                tp.Fragments.Add(f);

                if (si.ApplicationURL != null)
                {
                    f = new Fragment();
                    f.Text = "URL: " + si.ApplicationURL + Environment.NewLine;
                    f.Bold = true;
                    f.Font = Font.Helvetica;
                    f.FontSize = 13;
                    f.PreserveWhiteSpace = true;
                    tp.Fragments.Add(f);
                }

                f = new Fragment();
                f.Text = si.Notes + Environment.NewLine;
                f.Bold = true;
                f.Font = Font.Helvetica;
                f.FontSize = 13;
                f.PreserveWhiteSpace = true;
                tp.Fragments.Add(f);

                Section imageSec = new Section();
                doc.Sections.Add(imageSec);

                Image i = new Image(si.Bitmap, false);
                i.SpacingBefore = 2;
                i.SpacingAfter = 2;
                i.FitPolicy = FitPolicy.Shrink;

                imageSec.Paragraphs.Add(i);

                if (includeModules)
                {
                    Section modules = new Section();
                    modules.StartOnNewPage = true;
                    doc.Sections.Add(modules);

                    TextParagraph modulesTP = new TextParagraph();
                    modulesTP.SpacingBefore = 2;
                    modulesTP.SpacingAfter = 20;
                    modules.Paragraphs.Add(modulesTP);

                    f = new Fragment();
                    f.Text = "Modules" + Environment.NewLine;
                    f.Bold = true;
                    f.Font = Font.HelveticaBold;
                    f.FontSize = 14;
                    f.PreserveWhiteSpace = true;
                    modulesTP.Fragments.Add(f);

                    if (si.Modules != null)
                    {
                        foreach (string module in si.Modules)
                        {
                            Fragment moduleFrag = new Fragment();
                            moduleFrag.Text = module + Environment.NewLine;
                            moduleFrag.Bold = false;
                            moduleFrag.Font = Font.Courier;
                            moduleFrag.FontSize = 13;
                            moduleFrag.PreserveWhiteSpace = true;
                            moduleFrag.KeepWithNext = false;
                            modulesTP.Fragments.Add(moduleFrag);
                        }
                    }
                }
            }

            using (FileStream fs = new FileStream(outputFileName, FileMode.Create))
            {
                doc.Write(fs);
            }
        }
Esempio n. 44
0
        private static void SetupFrontPage(Document doc, string title, string subtitle)
        {
			if(title == null)
				title = "";
			if(subtitle == null)
				subtitle = "";
			
            ViewerPreferences vp = new ViewerPreferences();
            vp.ZoomFactor = 0.75;
            doc.ViewerPreferences = vp;

            Section mainPage = new Section();
            mainPage.StartOnNewPage = true;

            doc.Sections.Add(mainPage);

			System.Drawing.Bitmap logo = GetOpenSpanLogo();
			if(logo != null)
			{
				Image i = new Image(logo, true);
				i.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
				i.FitPolicy = FitPolicy.Shrink;
				i.Compression = Compression.Auto;
				i.KeepAspectRatio = true;
				i.Actions.Add(new TallComponents.PDF.Layout.Actions.UriAction("www.openspan.com"));
	
				double w = (mainPage.PageSize.Width/2) - (i.Width / 2);
				double h = (mainPage.PageSize.Height/2) - (i.Height / 2);
	
				Area a = new Area(w, mainPage.PageSize.Height, i.Width, mainPage.PageSize.Height);
				a.VerticalAlignment = TallComponents.PDF.Layout.VerticalAlignment.Middle;
				
				mainPage.ForegroundAreas.Add(a);
	
				a.Paragraphs.Add(i);

				TextParagraph tp = new TextParagraph();
				tp.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
				Fragment f = new Fragment();
				f.Text = title;
				f.Font = Font.HelveticaBold;
				f.FontSize = 22;
				f.Bold = true;
				tp.Fragments.Add(f);
				a.Paragraphs.Add(tp);
	
				tp = new TextParagraph();
				tp.HorizontalAlignment = TallComponents.PDF.Layout.HorizontalAlignment.Center;
				f = new Fragment();
				f.Text = subtitle;
				f.Bold = true;
				f.Font = Font.HelveticaBold;
				f.FontSize = 18;
				tp.Fragments.Add(f);
	
				a.Paragraphs.Add(tp);
			}
			
        }