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
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
6 Answers, 1 is accepted
0
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
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.
0
Sheraz
Top achievements
Rank 1
answered on 30 Jan 2015, 07:21 AM
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
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
0
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
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.
0
Sheraz
Top achievements
Rank 1
answered on 06 Feb 2015, 05:37 AM
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
0
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:
Hope this helps.
Regards,
Tanya
Telerik
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.
0
Sheraz
Top achievements
Rank 1
answered on 12 Feb 2015, 10:10 AM
Ok Thanks. Will wait for Q1 2015
Regards
Sheraz
Regards
Sheraz