Hi,
how can I generate pdf file from SSRS report using reporting service (ReportingService2010SoapClien)?
Thanks in advance.
Technology Tips and News
Hi,
how can I generate pdf file from SSRS report using reporting service (ReportingService2010SoapClien)?
Thanks in advance.
Hello,
Not with ReportingService SOAP, but with ReportingExecution, see
Developer's Guide (Reporting Services)
Building Applications Using the Web Service and the .NET Framework
Hi Pramod ,
In Reporting Services, we can use the Reporting Services web services SOAP API to render the report and save it into PDF file. The key is to call ReportingExecution service. There are some samples for your reference:
SSRS Reports Render Using Batch Script
How to render the Report to PDF/EXCEL format
SSRS and PowerShell: Get report as Excel
If you have any question, please feel free to ask.
Best regards,
Qiuyun Yu
If you have any feedback on our support, please click here.
Hi,
I used the sample code provided over link and try to print the SSRS report but the print is not coming properly it is printing only few text and zooming the entire text- below is the code used-
public bool PrintReport(byte[][] bytearray)
{
try
{
this.m_renderedReport = bytearray;
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.MaximumPage = m_numberOfPages;
printerSettings.MinimumPage = 1;
printerSettings.PrintRange = PrintRange.SomePages;
PrintDocument pd = new PrintDocument();
m_currentPrintingPage = 1;
m_lastPrintingPage = m_numberOfPages;
Console.WriteLine("Printing report...");
pd.PrinterSettings = printerSettings;
pd.PrintPage += this.pd_PrintPage;
pd.Print();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
Console.WriteLine(ex.Message);
}
return true;
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
try
{
ev.HasMorePages = false;
if (m_currentPrintingPage <= m_lastPrintingPage && MoveToPage(m_currentPrintingPage))
{
// Draw the page
ReportDrawPage(ev.Graphics);
// If the next page is less than or equal to the last page,
// print another page.
if (System.Threading.Interlocked.Increment(ref m_currentPrintingPage) <= m_lastPrintingPage)
{
ev.HasMorePages = true;
}
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
Console.WriteLine(ex.Message);
}
}
private void ReportDrawPage(Graphics g)
{
try
{
if (m_currentPageStream == null || 0 == m_currentPageStream.Length || m_metafile == null)
{
return;
}
lock (this)
{
// Set the metafile delegate.
int width = m_metafile.Width;
int height = m_metafile.Height;
m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback);
// Draw in the rectangle
Point destPoint = new Point(0, 0);
g.EnumerateMetafile(m_metafile, destPoint, m_delegate);
// Clean up
m_delegate = null;
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
Console.WriteLine(ex.Message);
}
}
private bool MoveToPage(int page)
{
try
{
// Check to make sure that the current page exists in
// the array list
if (m_renderedReport[m_currentPrintingPage - 1] == null)
{
return false;
}
// Set current page stream equal to the rendered page
m_currentPageStream = new MemoryStream(m_renderedReport[m_currentPrintingPage - 1]);
// Set its postion to start.
m_currentPageStream.Position = 0;
// Initialize the metafile
if (m_metafile != null)
{
m_metafile.Dispose();
m_metafile = null;
}
// Load the metafile image for this page
m_metafile = new Metafile(m_currentPageStream);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
Console.WriteLine(ex.Message);
}
return true;
}
private bool MetafileCallback(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback callbackData)
{
try
{
byte[] dataArray = null;
// Dance around unmanaged code.
if (data != IntPtr.Zero)
{
// Copy the unmanaged record to a managed byte buffer
// that can be used by PlayRecord.
dataArray = new byte[dataSize];
Marshal.Copy(data, dataArray, 0, dataSize);
}
// play the record.
m_metafile.PlayRecord(recordType, flags, dataSize, dataArray);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
Console.WriteLine(ex.Message);
}
return true;
}
private void RenderReport()
{
try
{
string reportPath = "/AONOfferteNewFR/AdresFR";
ReportExecutionServiceSoapClient rsExec = new ReportExecutionServiceSoapClient();
rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
string historyID = null;
ExecutionInfo execInfo = new ExecutionInfo();
TrustedUserHeader trusteduserHeader = new TrustedUserHeader();
ExecutionHeader execHeader = new ExecutionHeader();
ServerInfoHeader serviceInfo = new ServerInfoHeader();
rsExec.LoadReport(trusteduserHeader, reportPath, historyID, out serviceInfo, out execInfo);
execHeader.ExecutionID = execInfo.ExecutionID;
ReportParameter[] _parameters = execInfo.Parameters;
ParameterValue[] _ParameterValue = new ParameterValue[1];
_ParameterValue[0] = new ParameterValue();
_ParameterValue[0].Name = _parameters[0].Name;
_ParameterValue[0].Value = "1234";
rsExec.SetExecutionParameters(execHeader, null, _ParameterValue, "en-us", out execInfo);
string deviceInfo = null;
string extension = null;
string encoding = null;
string mimeType = null;
Warning[] warnings = null;
string[] streamIDs = null;
string format = "IMAGE";
Byte[] result;
byte[][] pages = null;
deviceInfo = String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>", "emf");
rsExec.Render(execHeader, null, format, deviceInfo, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs);
//using (FileStream stream = File.OpenWrite(Application.StartupPath + "\\SSRS_Report.pdf"))
//{
// stream.Write(result, 0, result.Length);
//}
m_numberOfPages = streamIDs.Length + 1;
pages = new byte[m_numberOfPages][];
// The first page was already rendered
pages[0] = result;
for (int pageIndex = 1; pageIndex <= m_numberOfPages - 1; pageIndex++)
{
// Build device info based on start page
deviceInfo = String.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat><StartPage>{1}</StartPage></DeviceInfo>",
"emf", pageIndex + 1);
rsExec.Render(execHeader, null, format, deviceInfo, out pages[pageIndex], out extension, out mimeType, out encoding, out warnings, out streamIDs);
}
PrintReport(pages);
}
catch (Exception ex)
{ }
}
Thanks for your help.