Sierra W. answered 06/09/23
Unlock Your Full Potential
Unfortunately, OfficeWriter does not have a direct feature to export SSRS (.rdl) reports to PDF. OfficeWriter is primarily designed for manipulating and generating Microsoft Office documents, such as Excel and Word files.
To export SSRS reports to PDF programmatically, you can consider using the SSRS web service API, also known as the Report Server Web service. This API allows you to interact with the SSRS server and perform various operations, including rendering reports to different formats like PDF.
Here's a general outline of the steps you would need to follow:
Add a reference to the Report Server Web service in your project. The Report Server Web service URL would typically look like: http://ReportServerName>/ReportServer/ReportService2010.asmx.
Create an instance of the ReportExecutionService class from the web service reference.
Set the necessary authentication credentials to access the SSRS server.
Specify the report path or report name that you want to export.
Set the rendering format to PDF.
Set any required report parameters, if your report has any.
Execute the report and retrieve the rendered report as a byte array.
Save the byte array to a PDF file.
Here's a sample code snippet that demonstrates how to export an SSRS report to PDF using the Report Server Web service API in C#:
using System;
using System.IO;
using System.Net;
using YourReportServiceReference; // Replace with your actual web service reference
class Program
{
static void Main()
{
// Create an instance of the ReportExecutionService
var rs = new ReportExecutionService();
// Set the necessary authentication credentials
rs.Credentials = new NetworkCredential("username", "password", "domain");
// Set the report path or name
var reportPath = "/YourReportFolder/YourReportName";
rs.LoadReport(reportPath, null);
// Set the rendering format to PDF
var format = "PDF";
var devInfo = @"<DeviceInfo><OutputFormat>PDF</OutputFormat></DeviceInfo>";
// Set any required report parameters if needed
var parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "ParameterName";
parameters[0].Value = "ParameterValue";
rs.SetExecutionParameters(parameters, "en-us");
// Execute the report and retrieve the rendered report as a byte array
var result = rs.Render(format, devInfo, out var extension, out var mimeType, out var encoding, out var warnings, out var streamIDs);
// Save the byte array to a PDF file
var outputPath = "Output.pdf";
using (var fs = new FileStream(outputPath, FileMode.Create))
{
fs.Write(result, 0, result.Length);
}
Console.WriteLine("Report exported to PDF successfully.");
}
}
Make sure to replace the placeholders like YourReportServiceReference with your actual web service reference, username, password, and domain with the appropriate credentials, and adjust the reportPath and outputPath variables to match your report's location and the desired output file path.
Please note that this code assumes you have already added the appropriate web service reference to your project. The exact steps to add the reference may vary depending on your development environment and version of Visual Studio.
I hope this helps you export SSRS reports to PDF programmatically.