Tuesday, February 21, 2012
Repost - How to reset page numbers in PDF Report
Looking for ideas on this one. Would like a report (single pdf file) whose page numbers would be say 1 of 5 and then 1 of 6, etc.. The page number resets would be based on the changing value of some field like summarybillnumber.
Any help/ideas would be appreciated.
ThanksAdd this to the Code property of the report:
shared offset as integer
public function GetPN(reset as boolean, pagenumber as integer) as integer
if reset
offset = pagenumber - 1
end if
return pagenumber - offset
end function
Use the function in the page number expression, basing the reset property on
the presence of something that only appears on the first page of the group.
For example:
="Page " & Code.GetPN(ReportItems!tag.Value = "Tag",Globals!PageNumber)
Note: To make this work, the offset member variable must be declared as
shared. This means the report cannot be run multiple times simultaneously,
otherwise the separate runs will smash the shared member variable's value.
In addition, failure to access the pages sequentially will have unexpected
results (since the shared offset member variable will be set out of order).
The only way to use this hack is to schedule runs of the report and save off
the rendered results. Users cannot run the report live or even from
snapshot history, since pagination occurs when the report is rendered, not
when the snapshot is taken.
The ability to conditionally reset page numbering on specific page breaks,
such as group page breaks, is on our wishlist for a future version, but this
feature is not likely to make it into SQL 2005.
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"chanley54" <chanley54@.discussions.microsoft.com> wrote in message
news:BDDF14C9-ACA0-4F8B-98BB-91839AAB6644@.microsoft.com...
> Hello,
> Looking for ideas on this one. Would like a report (single pdf file)
> whose page numbers would be say 1 of 5 and then 1 of 6, etc.. The page
> number resets would be based on the changing value of some field like
> summarybillnumber.
> Any help/ideas would be appreciated.
> Thanks
>
ReportViewer: creating PDF on the fly
Hi all,
I'm writing a offer web page using ReportViewer control.
This offer page will be shown in PDF format.
I understood that the ReportViewer control can't work without any DataSource, but for my needs I use report parameters and not DataSet (or somesimilar object). So, I defined the unreal DataSet just for deceive the ReportViewer (I don't know if this solution is wise, but probably it's what I able).
<rsweb:ReportViewer runat="server" ID="ReportViewer1" Font-Names="Verdana" Font-Size="8pt" Height="400px" ShowToolBar="False" Width="685px"> <LocalReport ReportPath="Offer.rdlc" > <DataSources> <rsweb:ReportDataSource DataSourceId="objectDataSource" Name="DataSet1" /> </DataSources> </LocalReport></rsweb:ReportViewer><asp:ObjectDataSource runat="server" ID="objectDataSource" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="DataSet1TableAdapters.MyTableAdapter"></asp:ObjectDataSource>So far so good. When I activate the offer page, it shown properly, but when I add the following code for create the PFD document from the page, I get an error:
A data source instance has not been supplied for the data source "DataSet1"
protected void Page_Load(object sender, EventArgs e){ Warning[] warnings;string[] streamids;string mimeType;string encoding;string extension;byte[] myBytes =this.ReportViewer1.LocalReport.Render("PDF",null,out mimeType,out encoding,out extension,out streamids,out warnings); Response.Buffer =true; Response.Clear(); Response.ContentType = mimeType; Response.BinaryWrite(myBytes); Response.Flush(); Response.End();}
Please help!
Thanks in advance!
Hi,
Take a look over here :
http://blogs.msdn.com/bimusings/archive/2005/07/01/434659.aspx
HTH,
Suprotim Agarwal
--
http://www.dotnetcurry.com
--
Hi Suprotim Agarwal,
Thank you for the quick response.
I already saw this short article, but it not exactly answers to my case - the error appears only when I create a PDF document from my predefined ReportViewer. If I delete an aforementioned code, the Offer.aspx page work properly.
|||
Hi,
Based on the code you provided, you are going to render the report in the code behind, right?
I think you should declare and add the report datasource explicitly in your code-behind file before you are invoking the render method, see the following code snippet:
protected void Page_Load(object sender, EventArgs e)
{
this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
this.ReportViewer1.LocalReport.ReportPath =
@."c:\Reports\Report1.rdl";
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Sales", LoadSalesData())); declare and add the datasource explicitly.
}
protected void Button1_Click(object sender, EventArgs e)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = ReportViewer1.LocalReport.Render(
"Excel", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
FileStream fs = new FileStream(@."c:\output.xls",
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Label1.Text = "Report exported to output.xls";
}
}
Thanks.
The problem solved when I moved a code that creates a PDF document from Page_Load to Page_SaveStateComplete event.
Thanks to all of you!
ReportViewer.LocalReport.Render - PDF filesize over 5 MB
I am testing the .Render method of a local report and can get to export to excel and pdf no problem. My xls file size is under 50 K for a small chart graphic report but every pdf generated tops 5 MB. Is this an issue that an be resolved or a bug in the ReportViewer?
Any solution to this problem? I've got a 10 page report that is less than 1MB in Excel and more than 40MB in PDF!|||This sucks!
I found this post saying that this is a known problem:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=379152&SiteID=1&mode=1
I have a PDF that renders as 25MB. If you open it in acrobat and save a copy of it the copy is saved as 270KB. 95 times smaller!!!