We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Webservice that creates report and returns as it PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

132606 Sep 11,2017 06:32 PM UTC Dec 20,2017 01:30 PM UTC Report Platform 11
loading
Tags: Report Viewer
asterinex
Asked On September 11, 2017 06:49 PM UTC

Hello,

I have a webservice in ASP.Net and I need to return reports converted to PDF.
What I want :
- Manually Draw/Create a Report with a designer.
- Webservice creates report in memory, converts it to PDF and returns the PDF.

I don't need a reportviewer ! I only want to create reports in memory.
 
Is this possible and what version do I need to install ?


Regards,Gert

Vinoth Srinivasan [Syncfusion]
Replied On September 12, 2017 11:39 AM UTC

Hi asterinex, 

Thanks for your interest in Syncfusion Components. 

Query 
Response 
Manually Draw/Create a Report with a designer. 
Please find the report designer sample to create a report. 


Please refer the below UG documentation for more details, 

You can obtain the WPF report designer samples from the below build installed location, 
%userprofile%\AppData\Local\Syncfusion\EssentialStudio\version\WPF\Reports.WPF\Samples\ReportDesigner.WPF 
Webservice creates report in memory, converts it to PDF and returns the PDF.

I don't need a reportviewer ! I only want to create reports in memory.
 
 
We can achieve your requirement by using ReportWriter control to export the report into PDF, Excel, Word, PPT and HTML directly without displaying in WebAPI controller and return the result as per your request as shown in below code example. 

        protected void ExportButton_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                string fileName = null; 
                WriterFormat format;                
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter(); 
                reportWriter.ReportPath = Server.MapPath("~/App_Data/GroupingAgg.rdl");                 
                reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
 
                if (this.ExportFormat.SelectedValue == "PDF") 
                { 
                    fileName = "GroupingAgg.pdf"; 
                    format = WriterFormat.PDF; 
                } 
                else if (this.ExportFormat.SelectedValue == "Word") 
                { 
                    fileName = "GroupingAgg.doc"; 
                    format = WriterFormat.Word; 
                } 
                else if (this.ExportFormat.SelectedValue == "Html") 
                { 
                    fileName = "GroupingAgg.Html"; 
                    format = WriterFormat.HTML; 
                } 
                else 
                { 
                    fileName = "GroupingAgg.xls"; 
                    format = WriterFormat.Excel; 
                } 
                reportWriter.Save(fileName, format, httpContext.Response); 
            } 
            catch { } 
        } 

We have prepared a ReportWriter sample and it can have downloaded from, 

Please refer to the below UG documentation for more detail, 

You can obtain the ASP.Net ReportWriter samples from the below build installed location, 
%userprofile%\AppData\Local\Syncfusion\EssentialStudio\version\Web\Samples\Web 

Is this possible and what version do I need to install ? 
You can install our latest ASP.Net build to export the report using ReportWriter, it can be downloaded from below location. 


Regards, 
Vinoth S. 


asterinex
Replied On September 12, 2017 01:34 PM UTC

Hi Vinoth,

thx for your extensive answer. Looks very promising.
So if I'm right, I need to use the WPF-Reportdesigner to create a report and save this as a

rdl-file.
Then I can use this RDL-File in my webservice to create a PDF with
the ReportWriter-Class ?

Is this summary correct ?


Vinoth Srinivasan [Syncfusion]
Replied On September 13, 2017 10:59 AM UTC

Hi asterinex, 

Yes, you can create a RDL report using our WPF report designer and save the report to local folder. In your web service use the ReportWriter class to access the saved report and convert the report to PDF then return the stream to your client. 

Regards, 
Vinoth S. 


asterinex
Replied On September 19, 2017 07:02 AM UTC

Hi Vinoth,

I managed to create an RDL Report, convert it to PDF and send the PDF with email to an emailadress in asp.net:)

But 2 things I could not figure out. In WPF I managed to do it, but not in ASP.NET
(See picture in attachement for more info)

1) How do I set reportparameters ? The method reportWriter.SetParameters(.....) takes a List of 'Syncfusion.Reports.EJ.Reportparameter'
    I cannot find this class. Do I miss Something ?
2) How do I change the connectstring for the database programmatically ?





Attachment: reportcode_7b8b5a4d.zip

Yuvaraj Devarajan [Syncfusion]
Replied On September 20, 2017 04:59 AM UTC

Hi Asterinex, 

Thanks for the update. 

1) How do I set reportparameters ? The method reportWriter.SetParameters(.....) takes a List of 'Syncfusion.Reports.EJ.Reportparameter' 
    I cannot find this class. Do I miss Something ? 

