Showing posts with label render. Show all posts
Showing posts with label render. Show all posts

Monday, March 12, 2012

Programmatically Render Report to PDF

Hello,

I'm looking for an example on how to programmatically render a report to pdf in C#. I don't want to use a url with the rs:Format=pdf querystring. Any help would be much appreciated!!

Hello,

Have a look at this doc page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

There is a full example of how to render reports programmatically using the Render method.

-Chris

|||

Hi Chris,

Thanks for your response. I took a look at the link you gave me and now I'm getting the following error:

There was an error opening this document. The file is damaged and cannot be repaired.

Here is the code I'm using:

localhost.ReportingService rs = new localhost.ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

byte[] ResultStream;

string[] StreamIdentifiers;

string OptionalParam = null;

string deviceInfo = "<DeviceInfo>" +

" <OutputFormat>PDF</OutputFormat>" +

" <PageWidth>8.5in</PageWidth>" +

" <PageHeight>11in</PageHeight>" +

" <MarginTop>0.5in</MarginTop>" +

" <MarginLeft>0.5in</MarginLeft>" +

" <MarginRight>0.5in</MarginRight>" +

" <MarginBottom>0.5in</MarginBottom>" +

"</DeviceInfo>";

string mimetype;

string encoding;

string historyid = null;

localhost.ParameterValue[] optionalParams = new localhost.ParameterValue[1];

optionalParams[0] = new localhost.ParameterValue();

optionalParams[0].Name = "applicantid";

optionalParams[0].Value = "10";

localhost.Warning[] optionalWarnings = null;

ResultStream = rs.Render("/employmentapplication/printableemploymentapplication",

"pdf",

historyid,

deviceInfo,

optionalParams,

null,

null,

out encoding,

out mimetype,

out optionalParams,

out optionalWarnings,

out StreamIdentifiers);

Response.BinaryWrite(ResultStream);

No matter which report I try to open, I get the same error. Any help is greatly appreciated!!!

Thanks!!

Daniel

|||

You get that error when you attempt to open the document?

It could be that there is some extraneous stuff being written to the HTTP stream to which you do your BinaryWrite. I suggest writing "ResultStream" to a file to isolate where corruption, if any, may be occurring.

Also, the OutputFormat value in DeviceInfo is not necessary when rendering to PDF since you're specifying the render format in the Render method call.

-Chris

|||There shouldn't be any extra bytes in the response stream so you shouldn't worry about that. Make sure that you are actually closing the BinaryWriter. Many of the CLR streams buffer internally, so if they are not closed completely then there can be problems where all of the data is not being written.
|||

Hi John -

Thanks for you response. How do I close Response.BinaryWriter? Do you have an example of programmatically rendering a report to pdf that I can look at? Thanks again for all your help!!!

|||

From the RS side of the things, you are doing things correctly. As Chris pointed out, I would look into making sure that you are properly handling the Response stream. If you are writing any other data to it, then you will run into problems.

You should be able to call .Flush() on the stream to make sure the contents are completely written out.

-John

|||

I was running into the same issue today... calling Flush() and Close() on the response object fixed my issues.

--Andy

|||

Hello,

I have successfully implemented the sample referenced above with a VB.NET console app. I would like to build a CLR stored procedure that implements the same code, programmatically generating a PDF report and outputting it to a file. I'm running into permissions issues.

Anybody had any luck calling the Reporting Services Web Service API from inside a CLR stored procedure?

Ken

|||

Renskemo, you might want to take this question over to the following forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=86&SiteID=1

Programmatically Render Report to PDF

Hello,

I'm looking for an example on how to programmatically render a report to pdf in C#. I don't want to use a url with the rs:Format=pdf querystring. Any help would be much appreciated!!

Hello,

Have a look at this doc page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

There is a full example of how to render reports programmatically using the Render method.

-Chris

|||

Hi Chris,

Thanks for your response. I took a look at the link you gave me and now I'm getting the following error:

There was an error opening this document. The file is damaged and cannot be repaired.

Here is the code I'm using:

localhost.ReportingService rs = new localhost.ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

byte[] ResultStream;

string[] StreamIdentifiers;

string OptionalParam = null;

string deviceInfo = "<DeviceInfo>" +

" <OutputFormat>PDF</OutputFormat>" +

" <PageWidth>8.5in</PageWidth>" +

" <PageHeight>11in</PageHeight>" +

" <MarginTop>0.5in</MarginTop>" +

