Hi,
I would like to programmatically do an export of my multi-paged report to PNG format, i.e. the end result should be 3 PNG files for a 3 paged report and so on. Is it possible to do this? And can I specify the filenames for each file programmatically or is it auto-generated? The whole process should be transparent to the end-user, i.e. I do not want the end user to click on the Export button and type in the file name in the File Dialog that pops up. Instead the program should do an auto-export to the required format and use names such as "Report1_pg1.png", "Report1_pg2.png" etc... Hope you can help me on this. Thanks.
I would like to programmatically do an export of my multi-paged report to PNG format, i.e. the end result should be 3 PNG files for a 3 paged report and so on. Is it possible to do this? And can I specify the filenames for each file programmatically or is it auto-generated? The whole process should be transparent to the end-user, i.e. I do not want the end user to click on the Export button and type in the file name in the File Dialog that pops up. Instead the program should do an auto-export to the required format and use names such as "Report1_pg1.png", "Report1_pg2.png" etc... Hope you can help me on this. Thanks.
3 Answers, 1 is accepted
0
Hello Ring,
You can export each page of the report to a separate png file. The Render Report method has an overload with CreateStream callback method. Here is a simple code snippet which illustrates the approach:
Greetings,
IvanY
the Telerik team
You can export each page of the report to a separate png file. The Render Report method has an overload with CreateStream callback method. Here is a simple code snippet which illustrates the approach:
List<Stream> streams =
new
List<Stream>();
void
RenderReport()
{
var reportProcessor =
new
ReportProcessor();
var documentName =
""
;
var deviceInfo =
new
Hashtable();
deviceInfo[
"OutputFormat"
] =
"JPEG"
;
reportProcessor.RenderReport(
"IMAGE"
,
new
ReportCatalog(), deviceInfo,
this
.CreateStream,
out
documentName);
this
.CloseStreams();
}
void
CloseStreams()
{
foreach
(var stream
in
this
.streams)
{
stream.Close();
}
this
.streams.Clear();
}
public
Stream CreateStream(
string
name,
string
extension, Encoding encoding,
string
mimeType)
{
const
string
path = @
"C:\Reports\"
;
var filePath = Path.Combine(path, name +
"."
+ extension);
var fs =
new
FileStream(filePath, FileMode.Create);
this
.streams.Add(fs);
return
fs;
}
private
void
button1_Click(
object
sender, System.EventArgs e)
{
RenderReport();
}
Greetings,
IvanY
the Telerik team
Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!
0

Karl
Top achievements
Rank 1
answered on 07 Nov 2013, 10:36 AM
Could you provide an example of how to use the code in your example to return the image from a html page response? The code below returns an image file but it is corrupt.
System.Collections.Hashtable deviceInfo =
new
System.Collections.Hashtable();
deviceInfo[
"OutputFormat"
] =
"JPEG"
;
string
documentName =
""
;
InstanceReportSource reportToExport =
new
InstanceReportSource();
reportToExport.ReportDocument =
new
RecruitmentBulletinPDF.RecruitmentBulletin(Convert.ToInt32(yearSelector.SelectedItem.Text), Convert.ToInt32(weekSelector.SelectedValue), rtbIssueNo.Text);
ReportProcessor reportProcessor =
new
ReportProcessor();
bool
result = reportProcessor.RenderReport(
"IMAGE"
, reportToExport, deviceInfo,
this
.CreateStream,
out
documentName);
byte
[] filebytes =
new
byte
[streams[0].Length];
streams[0].Read(filebytes, 0, Convert.ToInt32(streams[0].Length));
Response.Clear();
Response.ContentType =
"image/jpeg"
;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer =
true
;
Response.AddHeader(
"Content-Disposition"
,
string
.Format(
"{0};FileName=\"{1}\""
,
"attachment"
,
"imagefile"
));
Response.BinaryWrite(filebytes);
Response.End();
this
.CloseStreams();
0
Hello Karl,
Please follow the examples in the Exporting Report Programmatically help article.
I have tested with the following sample code and it is working correctly:
If you still experience any difficulties we will appreciate if you open a support thread and send us a runnable sample to debug on our end.
Regards,
Nasko
Telerik
Please follow the examples in the Exporting Report Programmatically help article.
I have tested with the following sample code and it is working correctly:
Telerik.Reporting.Report report =
new
ReportLibrary.Report1();
Telerik.Reporting.Processing.ReportProcessor reportProcessor =
new
Telerik.Reporting.Processing.ReportProcessor();
//set any deviceInfo settings if necessary
System.Collections.Hashtable deviceInfo =
new
System.Collections.Hashtable();
Telerik.Reporting.InstanceReportSource instanceReportSource =
new
Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = report;
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport(
"IMAGE"
, instanceReportSource, deviceInfo);
string
fileName = result.DocumentName +
"."
+ result.Extension;
Response.Clear();
Response.ContentType =
"image/jpeg"
;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer =
true
;
Response.AddHeader(
"Content-Disposition"
,
string
.Format(
"{0};FileName=\"{1}\""
,
"attachment"
,
fileName));
Response.BinaryWrite(result.DocumentBytes);
Response.End();
If you still experience any difficulties we will appreciate if you open a support thread and send us a runnable sample to debug on our end.
Regards,
Nasko
Telerik
New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.