Export RadGridView data to PDF and pagging

7 posts, 0 answers
  1. Sheraz
    Sheraz avatar
    5 posts
    Member since:
    Nov 2007

    Posted 28 Jan 2015 Link to this post

    Hi

    Want to export RadGridView data to PDF document. Tried to do this by following link below

    http://demos.telerik.com/silverlight/#GridView/PrintAndExportWithRadDocument

    Able to export and format document but unable to display grid header on each page. Need your assistance on this.

    I am using .net 4.0 and Telerik version: UI for WPF Q3 2014

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Jan 2015 Link to this post

    Hi Sheraz,

    I could suggest to you to run through the "Export RadGridView to Pdf and excel and add header and footer to pdf document" forum thread for a reference.

    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Sheraz
    Sheraz avatar
    5 posts
    Member since:
    Nov 2007

    Posted 30 Jan 2015 in reply to Maya Link to this post

    Hi Maya

    Able to display grid header on all pages by use of separate headers for first and other pages. But there is space between header and table on pages other than first. Please give suggestion in this regard

    I have used code for this purpose.

     var document = CreateDocument(grid, settings);

    document.LayoutMode = DocumentLayoutMode.Paged;
    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

    document.SectionDefaultPageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Portrait;
    document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(10, 0, 10, 10);

    Section gridSection = document.Sections.First;
    gridSection.HasDifferentFirstPageHeaderFooter = true;

    Table gridTable = (Table)gridSection.Blocks.First;

    Header header = new Header();
    Header firstHeader = new Header();
    Footer footer = new Footer();

    header = GetHeader(grid, gridTable);
    firstHeader = GetFirstHeader();
    footer = GetFotter();

    gridSection.Headers.Default = header;
    gridSection.Footers.Default = footer;
    gridSection.Headers.First = firstHeader;
    gridSection.Footers.First = footer;

    IDocumentFormatProvider provider = null;

    if (settings.Format == ExportFormat.Pdf)
    provider = new PdfFormatProvider();
    else if (settings.Format == ExportFormat.Word)
    provider = new DocxFormatProvider();

    using (var output = dialog.OpenFile())
    {
    provider.Export(document, output);
    }

    private static Header GetHeader(this RadGridView grid,Table gridTable)
    {
    RadDocument headerDocument = new RadDocument();
    RadDocumentEditor editor = new RadDocumentEditor(headerDocument);

    editor.InsertParagraph();
    editor.ChangeParagraphListStyle(null);
    editor.Insert(DateTime.Now.ToShortDateString());

    editor.InsertParagraph();

    Size imgSize = new Size(60, 60);
    using (Stream stream = Application.GetResourceStream(GetResourceUri("Images/MapView.png")).Stream)
    {
    ImageInline image = new ImageInline(stream, imgSize, "png");
    editor.InsertInline(image);
    }
    editor.ChangeParagraphTextAlignment(RadTextAlignment.Left);

    editor.InsertParagraph();
    StyleDefinition titleStyle = new StyleDefinition("Title", StyleType.Paragraph);
    titleStyle.ParagraphProperties.TextAlignment = RadTextAlignment.Center;
    titleStyle.SpanProperties.FontSize = 35;
    titleStyle.SpanProperties.ForeColor = Colors.CornflowerBlue;
    titleStyle.NextStyleName = RadDocumentDefaultStyles.NormalStyleName;

    editor.Document.StyleRepository.Add(titleStyle);
    editor.ChangeStyleName("Title");
    editor.Insert("Report Title");

    TableRow gridTabRow = gridTable.Rows.First();
    TableRow nTabRow = gridTabRow.CreateDeepCopy() as TableRow;

    Table hTab = new Table();
    hTab.Borders = gridTable.Borders;

    hTab.Rows.Add(nTabRow);
    editor.InsertTable(hTab);

    editor.UpdateAllFields(FieldDisplayMode.Result);

    Header header = new Header() { Body = headerDocument };
    return header;
    }


    Regards

    Sheraz
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Feb 2015 Link to this post

    Hi Sheraz,

    Could you clarify a bit on your exact requirement ? Is the picture you attached on your pages that you want to modify ? Do you want the "Report Title" to be closer to the grid ? 

    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Sheraz
    Sheraz avatar
    5 posts
    Member since:
    Nov 2007

    Posted 05 Feb 2015 in reply to Maya Link to this post

    No. Upper table is part of page header and lower table is part of page body. I want to reduce vertical space between these two tables as mentioned in attached Req_page2.png
  6. Tanya
    Admin
    Tanya avatar
    853 posts

    Posted 09 Feb 2015 Link to this post

    Hi Sheraz,

    When inserting a table in RadRichTextBox, a paragraph is inserted after it. Currently, we are working on removing this paragraphs and will release the new version with Q1 2015, which is scheduled for the end of this month.

    Meanwhile, you can reduce the height of these paragraphs by setting the RadRichTextBox's FontSize property to 0 and decreasing the SpacingBefore and SpacingAfter properties:
    IEnumerable<Table> tables = this.radRichTextBox.Document.EnumerateChildrenOfType<Table>();
    foreach (var table in tables)
    {
        this.radRichTextBox.Document.CaretPosition.MoveToEndOfDocumentElement(table);
        this.radRichTextBox.Document.CaretPosition.MoveDown();
        this.radRichTextBox.ChangeFontSize(0);
        this.radRichTextBox.ChangeParagraphSpacingAfter(0);
        this.radRichTextBox.ChangeParagraphSpacingBefore(0);
    }

    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Sheraz
    Sheraz avatar
    5 posts
    Member since:
    Nov 2007

    Posted 12 Feb 2015 in reply to Tanya Link to this post

    Ok Thanks. Will wait for Q1 2015

    Regards

    Sheraz
Back to Top