" <MarginLeft>0.5in</MarginLeft>" +

" <MarginRight>0.5in</MarginRight>" +

" <MarginBottom>0.5in</MarginBottom>" +

"</DeviceInfo>";

string mimetype;

string encoding;

string historyid = null;

localhost.ParameterValue[] optionalParams = new localhost.ParameterValue[1];

optionalParams[0] = new localhost.ParameterValue();

optionalParams[0].Name = "applicantid";

optionalParams[0].Value = "10";

localhost.Warning[] optionalWarnings = null;

ResultStream = rs.Render("/employmentapplication/printableemploymentapplication",

"pdf",

historyid,

deviceInfo,

optionalParams,

null,

null,

out encoding,

out mimetype,

out optionalParams,

out optionalWarnings,

out StreamIdentifiers);

Response.BinaryWrite(ResultStream);

No matter which report I try to open, I get the same error. Any help is greatly appreciated!!!

Thanks!!

Daniel

|||

You get that error when you attempt to open the document?

It could be that there is some extraneous stuff being written to the HTTP stream to which you do your BinaryWrite. I suggest writing "ResultStream" to a file to isolate where corruption, if any, may be occurring.

Also, the OutputFormat value in DeviceInfo is not necessary when rendering to PDF since you're specifying the render format in the Render method call.

-Chris

|||There shouldn't be any extra bytes in the response stream so you shouldn't worry about that. Make sure that you are actually closing the BinaryWriter. Many of the CLR streams buffer internally, so if they are not closed completely then there can be problems where all of the data is not being written.
|||

Hi John -

Thanks for you response. How do I close Response.BinaryWriter? Do you have an example of programmatically rendering a report to pdf that I can look at? Thanks again for all your help!!!

|||

From the RS side of the things, you are doing things correctly. As Chris pointed out, I would look into making sure that you are properly handling the Response stream. If you are writing any other data to it, then you will run into problems.

You should be able to call .Flush() on the stream to make sure the contents are completely written out.

-John

|||

I was running into the same issue today... calling Flush() and Close() on the response object fixed my issues.

--Andy

|||

Hello,

I have successfully implemented the sample referenced above with a VB.NET console app. I would like to build a CLR stored procedure that implements the same code, programmatically generating a PDF report and outputting it to a file. I'm running into permissions issues.

Anybody had any luck calling the Reporting Services Web Service API from inside a CLR stored procedure?

Ken

|||

Renskemo, you might want to take this question over to the following forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=86&SiteID=1

Wednesday, March 7, 2012

programmatic rendering of multipage report

Hi,
I have created a multipage report (having almost 40 pages). I need to
render this report programmatically.
Is there any way to get the report pages as and when required (i.e.
when user clicks on <next> button).
I am able to render single page report using render() method. How to do
so for multipage report.
regards,
Sachin.What are you rendering it as? Image, HTML?
For an Image type you can specify the start page as part of the DeviceInfo.
Craig
"sachin laddha" <sachinladdha@.gmail.com> wrote in message
news:1142572855.966655.266270@.v46g2000cwv.googlegroups.com...
> Hi,
> I have created a multipage report (having almost 40 pages). I need to
> render this report programmatically.
> Is there any way to get the report pages as and when required (i.e.
> when user clicks on <next> button).
> I am able to render single page report using render() method. How to do
> so for multipage report.
> regards,
> Sachin.
>|||Hi,
I need to render it as HTML and PDF. Also Is it possible to find out
number of report pages in advance.
regards,
sachin.|||http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/tree/browse_frm/thread/5a73412801f5ba54/f63ce6b85e448735?rnum=1&hl=en&q=%22Oleg+Yevteyev%22+pages&_done=%2Fgroup%2Fmicrosoft.public.sqlserver.reportingsvcs%2Fbrowse_frm%2Fthread%2F5a73412801f5ba54%2F41e4ed35916811eb%3Flnk%3Dst%26q%3D%22Oleg+Yevteyev%22+pages%26rnum%3D8%26hl%3Den%26#doc_ac075ac1383673e8
That is for HTML4.0 rendering
Hope it helps.
--
Oleg Yevteyev,
San Diego, CA
It is OK to contact me with a contracting opportunity.
"myfirstname"001atgmaildotcom.
Replace "myfirstname" with Oleg.
--
"sachin laddha" <sachinladdha@.gmail.com> wrote in message
news:1142578108.796952.163040@.z34g2000cwc.googlegroups.com...
> Hi,
> I need to render it as HTML and PDF. Also Is it possible to find out
> number of report pages in advance.
> regards,
> sachin.
>

