English 中文(简体)
自定义按钮而不是工具栏中的 print Report 报表查看器
原标题:print ReportViewer from custom button not toolbar

Ok 我花了几个小时( 确切地说是4个小时) 来寻找解决办法。 我找到了一些结果, 但至今为止没有工作 。 () ( ) : ( ) ( ) @ info/ plain

问题 : 我有一个用户控制中的报告查看器, 我隐藏工具栏并创建了自己的工具栏。 现在, 我添加了一个应该打印的按钮, 但似乎无法让它工作 。 我会为我采取你们可能拥有的任何解决方案 。 但是它必须是个按钮, 而不是报表的默认栏 。

这是我的代码:

<rsweb:reportviewer 
ID="rvReports" 
runat="server" 
Height="600px"
Width="600px"
ShowToolBar="False"
SizeToReportContent="True" AsyncRendering="false" />

<asp:ImageButton ID="btnprint" runat="server" ImageUrl="../img/print.png" 
     OnClientClick="PrintReport();" />

标注描述 :

<script type="text/javascript">
function PrintReport() {
    var viewerReference = $find("rvReports");
    var reportArea = viewerReference.get_reportAreaContentType();
        if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
            $find("rvReports").invokePrintDialog();
        }

 } 
</script>

我犯的错误是:

Uncaught TypeError: Cannot call method  get_reportAreaContentType  of null

Just in case I added a Jquery Library cause I thought that was it but nothing doing.. BTW I got that javascript from here as it was one of the answers on another stackoverflow questions.

问题回答

我最后用ITextSharp来做这个,这很简单。 添加一个隐藏的 Iframe 并在这个代码后面:

Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;

        byte[] bytes = rvReports.LocalReport.Render("PDF", null, out mimeType,
                       out encoding, out extension, out streamids, out warnings);

        FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output.pdf"), FileMode.Create);
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();

        //Open exsisting pdf
        Document document = new Document(PageSize.LETTER_LANDSCAPE, 0, 0, 0, 0);
        PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output.pdf"));
        //Getting a instance of new pdf wrtiter
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(
           HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create));
        document.Open();
        PdfContentByte cb = writer.DirectContent;

        int i = 0;
        int p = 0;
        int n = reader.NumberOfPages;
        Rectangle psize = reader.GetPageSize(1);

        //float width = psize.Width;
        //float height = psize.Height;

        //Add Page to new document
        while (i < n)
        {
            document.NewPage();
            p++;
            i++;

            PdfImportedPage page1 = writer.GetImportedPage(reader, i);
            cb.AddTemplate(page1, 0, 0);
        }

        //Attach javascript to the document
        PdfAction jAction = PdfAction.JavaScript("this.print(true);
", writer);
        writer.AddJavaScript(jAction);
        document.Close();

        //Attach pdf to the iframe
        frmPrint.Attributes["src"] = "Print.pdf";

做了,猜想只是不得不 继续挖掘谷歌内。 。 。 。

它看起来像 $find ("rv Reports") 返回收藏,没有控制, 结果获得_reportAreaContentType 报告一个错误。 在脚本调试器中检查 $find ("rv Reports") 调用的结果, 并查看您期待的元素是否在视图中存在 。

注意 我认为选择器应该是"#rv Reports"...

在 $find 函数中使用客户端Id 而非服务器ID :

$find(<%=rvReports.ClientID%>)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签