ReportViewer 打印一页字母大小,但当我打印时它是两页
ReportViewer prints one page letter size, but when I print it is in two pages
我在 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%" />
有什么建议吗?
谢谢
鲁本茨
原来问题是我在 RDLC 报告中设置了边距,我只是将它们更改为 0,现在可以正常工作了。
我在 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%" />
有什么建议吗?
谢谢 鲁本茨
原来问题是我在 RDLC 报告中设置了边距,我只是将它们更改为 0,现在可以正常工作了。