We suspect the mentioned problem occurs when the “Syncfusion.EJ.ReportViewer” assembly is not referred properly in your application. If the mentioned issue is again reproduced after referring the Syncfusion assemblies, then it might occur when the Syncfusion namespace references is not added in web.config file in your application. So we request you to specify the “Syncfusion.JavaScript.Web” namespaces in web.config as shown in shared screenshot in your application to rectify the mentioned issue at your end.   

 

2) How do I change the connectstring for the database programmatically ? 

We have an option to change the connection string of the report using SetDataSourceCredentials method in ReportWriter as shown in below code example, 

            try 
            { 
                string fileName = null; 
                WriterFormat format;                
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter(); 
                reportWriter.ReportPath = Server.MapPath("~/App_Data/GroupingAgg.rdl");                 
                reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
 
                DataSourceCredentials _credential = new DataSourceCredentials(); 
                _credential.ConnectionString = "Data Source=mvc.syncfusion.com;Initial Catalog=AdventureWorks;"; 
                _credential.Name = "AdventureWorks"; //Datasource name 
                _credential.UserId = "ssrs1"; 
                _credential.Password = "RDLReport1"; 
 
                IList<DataSourceCredentials> _credentials = new List<DataSourceCredentials>(); 
                _credentials.Add(_credential); 
                reportWriter.SetDataSourceCredentials(_credentials); 
 
                List<ReportParameter> parameters = new List<ReportParameter>(); 
                parameters.Add(new ReportParameter() { Name = "ReportParameter1", Labels = new List<string>() { "SampleValue" }, Values = new List<string>() { "SampleValue" } }); 
                reportWriter.SetParameters(parameters); 
 
 
                if (this.ExportFormat.SelectedValue == "PDF") 
                { 
                    fileName = "GroupingAgg.pdf"; 
                    format = WriterFormat.PDF; 
                } 
                else if (this.ExportFormat.SelectedValue == "Word") 
                { 
                    fileName = "GroupingAgg.doc"; 
                    format = WriterFormat.Word; 
                } 
                else if (this.ExportFormat.SelectedValue == "Html") 
                { 
                    fileName = "GroupingAgg.Html"; 
                    format = WriterFormat.HTML; 
                } 
                else 
                { 
                    fileName = "GroupingAgg.xls"; 
                    format = WriterFormat.Excel; 
                } 
                reportWriter.Save(fileName, format, httpContext.Response); 
            } 
            catch { } 
        } 

We have prepared a sample and it can be downloaded from below location, 



Regards, 
Yuvaraj D. 


asterinex
Replied On September 27, 2017 05:34 PM UTC

thx Vinoth for the samples. Everythings works like a charm now. Very good software :) !

I have one quesytion, but is not urgent.

What is the difference between properties ReportParameters.Labels and
ReportParameters.Values ?

    



Yuvaraj Devarajan [Syncfusion]
Replied On September 28, 2017 02:35 PM UTC

Hi Asterinex, 

Thanks for the update. 

Report Parameter Label 
Report Parameter Value 
Labels will be displayed in the parameter instead of parameter values. You can display meaningful user-friendly labels in the parameter instead of actual value. 

For example: If you want to show the user "ProductName" but use "ProductID" as the value of the parameter. 

Value doesn’t display in the Parameter, it can be used within the report or expression. 

For example:  if you have to specify a "value field" for parameter, in case you want the user to be prompted with something meaningful to them then use labels.  

Regards, 
Yuvaraj D. 


asterinex
Replied On December 18, 2017 10:36 AM UTC

Dear Syncfusion,

is it possible to add a watermarkt and preferably programmatically ?
like 'reportWriter.Watermark = "Test";' 


regards,Gert

Yuvaraj Devarajan [Syncfusion]
Replied On December 19, 2017 11:54 AM UTC

Hi Gert, 
 
We can design the report (RDL/RDLC) with background image for the body report item as watermark. Since, we don’t have option to set the water mark text in report as per RDL standard. But, we can able to achieve this using “set background image” property for body report item as shown in below screenshot. 
 
 
 
Note: For the watermark we should use the low opacity background image for the body property. 
 
Please refer to the below MSDN documentation for more information, 
 
Regards, 
Yuvaraj D. 


asterinex
Replied On December 19, 2017 03:52 PM UTC

Thx Yuvaraj,

is it possible to set this by code (reportwrite) ?
I need different watermarks for the same report (Test, Duplicate, ... )

Yuvaraj Devarajan [Syncfusion]
Replied On December 20, 2017 01:30 PM UTC

Hi Glenn, 

We have an issue while export the report with body background image and logged a defect report on this. So a support incident to track the status of this future has been created under your account. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Regards, 
Yuvaraj D. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;