Programmatic Render of Reports into PDF format

Hi,
Can anybody please convert the following C# code into VB.Net Code.I tried
but its saying Object Reference not set to an instance of an object.
Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
programmatically render reports into PDF format.
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "Parameter1";
parameters[0].Value = Request.QueryString["id"];
Thanks
Rajesh YDim Parameters(1) As New ParameterValue
Parameters(0) = New ParameterValue
Parameters(0).Name = "Parameter1"
Parameters(0).Value = Request.QueryString("id")
"Rajesh Yennam" wrote:
> Hi,
> Can anybody please convert the following C# code into VB.Net Code.I tried
> but its saying Object Reference not set to an instance of an object.
> Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
> programmatically render reports into PDF format.
> // Prepare report parameter.
> ParameterValue[] parameters = new ParameterValue[1];
> parameters[0] = new ParameterValue();
> parameters[0].Name = "Parameter1";
> parameters[0].Value = Request.QueryString["id"];
> Thanks
> Rajesh Y|||Hi Rajesh:
I'd suspect the line of code :
parameters[0].Value = Request.QueryString["id"];
I'd guess you do not have an id parameter in the query string. Double
check the query string.
HTH,
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 29 Oct 2004 03:43:01 -0700, "Rajesh Yennam"
<RajeshYennam@.discussions.microsoft.com> wrote:
>Hi,
>Can anybody please convert the following C# code into VB.Net Code.I tried
>but its saying Object Reference not set to an instance of an object.
>Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
>programmatically render reports into PDF format.
>// Prepare report parameter.
> ParameterValue[] parameters = new ParameterValue[1];
> parameters[0] = new ParameterValue();
> parameters[0].Name = "Parameter1";
> parameters[0].Value = Request.QueryString["id"];
>Thanks
>Rajesh Y

Saturday, February 25, 2012

Programing: RENDER METHOD and PAGE COUNTS for HTML Rendering

We understand how to use the Render method of the RS web service. And can
successfully render reports in image and PDF formats. I am having a problem
with HTML rendering. we understand how to (and are able to) render HTML
reports as a single "section" (i.e. page) or to generate all sections in a
single call. I am not sure how to ask the RS web service to tell me the
total number of "sections" (pages) in an HTML rendered report. Can anyone
help with this? we know it must be straight forward but have not found how.
thanks.
dlrThere is no direct way of determining number of pages
returned by the render method.
But when you call the render method you can see that the
method returns streamIds.
Your first page comes as as the byte array and the
remaining pages have streamIds associated.
So the number of pages is basically : StreamIds.Length+1
>--Original Message--
>We understand how to use the Render method of the RS web
service. And can
>successfully render reports in image and PDF formats. I
am having a problem
>with HTML rendering. we understand how to (and are able
to) render HTML
>reports as a single "section" (i.e. page) or to generate
all sections in a
>single call. I am not sure how to ask the RS web service
to tell me the
>total number of "sections" (pages) in an HTML rendered
report. Can anyone
>help with this? we know it must be straight forward but
have not found how.
>thanks.
>dlr
>
>.
>|||beg to differ. When I render using and IMAGE format I get StreamIDs (and
thus a page count as StreamIDs + 1) but when I render using an HTML format
StreamIDs are always null!
(I have no image links in the report).
what saz's you now?
thanks.
dlr
"Ravi" <ravikantkv@.rediffmail.com> wrote in message
news:84c401c495d0$4572bca0$a301280a@.phx.gbl...
> There is no direct way of determining number of pages
> returned by the render method.
> But when you call the render method you can see that the
> method returns streamIds.
> Your first page comes as as the byte array and the
> remaining pages have streamIds associated.
> So the number of pages is basically : StreamIds.Length+1
> >--Original Message--
> >We understand how to use the Render method of the RS web
> service. And can
> >successfully render reports in image and PDF formats. I
> am having a problem
> >with HTML rendering. we understand how to (and are able
> to) render HTML
> >reports as a single "section" (i.e. page) or to generate
> all sections in a
> >single call. I am not sure how to ask the RS web service
> to tell me the
> >total number of "sections" (pages) in an HTML rendered
> report. Can anyone
> >help with this? we know it must be straight forward but
> have not found how.
> >
> >thanks.
> >
> >dlr
> >
> >
> >.
> >