Hello Telerik,
I want to export a file.txt to Pdf, I´m using GridViewPdfExport component but this line does not work:
Telerik.WinControls.Export.PdfExportRenderer renderer = new Telerik.WinControls.Export.PdfExportRenderer();
This is my code , taken from Export to PDF
Telerik.WinControls.Export.GridViewPdfExport pdfExporter =
new
Telerik.WinControls.Export.GridViewPdfExport(radGrid1);
pdfExporter.FileExtension =
".pdf"
;
pdfExporter.ShowHeaderAndFooter =
true
;
pdfExporter.HeaderHeight = 30;
pdfExporter.HeaderFont =
new
Font(
"Arial"
, 22);
pdfExporter.Logo = System.Drawing.Image.FromFile(@
"C:\temp\logo.png"
);
pdfExporter.LeftHeader =
"[Logo]"
;
pdfExporter.LogoAlignment = ContentAlignment.MiddleLeft;
pdfExporter.LogoLayout = Telerik.WinControls.Export.LogoLayout.Fit;
pdfExporter.MiddleHeader =
"Middle header"
;
pdfExporter.RightHeader =
"Right header"
;
pdfExporter.ReverseHeaderOnEvenPages =
true
;
pdfExporter.FooterHeight = 30;
pdfExporter.FooterFont =
new
Font(
"Arial"
, 22);
pdfExporter.LeftFooter =
"Left footer"
;
pdfExporter.MiddleFooter =
"Middle footer"
;
pdfExporter.RightFooter =
"Right footer"
;
pdfExporter.ReverseFooterOnEvenPages =
true
;
pdfExporter.SummariesExportOption = SummariesOption.ExportAll;
pdfExporter.FitToPageWidth =
true
;
pdfExporter.Scale = 1.2;
pdfExporter.ExportSettings.Title =
"Prueba"
;
string
exportFile = @
"..\..\exportedData.pdf"
;
using
(System.IO.MemoryStream ms =
new
System.IO.MemoryStream())
{
Telerik.WinControls.Export.GridViewPdfExport exporter =
new
Telerik.WinControls.Export.GridViewPdfExport(radGrid1);
Telerik.WinControls.Export.PdfExportRenderer renderer =
new
Telerik.WinControls.Export.PdfExportRenderer();
exporter.RunExport(ms, renderer);
using
(System.IO.FileStream fileStream =
new
System.IO.FileStream(exportFile, FileMode.Create, FileAccess.Write)){
ms.WriteTo(fileStream);}
}
Thanks in advance.
25 Answers, 1 is accepted
Thank you for writing.
You do not need to use the grid to convert text files to pdf. You can just use the WordsProcessing library. Detailed information is available here:
Nevertheless, could you please share the error message observed on your side? You code compiles without errors on mine.
I am looking forward to your reply.
Dimitar
Telerik by Progress
Hi Dimitar,
It works, but I now have another problem
My RadGridView does not load any information, I use this
DataTable dt =
new
DataTable();
dt = objAdmin.Sales();
RadGridView radGrid1 =
new
RadGridView();
radGrid1.AutoGenerateColumns =
true
;
radGrid1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGrid1.MasterTemplate.DataSource = dt;
Are you adding the grid to the form or you want to export the data without showing it? If this is the case you need to call the LoadElementTree method and set the BindingContext manually:
RadGridView radGrid1 =
new
RadGridView();
radGrid1.AutoGenerateColumns =
true
;
radGrid1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGrid1.MasterTemplate.DataSource = dt;
radGrid1.BindingContext =
this
.BindingContext;
radGrid1.LoadElementTree();
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
You need to make sure that the System.Windows.Forms assembly is referenced. In addition, since you do not have a form you need to create a binding context:
radGrid1.BindingContext =
new
BindingContext();
I hope this will be useful.
Regards,
Dimitar
Telerik by Progress
It´s work , thanks a lot.
Gustavo
Telerik.WinControls.Export.GridViewPdfExport pdfExporter =
new
Telerik.WinControls.Export.GridViewPdfExport(DgvTrialBalance);
pdfExporter.FileExtension =
".pdf"
;
pdfExporter.ShowHeaderAndFooter =
true
;
pdfExporter.HeaderHeight = 30;
pdfExporter.HeaderFont =
new
Font(
"Arial"
, 22);
//pdfExporter.Logo = System.Drawing.Image.FromFile(@"C:\temp\logo.png");
//pdfExporter.LeftHeader = "[Logo]";
//pdfExporter.LogoAlignment = ContentAlignment.MiddleLeft;
//pdfExporter.LogoLayout = Telerik.WinControls.Export.LogoLayout.Fit;
pdfExporter.MiddleHeader =
"Middle header"
;
pdfExporter.RightHeader =
"Right header"
;
pdfExporter.ReverseHeaderOnEvenPages =
true
;
pdfExporter.FooterHeight = 30;
pdfExporter.FooterFont =
new
Font(
"Arial"
, 22);
pdfExporter.LeftFooter =
"Left footer"
;
pdfExporter.MiddleFooter =
"Middle footer"
;
pdfExporter.RightFooter =
"Right footer"
;
pdfExporter.ReverseFooterOnEvenPages =
true
;
pdfExporter.SummariesExportOption = SummariesOption.ExportAll;
pdfExporter.FitToPageWidth =
true
;
pdfExporter.Scale = 1.2;
pdfExporter.ExportSettings.Title =
"Prueba"
;
string
exportFile = @
"..\..\exportedData.pdf"
;
using
(System.IO.MemoryStream ms =
new
System.IO.MemoryStream())
{
Telerik.WinControls.Export.GridViewPdfExport exporter =
new
Telerik.WinControls.Export.GridViewPdfExport(DgvTrialBalance);
PdfExportRenderer renderer =
new
Telerik.WinControls.Export.PdfExportRenderer();
exporter.RunExport(ms , renderer);
using
(System.IO.FileStream fileStream =
new
System.IO.FileStream(exportFile, FileMode.Create, FileAccess.Write))
{
ms.WriteTo(fileStream);
}
}
[quote]Dimitar said:Hi Gustavo,
Thank you for writing.
You need to add a reference to the TelerikExport assembly. This is noted at the begging of the article.
In addition, you can use our WordsProcessing library to convert such files, you do not need a UI component for this: WordsProcessing.
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
[/quote]Hello Dimitar,
I want to export a file.txt to Pdf, I´m using GridViewPdfExport component but this line does not work:
exporter.RunExport(ms , renderer);
I have this error
Thanks in advence
Please note that you do not need the grid exporter in order to convert such files. You can just use the WordsProcessing library. Detailed information is available here:
In addition, I cannot see the error message. Could you please specify it again? Your code compiles without errors on my side.
I am looking forward to your reply.
Dimitar
Telerik by Progress
Hello Dimitar,
I have error message in there in my memeorystream variable its like below
Thanks in advence
jamsheer
I have error message in there in my memeorystream variable its like below
Thanks in advence
jamsheer
The method overload that accepts stream was introduced in R2 2016 SP1 (version 2016.2.608). So you need this or newer version in order to export to a stream.
Please note that you can pass the file name and path directly and export the grid, the stream is used for some cases where you do not want to create a file.
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
Hello Dimitar,
I overcome that Issue ,Thanks a lot.
Now I want to export my RadGridview to Word file also,How could I do ?
Thanks in advance
jamsheer
There is no built-in exporter that can export to the format. However, this can be achieved and we have an example of it in our demo application (see attached image).
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
Hello Dimitar,
How could I convert my RadPrintDocument values to RadFlowDocument, because when export RadGridview to docx file or text file there we are using RadFlowDocument.
Where I exported successfully to pdf,xlsx,xls formats, The above issue when exporting to those formats (docx and txt)
If you can attach example project or sample codes
Thanks in advance
jamsheer
There is no way to convert RadPrintDocumet to RadFlowDocument.
I do not understand what is your exact requirement. So could you please specify what exactly you want to achieve and why you want to convert these document types?
I am looking forward to your reply.
Regards,
Dimitar
Telerik by Progress
Hello Dimitar,
I tried to export Radgridview to Docx file ,but i didnt get the output .
can u please attach example codes or sample projects
Thanks in advance
jamsheer
Hello Dimitar,
I have getting duplicate value to my radprintpreview from a grouped radfridview (Actually there i grouped two columns name as ledgergroup and groupname , some ledgergroup have same groupname because of that its getting duplication ,In this pic look the second marked fields where "sales is a ledgergroup and the groupname also same as ledgergroup name as sales")
i want to avoid that duplicate name at this case.
Thanks in advance
jamsheer
We have an example that shows how you can export to format in our demo application. You can directly copy the code as well (see attached image).
In addition, I am not sure how to reduce the issue with the groups printing. This is why I want to kindly ask you to open a separate thread for this and add the code of your form. This will allow us to properly investigate this and provide you with a solution.
I hope this will be useful.
Regards,
Dimitar
Telerik by Progress
Hello Dimitar,
I want to show printdialog with the all details of print preview without using print preview ,where i created class for Header and footer .
I can get that with this code (this.Raddatagridview.Print(true);),but there i didnt get Header and footer
how could i get it ?
Thanks in advance
jamsheer
Hello ,
I got the answer where i used this:
DgvTrialBalance.Print(
true
, RadPrintDocument1);
Thanks,
I am glad that you have found a solution for this. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
Hello Dimitar,
I want to create a new row at top of my Radgrid look like below.
where my Radgrid grouping is true
Thanks in advance
jamsheer
Hello Dimitar,
How could I change the color of Pinned row of Radgrid,where I have lot of summary rows and I pinned the last total value of my documents .
Where I used to Pinned Row with this code,
this.DgvTrialBalance.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Bottom;
I want to change the color where I red marked in the below pic.
Expecting your help,
Thanks in advance
jamsheer
Hello Dimitar,
Expecting your help for those questions.
Thanks in advance
jamsheer
1. You can use Column Groups View to create such layout.
2. Use the ViewCellFormatting event to change the styles of the summary cells:
private
void
RadGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridSummaryCellElement)
{
e.CellElement.DrawFill =
true
;
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.CellElement.BackColor = Color.Red;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
}
}
Off topic, I want to mention that these questions are not related to the original subject of this thread. I want to kindly ask you to use relevant or open new threads for unrelated questions. In addition, could please use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one.
Thank you for your understanding.
Regards,
Dimitar
Telerik by Progress