ReportViewer可以打印一页字母,但是当我打印时是两页

时间:2018-07-04 19:53:16

标签: webforms rdlc reportviewer

我在web.forms网站中使用vs2017,C#,asp.net 4.6.1和Rdlc 14.2

当我直接将报告发送到pdf时,我有一页报告,位于一页中

        ReportViewer1.DataBind();

        Microsoft.Reporting.WebForms.Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;

        string deviceInfo = "<DeviceInfo>" +
                                           "  <OutputFormat>PDF</OutputFormat>" +
                                           "  <PageWidth>8.5in</PageWidth>" +
                                           "  <PageHeight>11in</PageHeight>" +
                                           "  <MarginTop>0.5in</MarginTop>" +
                                           "  <MarginLeft>0.25in</MarginLeft>" +
                                           "  <MarginRight>0.25in</MarginRight>" +
                                           "  <MarginBottom>1in</MarginBottom>" +
                                           "</DeviceInfo>";
        byte[] writeBinaryBytes = new byte[0];
        writeBinaryBytes = ReportViewer1.LocalReport.Render
            ("Pdf", deviceInfo, out mimeType, out encoding, out extension,
            out streamids, out warnings);

        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.AddHeader
    ("content-disposition", "attachment; filename=" + nombreReporte+".pdf");
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.BinaryWrite(writeBinaryBytes);
        HttpContext.Current.Response.Flush();

当我在ReportViewer中查看页面时,它是一页,但是如果将其导出为pdf或进行打印,则页面是两页……这是我打印之前的代码

        System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
        pg.Margins.Top = 50;        //hundredths of an inch 0.5" * 100
        pg.Margins.Left = 25;       //hundredths of an inch 0.25" * 100
        pg.Margins.Right = 25;      //hundredths of an inch 0.25" * 100
        pg.Margins.Bottom = 100;    //hundredths of an inch 1" * 100
        System.Drawing.Printing.PaperSize size = new PaperSize
        {
            RawKind = (int)PaperKind.Letter
            //hundredths of an inch
            , Width = 850       //hundredths of an inch 8.5" * 100
            , Height = 1100     //hundredths of an inch 11" * 100
        };
    pg.PaperSize = size;
        pg.Landscape = false;
        //pg.PaperSource.RawKind = (int)PaperKind.A5;
        ReportViewer1.SetPageSettings(pg);
        ReportViewer1.LocalReport.Refresh();

这是aspx页面中的ReportViewer控件:

            <rsweb:ReportViewer ID="ReportViewer1" runat="server" 
                ShowToolBar="true" 
                ShowFindControls ="false"
                ShowCredentialPrompts="true"
                ShowDocumentMapButton="true"
                EnableEventValidation="fase" 
                AsyncRendering = "false"
                width="100%" />

有什么建议吗?

谢谢 红宝石

1 个答案:

答案 0 :(得分:0)

事实证明,问题在于我在RDLC报告中设置了页边距,我只是将它们更改为0,现在可以正常工作了。