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

create titles before exporting to pdf

15 Answers 175 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vasya Ivanov
Top achievements
Rank 1
Vasya Ivanov asked on 29 Dec 2010, 07:27 PM

Hi guys,
before I export grid to pdf I need to write couple of titles lines include header from another grid.My pdf format should look like this:
Title: NYC DEPT OF EDUCATION
        BUREAU OF COMPENSATION
        ROSTER - 9/08 thru 06/09
 Header coming from another grid:
        TOTAL DAYS - 80 TOTAL AMOUNT - 1900
 And then detail data which I exporting to PDF.

Please help me with that issue.So far I only have the following code:
PriReportGrid.ExportSettings.Pdf.PageTitle = "NEW YORK CITY DEPT.OF EDUCATION ";
PriReportGrid.MasterTableView.ExportToPdf();

 

 

Thanks so much      

15 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Dec 2010, 08:38 AM
Hello Vasya,

You can insert custom bits of HTML in the PdfExporting event.
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
{
    e.RawHTML ...
}

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 30 Dec 2010, 04:22 PM
Hi Daniel,
can you be more specific and provide for me  example in pdf exporting event how to create multiple title lines.

Thanks so much for your help..
0
Daniel
Telerik team
answered on 30 Dec 2010, 05:00 PM
Hello Vasya,

Here is a sample code-snippet:
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
{
    e.RawHTML = "<div>Line1</div><div>Line2</div>" + e.RawHTML;
}

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 30 Dec 2010, 09:31 PM
Thanks Daniel,
it is working,however its working only for constant title.If I want to include some data in the title.For example if I have a DataTable consisting of dates and I want to create a title included that dates.
How can I do that.

Thanks again and Happy New Year.
0
Daniel
Telerik team
answered on 30 Dec 2010, 10:40 PM
Hello Vasya,

You have the complete freedom to build your custom HTML code in the way you prefer. For instance, you can traverse your table, add the results to a StringBuilder, and then pass the generated string to the RawHTML property.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 04 Jan 2011, 09:51 PM
Thanks Daniel for your help.I have created stringbuilder:

 

StringBuilder sb = new StringBuilder();

 

sb.AppendLine(

"<div>NEW YORK CITY DEPT.OF EDUCATION</div>");

 

sb.AppendLine(

"<div>BUREAU OF PEDAGOGIC COMPENSATION</div>");

 

sb.AppendLine(

"PER DIEM ROSTER");

 

sb.AppendLine(DateFrom.ToShortDateString());

sb.AppendLine(

" ");

 

sb.AppendLine(

"THRU");

 

sb.AppendLine(

" ");

 

sb.AppendLine(DateTo.ToShortDateString());

sb.AppendLine(

"<div>Eis-Id:");

 

sb.AppendLine(HeaderData.Rows[0][3].ToString());

sb.AppendLine(

"Name:");

 

sb.AppendLine(HeaderData.Rows[0][0].ToString() + HeaderData.Rows[0][1].ToString());

sb.AppendLine(

"</div>");

 

sb.AppendLine(

"<div>Empl-Id:");

 

sb.AppendLine(HeaderData.Rows[0][3].ToString());

sb.AppendLine(

"Total Days:");

 

sb.AppendLine(HeaderData.Rows[0][4].ToString());

sb.AppendLine(

"Total Amount:");

 

sb.AppendLine(

"$" + String.Format("{0:C}", HeaderData.Rows[0][5].ToString()));

 

sb.AppendLine(

"</div>");

 

e.RawHTML = sb + e.RawHTML;

My questions is:How can I apply style to this titles.I need set different colors.

As always thanks for your help.

0
Daniel
Telerik team
answered on 04 Jan 2011, 10:58 PM
Hello Vasya,

Just add the desired inline styles to the DIV element. Simplified code-snippet is available below:
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
{
    e.RawHTML = "<div style='color: #606010; background-color: #88afea; font-weight: bold;'>this is a test</div>" + e.RawHTML;
}

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 13 Jan 2011, 10:12 PM
Thanks Daniel,its working.But I have another question.
I have a string builder:

sb.AppendLine(

"Total Amount:");

 

sb.AppendLine(

"$" + String.Format("{0:C}", HeaderData.Rows[0][5].ToString()));

 

sb.AppendLine(

"</div>");

 

sb.AppendLine(

"<div style='color: #008040; font-style:bold; font-size:12px'>Location:");

 

sb.AppendLine((

string)ViewState["SelectedLocation"]);

 


I want to put blank line between two titles after sb.AppendLine("</div>");
How can I do that.
Thanks so much for your help.
0
Daniel
Telerik team
answered on 18 Jan 2011, 05:12 PM
Hello Vasya,

The easiest way would be to insert a paragraph element:
<p></p>

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 28 Jan 2011, 04:55 PM
Thanks so much for your help Daniel.
I have another question for you:
I have a radgrid with a negative amount (for example -$1117.04) and I try to export to excel.In excel this field is displaying in red color and in parentnesis like this ($1117.04).I know that is the way radgrid is exporting but my users do not undastand that and want to see this number as negative number like this: -$1117.04.

How can I do that.
Thanks so much..
0
Daniel
Telerik team
answered on 28 Jan 2011, 10:47 PM
Hello Vasya,

You could choose different approach depending on the Excel format you use:
1) HTML - Word/Excel export (HTML-based)
2) ExcelML - ExcelML basics

Let me know if you need any specific instructions

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 31 Jan 2011, 04:39 PM
Hi Daniel,
I am using ExcelML format.Please,can you give me a example how to export negative number and display negative number in excel spreadsheet.

As always thank you very much for your help.
0
Daniel
Telerik team
answered on 31 Jan 2011, 05:18 PM
Hello Vasya,

Ok, I attached a demo project to this post. Let me know whether this helps.

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vasya Ivanov
Top achievements
Rank 1
answered on 01 Feb 2011, 05:08 PM

Hi Daniel,
I am sorry I should be more specific on this.
I have a following code:
<telerik:GridBoundColumn HeaderText="Available" DataField="MONEYLEFT" UniqueName="MONEYLEFT" ReadOnly="True" DataFormatString="{0:$#####.#0}" SortExpression="MONEYLEFT" HeaderButtonType="TextButton">

 

 

 

<HeaderStyle Width="60px" />

 

 

 

<ItemStyle Width="60px" />

 

 

 

/telerik:GridBoundColumn>

(Look at the dataformatstring) in the grid its appeared as negative but when I am exporting to Excel it looks like this:(1711.85).
Thanks for your help.
P.S.Also I forgot to mentioned this grid in the user control.

 

0
Daniel
Telerik team
answered on 04 Feb 2011, 06:10 PM
Hello Vasya,

The DataFormatString will not affect the exported file when you use the ExcelML format.

Please try the following custom format:
style.NumberFormat.FormatType = NumberFormatType.General;
style.NumberFormat.Attributes["ss:Format"] = "#;-#";

Alternatively you could use one of the predefined number formats. See the Number Formats section in the ExcelML export help topic for more information.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Vasya Ivanov
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Vasya Ivanov
Top achievements
Rank 1
Share this question
or