如何将 RDLC 报告限制为 PDF 中的一页?
我有一个 RDLC 报告,并将其显示在前端应用程序的报告查看器控件上。 我能够完美地查看报告。
但当我尝试将报告导出为 PDF(使用内置选项)时,问题就出现了。
我将报告打印为 3 页,而我的客户希望将其打印为一页。 我无法弄清楚其原因,因为在我的报告查看器中我只看到一页,但在 PDF 中却有 3 页。
可以采取一些措施来控制报告的大小吗?
I have a RDLC report and I am displaying it on the Report Viewer Control in my front end application. I am able to view the report perfectly.
But the problem arises when I try to export the report to a PDF (using the built-in option).
I print the report in 3 pages whereas my client wants it to be in a single page. I can't figure out the reason for it as in my report viewer I see only one page but in a PDF there are 3 pages.
Can something be done about it so that I can control the size of the report?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
答案与杜根所说的非常相似,但并不总是只是利润率。
但这非常简单:
当您在设计模式下编辑 rdlc 文件时,首先单击设计的 BODY 区域的空白部分。 按 F4 查看属性选项卡。 在这里,您将看到“大小”属性。 这可以扩展宽度和高度。 您在此处看到的宽度表示报告正文作为可打印区域所需的宽度。 即使到处都是空白,页面也知道需要将其保留为可打印区域。 从某种意义上说,它保留了空间。 至于高度,系统通常知道它可以根据需要增大或缩小,除非您在其中的控件中另有指定。 因此,宽度通常起着最重要的作用。
接下来,单击报表的空白区域(页眉、正文和页脚之外;基本上是设计周围的灰色区域),然后按 F4 查看属性面板。 在属性的“布局”类别下,您将看到 3 个不同的选项:
交互尺寸,
边距,
页面大小。
每个“尺寸”属性都可以展开以显示宽度和高度。 Margins 属性可以扩展为左/右/上/下。
基本上,pdf 导出是根据页面大小进行的(尽管我通常会尝试保持交互大小和页面大小相等)。 当通过 ReportViewer 的内置导出功能呈现 pdf 文件时,pdf 中每个“页面”的宽度和高度将由报表的 PageSize 属性中的宽度和高度确定(如果您使用自己的属性,则可以覆盖此属性) pdf 渲染的自定义代码)。
至于边距,它们指定为报告保留的可打印区域和页面边缘之间必须留有多少空白和不可打印的空间。
换句话说:
报告正文的宽度,加上报告的左边距,加上报告的右边距,必须小于或等于报告的 PageSize 的宽度!
所以...如果您的页边距太宽,或者您的报告正文太宽,或者 PageSize 的宽度太窄,则渲染结果将被迫分解为多个页面以适应!
例如:如果我的报告正文宽度为 7.75 英寸,左边距为 0.5 英寸,右边距为 0.5 英寸,PageSize 中指定的宽度为 8.5 英寸,则我的报告将始终为每 1 页数据使用 2 页。 正文的 7.75 英寸宽度,加上边距的 0.5 英寸+0.5 英寸,总计为 8.75 英寸,比我的页面中可用的 8.5 英寸大。因此,我的报告每页的前 7.5 英寸(左右)正文将显示在第一页,其余部分将拆分到下一页。 这不会在报告查看器内完成,因为它允许报告通过添加滚动条而超出页面大小,但在 pdf 导出中会非常明显。
为了使我的示例报告适合 1 页,我可以尝试将报告正文减少到 7.5 英寸或更少,或者我可以将左右边距总共减少 0.25 英寸或更多(例如,将它们设置为 0.3",总共减少 0.4"),或者我可以将 PageSize 增加到大于 8.75"。
注意:Acrobat Reader 非常智能,可以识别各种纸张尺寸。 因此,虽然任意页面大小都可以,但通常最好使用实际页面大小。 因此,在我的最后一个示例中,我宁愿将 PageSize 设置为宽度 = 11 英寸,高度 = 8.5 英寸,这是横向的真实字母大小! Adobe 通常会理解这一点并正确打印。
另请注意:某些打印机,尤其是较旧的打印机,在页边距小于 0.3 英寸的情况下会出现问题。如果您想对用户友好,则最好为那些较旧的打印机保留足够大的页边距;)
我希望这会有所帮助。
The answer is pretty similar to what Dugan said, but it's not always just the margins.
It is pretty simple though:
When you are editing the rdlc file in design mode, firstly click on an empty part of the BODY area of your design. Hit F4 to see the properties tab. Here, you will see a "Size" property. This can be expanded for the width and height. The width you see here represents the width that the body of your report requires as printable area. Even if you have white space all over, the page knows that it needs to keep it as a printable area. It reserves the space, in some sense. As for the height, the system generally knows that it can grow or shrink as necessary, unless you have specified otherwise within your controls therein. So the width is what will, usually, play the most important role.
Next, click on an empty area of the report (outside the header, body, and footer; basically the gray area around the design), then hit F4 to view the properties panel. Under the "Layout" category of the properties, you will see 3 different options:
InteractiveSize,
Margins,
PageSize.
Each of those Size attributes can be expanded to show the Width and Height. The Margins attribute can be expanded for the left/right/top/bottom.
Basically, the pdf export works out of the PageSize (though I generally try to keep Interactive and Page size equal). When the pdf file is rendered via the ReportViewer's built-in export function, the width and height of each "page" within the pdf will be determined by the width and height in the report's PageSize attribute (you could override this if you used your own custom code for the pdf rendering).
As for the margins, they specify how much space MUST be left blank and unprintable between the printable area reserved for your report and the edge of the page.
In other words:
Your report's Body's Width, Plus the Report's Left Margin, Plus the Report's Right Margin, MUST be smaller than or equal to the Report's PageSize's Width!
So...if your margins are too wide, or if your report's body is too wide, or if the PageSize's width is too narrow, the rendered result is forced to be broken down to multiple pages in order to fit!
For example: If my report's body has width 7.75", my Left margin is 0.5", my right margin is 0.5", and the width specified in the PageSize is 8.5", my report will always use 2 pages for each 1 page of data. The 7.75" width of the body, plus 0.5"+0.5" for the margins add up to 8.75", which is larger than the 8.5" available in my page. So the first 7.5" (or so) of each page of my report's body will be shown in the first page, and the rest will be split down to the next page. This will not be done inside the report viewer, as it allows for the report to grow beyond the page size by just adding a scrollbar, but it will be annoyingly noticeable in the pdf export.
In order to make my example report fit in 1 page, I can either try and reduce the body of my report to 7.5" or less, or I can reduce the left and right margins by a total of 0.25" or more (for example, set them to 0.3" for a total reduction of 0.4"), or I can increase the PageSize to something larger than 8.75".
Note: Acrobat Reader is pretty smart and knows about various paper sizes. Therefore, while arbitrary PageSizes will work, it is typically best to use real page sizes. As such, in my last example I would rather set the PageSize to have Width = 11" and Height = 8.5", which is a real letter-size in landscape! Adobe will typically understand this and print properly.
Also Note: Some printers, especially older ones, have trouble printing with less than 0.3" margins. If you want to be nice to your users, you should best keep the margins large enough for those older printers ;)
I hope this helps.
始终保持正文宽度:7.5以下
左、右页边距宽度小于0.5
首先设置边距宽度-> 转到主菜单报告->报告属性->布局->更改左边距和右边距
总页面宽度:8.5
Ramana
Always maintain body width : 7.5 or less
Left, Right Margin width less than 0.5
Set the Margin width first -> goto main menu Reports->Report Properties->Layout->change left margin and right margin
Total page width :8.5
Ramana
除了观察宽度之外,我还发现其他不相关的事情可能会导致 PDF 中出现额外的空白页面。
如果 tablix 中有任何字段具有自动换行,则可能会导致这种情况。 如果数据很长,您可能需要缩小字体。 使字体大小属性等于这样的内容:
您可能需要做的另一件事。 当我没有明显理由需要额外的页面时,这对我很有帮助。 在报表属性页中,设置:
ConsumeContainerWhitespace = true
还有一件事需要注意。 在更改布局时,车身尺寸可能会在您不知情的情况下增大。 你可能不得不再次把它击倒。
如果这个问题没有得到解决,那么对于最终用户来说非常烦人,对于我们来说解决起来也非常烦人。
In addtion to watching your widths, I found other unrelated things that can cause extra blank page in the PDF.
If the tablix has any field with word wrap, this can cause it. You might want to make the font smaller if you have long data. Make the font size property equal to something like this:
Another thing you may have to do. And this helped me when I had no apparent reason for the extra page. In the Report property page, set:
ConsumeContainerWhitespace = true
Yet another thing to watch for. The body size can grow without you knowing it while making changes to the layout. You might have to knock it back down again.
This issue is highly annoying for the end user if not resolved and annoying as heck for us to resolve.
如果其他人遇到这个问题并最终出现在这里,这很可能是您的利润问题。 如果页边距设置不正确,当您尝试打印时,通常会出现“额外”页面,而当您查看文档时一切正常。
In case anyone else runs into this issue and ends up here, it's most likely a issue with your margins. If the margins are set incorrectly, you will often get "extra" pages that appear when you try and print, whereas when you view the document everything is fine.