none
How to convert ParagraphVisual to a system.Document.Paragraph in wpf -flow document RRS feed

  • Question

  • hi,

        How can i convert ParagraphVisual  to a system.Document.Paragraph. i need to convert Visual to a Wpf control
    and need to do some modification before rendering .  here is my  code.

     public override DocumentPage GetPage(int pageNumber) {
          DocumentPage page = paginator.GetPage(pageNumber);
          DrawingVisual newpage = new DrawingVisual();
          ContainerVisual header = GetPartVisual();
          newpage.Children.Add(header);
          ContainerVisual footer = new ContainerVisual();
          header.Children.Add(XpsReport.GetFooter(pageSize.Width,pageSize.Height));
         // newpage.Children.Add(footer);
          PageStartsWithTable(paginator.GetPage(pageNumber).Visual);

          ContainerVisual smallerPage = new ContainerVisual();

          smallerPage.Children.Add(page.Visual);
          smallerPage.Transform = new MatrixTransform(1,0,0,1,0,100);
          newpage.Children.Add(smallerPage);
          newpage.Transform = new TranslateTransform(margin.Width,margin.Height);
          return new DocumentPage(newpage,pageSize,page.BleedBox,page.ContentBox);     

        }

       private bool PageStartsWithTable(DependencyObject element)
        {
          ContainerVisual tableVisual;
          tableVisual = null;
          if (element.GetType().Name == "ParagraphVisual")//This is what i need to convert
          {
            // Paragraph paragraph = (Paragraph)element;
          tableVisual = (ContainerVisual)VisualTreeHelper.GetParent(element);
            return true;
          }
          if (VisualTreeHelper.GetChildrenCount(element) > 0) {
            DependencyObject child = VisualTreeHelper.GetChild(element,0);
            if (PageStartsWithTable(child)) {
              return true;
            }
          }
          return false;
        }


     private void LoadContent(string headerText,FlowDocument flow) {
          flow.ColumnWidth = 999999;
          Table content = new Table {CellSpacing = 5};
          TableRowGroup tr= new TableRowGroup();
          Section section = new Section();
          section.Name = "sss1";------------------------------>This is the section(paragraph) which i need to Find out with the name and do  ----------------------------------------------------------------->modification while rendering
          section.Blocks.Add(content);
     
          int columns = 6;
          for (int index = 0;index < columns;index++) {
            TableColumn tableColumn= new TableColumn();
            tableColumn.Name = "sajith";
            tableColumn.Width = new GridLength(110);
            content.Columns.Add(tableColumn);
           // content.Columns[index].Width = new GridLength(110);

            //   TableColumn tableColumn=new TableColumn();

          }

          content.RowGroups.Add(new TableRowGroup());
          content.RowGroups[0].Rows.Add(new TableRow());
          TableRow currentRow = content.RowGroups[0].Rows[0];
          currentRow.Background = Brushes.CornflowerBlue;
          currentRow.Foreground = Brushes.White;
          currentRow.FontFamily = new FontFamily("MS Sans Serif");
          currentRow.FontSize = 20;
          currentRow.FontWeight = FontWeights.Bold;

          currentRow.Cells.Add(new TableCell(new Paragraph(new Run(headerText))));
          currentRow.Cells[0].ColumnSpan = 6;
          currentRow.Cells[0].TextAlignment = TextAlignment.Center;
          currentRow.Cells[0].LineHeight = 30;


          content.RowGroups[0].Rows.Add(new TableRow());
          currentRow = content.RowGroups[0].Rows[1];
          currentRow.FontFamily = new FontFamily("MS Sans Serif");
          currentRow.FontSize = 14;
          currentRow.FontWeight = FontWeights.Bold;
          currentRow.Background = Brushes.Gainsboro;

          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Stage+ccccccccccccc"))));
          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Duration-Heading"))));
          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Elapsed"))));
          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Speed"))));
          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Grade(%)"))));
          currentRow.Cells.Add(new TableCell(new Paragraph(new Run("HR (bpm)"))));

          for (int index = 2;index < 200;index++) {
            content.RowGroups[0].Rows.Add(new TableRow());
            currentRow = content.RowGroups[0].Rows[index];
            currentRow.FontFamily = new FontFamily("MS Sans Serif");
            currentRow.FontSize = 14;

            if (index % 2 == 0)
              currentRow.Background = Brushes.MistyRose;

            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Stage" + index.ToString()))));
            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Duration"))));
            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Elapsed"))));
            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Speed"))));
            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Grade(%)"))));
            currentRow.Cells.Add(new TableCell(new Paragraph(new Run("HR (bpm)"))));
          }

          flow.Blocks.Add(section);
        }

    ///////////////////////////////////////////////////////////////////////////////////////

    Here i need to get the paragraphvisual and need to itrate through the RowVisual and do the modification.


                
    • Edited by sajithtgs Wednesday, February 22, 2012 12:17 PM
    Wednesday, February 22, 2012 10:22 AM

Answers

  • thanks  Sheldon,

        i will start new thread.Code project stuff is ok but it does not serve my needs.

    Regards,

    sajith

    • Marked as answer by sajithtgs Saturday, March 3, 2012 1:04 PM
    Monday, February 27, 2012 8:45 AM

All replies

  • Hi sajithtgs,

    No, we could not convert ParagraphVisual to Paragraph, becasue ParagraphVisual is the presentation of Paragraph, if you want to complete convert, you have to get the data of ParagraphVisual, however, this data is internel, we could not get it.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 23, 2012 9:36 AM
    Moderator
  • thankyou sheldon,

      ur absolutely correct.i found that.i have a  question  how can we do custome pagination

    in flow document i had writtern custome pagination but i have no clue how to add

    section headers and table  headers when the rows flows to next page.

    Regards,

    sajith

    Saturday, February 25, 2012 12:13 PM
  • Hi sajithtgs,

    I suggest you could strar a new thread for your new question, then more people could jump in and provide you more helpful information, additional, you could refer to below links:

    http://msdn.microsoft.com/en-us/library/system.windows.documents.documentpaginator.aspx

    http://www.codeproject.com/Articles/31834/FlowDocument-pagination-with-repeating-page-header

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 7:14 AM
    Moderator
  • thanks  Sheldon,

        i will start new thread.Code project stuff is ok but it does not serve my needs.

    Regards,

    sajith

    • Marked as answer by sajithtgs Saturday, March 3, 2012 1:04 PM
    Monday, February 27, 2012 8:45 AM