This is a migrated thread and some comments may be shown as answers.

Formatting the Grid export to PDF

17 Answers 1691 Views
Grid
This is a migrated thread and some comments may be shown as answers.
robert
Top achievements
Rank 1
robert asked on 09 Apr 2008, 12:22 AM
I saw a post in Todd Anglin's blog from September about how to format output (font size, etc) of a grid export to PDF.  But I tried the suggestion and the suggested code had no effect on the output.  Is there anywhere I can go for a better discussion of this?

17 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 09 Apr 2008, 08:10 AM
Hi Robert,

This help article contains working code for formatting the output of exported pdf file ("RadGrid formatting and PDF export" section. You can use it as a starting point for your page and let us know if further help is needed.

All the best,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
robert
Top achievements
Rank 1
answered on 09 Apr 2008, 03:42 PM
I read the article and the only thing that worked for formatting PDF output was putting code in the itemcreated event to change the style, so I guess I'll use that method.

Before rebinding, I tried the following line of code:
gridList.HeaderStyle.Font.Size = New FontUnit(8, UnitType.Point)
but this had no effect.  The article said that changing HeaderStyle or ItemStyle would work, but apparently it does not.

Thanks for your help,
Bob Reader
0
Steve
Telerik team
answered on 10 Apr 2008, 09:49 AM
Hello Robert,

Indeed it seems that these settings in the markup are not persisted in the export. I've logged the issue in our bug tracking system and we will investigate what is causing it. Your Telerik points have been updated for pointing this out.

Regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
robert
Top achievements
Rank 1
answered on 10 Apr 2008, 04:10 PM
I have also noticed that using the other way of formatting PDF output does not work with certain style settings, but does with others.  For example, the following line of code works, where "item" is a GridItem of type Item: 

item.Style("font-size") = "10pt"

But setting the following does not work:

item.Style("font-weight") = "bold"
item.Style("font-family") = "arial" 
cell.Style("text-decoration") = "underline"

Are there just a subset of style settings that are rendered?

Regards,
Bob
0
Accepted
Vlad
Telerik team
answered on 15 Apr 2008, 12:53 PM
Hi Robert,

Here is a bit different technique how to achieve desired result:

<%@ Page Language="VB" %> 
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<script runat="server"
    Private isPdfExport As Boolean = False 
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand 
        If e.CommandName = RadGrid.ExportToPdfCommandName Then 
            isPdfExport = True 
            RadGrid1.Rebind() 
        End If 
    End Sub 
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound 
        If isPdfExport AndAlso TypeOf e.Item Is GridDataItem Then 
            Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
 
            For Each cell As TableCell In dataItem.Cells 
                Dim text As StringString = String.Format("<span style='font-weight:bold;font-family:arial;text-decoration:underline;color:red;'>{0}</span>", cell.Text) 
                cell.Text = text 
            Next 
        End If 
    End Sub 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        RadGrid1.DataSource = New Object() {1, 2, 3} 
    End Sub 
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <telerik:RadGrid ID="RadGrid1" Skin="" runat="server"
                <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" /> 
                <MasterTableView Width="100%" CommandItemDisplay="Top"
                    <CommandItemTemplate> 
                        <asp:LinkButton ID="LinkButton1" Text="Export" CommandName="ExportToPdf" runat="server" /> 
                    </CommandItemTemplate> 
                </MasterTableView> 
            </telerik:RadGrid> 
        </div> 
    </form> 
</body> 
</html> 
 


All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Potter
Top achievements
Rank 1
answered on 10 Jul 2008, 06:49 PM
Hello all,
I am exporting my Web Grid form a Web Page to a PDF format. I am not using the events from the Grid in order to intercept the export. I am clicking a button in order to export my grid to a PDF. Is there a way to format my grid before being exported? I have set several properties using the following code.
//setup PDF
        this.RadGrid1.ExportSettings.Pdf.AllowPrinting = true;
        this.RadGrid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter;
        this.RadGrid1.ExportSettings.Pdf.PageWidth = 1500;
        this.RadGrid1.ExportSettings.Pdf.PageTitle = "Users";
        this.RadGrid1.ExportSettings.Pdf.AllowModify = true;
        this.RadGrid1.ExportSettings.Pdf.AllowCopy = true;
        this.RadGrid1.ExportSettings.Pdf.FontType = Telerik.Web.Apoc.Render.Pdf.FontType.Embed;

However, I can't use the other examples of the events ItemCommand and ItemDataBound to intercept the grid items. I need to setup the column widths so my PDF displays correctly. Currently, my data is overlapping the other columns next to it.

Thanks,
Wayne
0
Steve
Telerik team
answered on 11 Jul 2008, 08:54 AM
Hello Mark,

Try the following:

RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse( "162mm" );
RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse( "600mm" );

This would basically force the pdf file export with landscape orientation.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Andrew
Top achievements
Rank 1
answered on 08 Jan 2009, 01:49 AM
I have tried the above example (wrapping a styled span around the cell content), it only partly works.

It seems that your HTML to PDF conversion does not respect all possible styles, for example the text-transform:uppercase; and the attempt to change font. This is despite the HTML being rendered properly.

I also note that the table layout does not respect percentage column widths. Setting widths in pixels results in the expected differences in column widths, but using percentages (which on screen provides for nice resizing as the window changes size), means all columns come out the same size on the PDF.

Also I note that the HTML for a table with gridlines uses "border="1", but the lines are hardly 1 pixel wide when they get to the PDF - this makes the PDF rather ugly. There is absolutely no control over whether a boarder is palced around the PDF content (and it is an even thicker line than the grid lines).

Further for some reason there is a blank row of cells being added in the table header (under the column titles) - presumably some other "Item" from the grid is being rendered (filters, or whatever).

Having worked through the support pages on the subject of getting a nice PDF out of the export from the Grid, I note that there seems to be a policy that pretty reports are to be produced from the Telerik Reporting system. Now whist this is an excellent reporting system, it has a lot of limitations.

Specifically using a RadGrid to display what is essentially a report, the user can fiddle about - dropping unwanted columns, selecting filters sort orders and groupings, changing column widths (which incidentally seem to then switch to pixel based sizing) and column orders, and then generate a PDF which can be printed - except at teh moment, the PDF leaves a lot to be desired.

With some clever background code to collect the user's layout decisions and persist them to a data store, it is then possible to re-produce the same layout in the future for the user - you even give a worked example of how to do this with user profiles.

Of course this does not replace all reporting needs, but I would prefer to provide the users with a small set of reports which can be tailored to their particular preferenes by themselves. Often they won't even need to print the thing since the on screen grid is an excellent presentation tool, but it is nice to be able to get a decent hard copy (or something that can be emailed), when wanted.

Is there any chance that a more complete HTML-PDF rendering engine will be provided?

And on that subject, what about PDF export of grids with templated content?
0
Yavor
Telerik team
answered on 10 Jan 2009, 11:56 AM
Hello Andrew,

Thank you for your feedback. Indeed, you do make some good points, as the pdf exporting functionality can be further improved. I will pass your comments/suggestions to our developers, for further consideration. Should they find a feasible way to implement them, these improvements will be available in one of the upcoming versions of the control.
For some of the styles which can be altered when exporting, please review the following article. It also contains a work-around for exporting template columns data.
I hope this information helps.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Duc
Top achievements
Rank 1
answered on 22 Jan 2009, 09:35 PM
Hi Steve,

Just wondering if the header styling not being rendered in the PDF is still an issue? If not which version was it resolved in?

Thanks
Duc
0
Yavor
Telerik team
answered on 26 Jan 2009, 12:00 PM
Hello Duc,

Attached to this message, is a small application, which handles a similar task.
I hope it helps.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Duc
Top achievements
Rank 1
answered on 26 Jan 2009, 03:24 PM
Hi Yavor,

Is there a way to change the font of the header? That's what I'm really after. I tried this:

headerItem.Style["font-family"] = "arial";

and other fonts too, but none of them seem to have any affect on the exported PDF. (Word and excel are fine).

Thanks
Duc
0
Yavor
Telerik team
answered on 27 Jan 2009, 09:59 AM
Hi Duc,

Attached to this message, is small application, which also alters the font names.
Please, note that there is an issue with the Arial setting (we are currently working on it), but most other types are picked up.
I hope this helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Yavor
Telerik team
answered on 27 Jan 2009, 11:06 AM
Hello Duc,

As a quick follow up on the previous post, attached to this message, is a modification of the code supplied earlier, to cater for the "arial" setting as well.
I hope this helps.

Best wishes,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Steve
Top achievements
Rank 1
answered on 27 Feb 2011, 08:38 PM
What is the point of deleting attachments after two years? Furthermore why does your send email link go to an invalid email address?
0
Daniel
Telerik team
answered on 02 Mar 2011, 10:59 PM
Hello Steve,

I'm not sure that I understand what exactly do you mean. Could you please elaborate?

Regards,
Daniel
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jorge
Top achievements
Rank 1
answered on 27 Aug 2011, 03:27 AM
This can easily save your day.

The default page orientation for the PDF file is Portrait. You can easily switch to Landscape by modifying the PageWidth / PageHeight properties manually.

  • A4 Portrait<Pdf PageWidth="210mm" PageHeight="297mm" />
  • A4 Landscape<Pdf PageWidth="297mm" PageHeight="210mm" />
regards,
Tags
Grid
Asked by
robert
Top achievements
Rank 1
Answers by
Steve
Telerik team
robert
Top achievements
Rank 1
Vlad
Telerik team
Mark Potter
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Yavor
Telerik team
Duc
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Daniel
Telerik team
Jorge
Top achievements
Rank 1
Share this question
or