【ActiveReports】调整 Acrobat Viewer 控件大小以适应页面的大小

在ActiveReports 7.0专业版中,您可以使用WebViewer控件在ASP.NET应用程序中显示报表,WebViewer控件提供了以下几种查看类型:HtmlViewer, RawHtml, AcrobatReader, 和 FlashViewer

发布于 2013/03/03 00:00

在ActiveReports 7.0专业版中,您可以使用WebViewer控件在ASP.NET应用程序中显示报表,WebViewer控件提供了以下几种查看类型:HtmlViewer, RawHtml, AcrobatReader, 和 FlashViewer。以下是这几种

产看类型的简单描述:

HtmlViewer(默认类型):

RawHTML:

AcrobatReader:

FlashViewer:

 

通过WebViewer允许用户快速地创建并在Web中显示报表,在某些情况下我们希望WebViewer控件能够填充Web页面的整个区域,通常情况下用户需要设置WebViewer的height属性为 100%,不过height属性设置是不会生效的。一种常用解决方法就是通过CSS样式来控制,如下:

<style type="text/css">
html, body, #WebViewer1, #controlDiv
{
   width: 100%;
   height: 100%;
   margin: 0;
}
</style>

然而,AcrobatReader类型有些限制,所以,以上方法并不会很好的工作。另外一种解决方法就是在Page_Load中添加以下代码:

protected void Page_Load(object sender, EventArgs e)
{
   WebViewer1.Width = Unit.Percentage(100);
   WebViewer1.Height = Unit.Percentage(100);
   WebViewer1.Style["left"] = "0px";
   WebViewer1.Style["height"] = "100%";
}

不过,在我看来控制控件大小的最后方法是在客户端通过jQuery来完成。下面的jQuery代码可以用于设置AcrobatViewer控件的高度,而且在各种浏览器中均可正常工作:

<script type="text/javascript" language="javascript">
   $(document).ready(function () {
   // Get a reference to the first <DIV> inside
   // the <DIV> with ID="viewer-layout-main-panel"
   var d = $("#viewer-layout-main-panel:first");
 
   // Set d equal to the width of its parent <DIV> minus
   // an offset to accomodate padding or margin attribute
   d.width($("#viewer-layout-main-panel:first").width() - 10);
 
   // Get the top position of the Main Div
   var top = $("#mainDiv").position().top;
 
   // Set the height of the MainDiv to the
   // document height minus its Top position
   $("#mainDiv").height($(document).height() - top - 25);
 
   // Get the height and width of the mainDiv
   var h = $("#mainDiv").height();
   var w = $("#mainDiv").width();
 
   // Size the WebViewer Control
   $("#WebViewer1").height(h - 8);
   $("#WebViewer1").width(w - 8);
   });
</script>
 
运行截图:

 源码下载:VS2010 + ActiveReports 7.0 

Webviewer_Resize.zip (147.06 kb)

关于葡萄城

葡萄城是专业的软件开发技术和低代码平台提供商,以“赋能开发者”为使命,致力于通过表格控件、低代码和BI等各类软件开发工具和服务,一站式满足开发者需求,帮助企业提升开发效率并创新开发模式。葡萄城开发技术始于1980年,40余年来始终聚焦软件开发技术,有深厚的技术积累和丰富的产品线。是业界能够同时赋能软件开发和低代码开发的企业。凭借过硬的产品能力、活跃的用户社区和丰富的伙伴生态,与超过3000家合作伙伴紧密合作,产品广泛应用于信息和软件服务、制造、交通运输、建筑、金融、能源、教育、公共管理等支柱产业。

推荐相关案例
推荐相关资源
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态