localReport.GetDefaultPageSettings()。PageSize获取错误的值 [英] localReport.GetDefaultPageSettings().PageSize gets wrong values

查看:154
本文介绍了localReport.GetDefaultPageSettings()。PageSize获取错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想获取localReport的PageSize。我使用了localReport.GetDefaultPageSettings()。PageSize,但宽度和高度相反。我把它们放在rdlc报告中11 * 8.5我发现它们是8.5 * 11.

我在ReportPageSettings对象中找到了2个私有变量,但我不知道如何访问它们。

有人可以帮忙吗?

解决方案

我不知道你是否想出来了,但MS在报告页面宽度较大时会这样做比页面高度。这是对景观印刷的一种蹩脚尝​​试,而不是在报告设计中包含景观标志。我们的标签打印机使用标签4x3,但仍然打印肖像。如果您通过代码打印,则可以覆盖文档页面设置。这样的事情。



  //  打印机名称格式: 
// 本地打印机名称或网络打印机例如\\fit-app-mobile \ App Bagger 3 Mobile
// 检查查看是否有流
如果(m_streams == null || m_streams.Count == 0
return ;

// 生成新的打印文档
PrintDocument printDoc = new PrintDocument();

// 通过将控制器从默认控制器切换到标准控制器来取消打印对话框
PrintController printCtl = new System.Drawing.Printing.StandardPrintController();
printDoc.PrintController = printCtl;

// 设置要打印的份数
printDoc.PrinterSettings.Copies =拷贝;


/ * ************ ************************************************** ***********************
*注意! MS BUG / Oversight。记录缺乏横向打印处理。
*横向打印的高度和宽度可能会相反。报告设计中没有
*横向标志。对于标签,宽度可能比
*长度宽,导致MS扭转高度和宽度杂乱,打算使用横向
*打印,但我们可能真的想要一个肖像打印因为实际纸张尺寸。
*
*查找名为landscape的报告参数并检查其值。另外ASSUME
*一个肖像打印。这意味着当
* width大于height时,REVERSE高度和宽度以强制纵向。
* ********************************************* *************************************** /

bool forcePortrait = false ;

ReportPageSettings rps = report.GetDefaultPageSettings();
ReportParameterInfoCollection rc = report.GetParameters();
foreach (ReportParameterInfo rpi in rc)
{
if (rpi.Name.ToUpper()== FORCEPORTRAIT
{
forcePortrait =(rpi.Values [ 0 ] == True)? true false ;
}
}

if (forcePortrait&& rps.PaperSize.Height > rps.PaperSize.Width) // 如果Width>,请记住MS已经撤消了这些;高度
{
// 注意:强制人像打印因为肖像报告参数是设置和高度> width
// 表示设计时的报告大小是用于拍摄本田的
// 纸张宽度超过其高度(例如标签)
printDoc.DefaultPageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
rps.PaperSize.Height,rps.PaperSize.Width) ;
}
其他
{
// < span class =code-comment>注意:正常打印横向或正常宽度<高度打印。
printDoc.DefaultPageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
rps。 PaperSize.Width,rps.PaperSize.Height);
}
/ * *************** ************************************************** ******************* /

// 设置边距
printDoc.DefaultPageSettings.Margins = rps.Margins;


// 设置打印机名称
printDoc.PrinterSettings.PrinterName = MapIFSPrinter(printerName);
if (!printDoc.PrinterSettings.IsValid)
{
Log.Write( 打印错误!找不到打印机 + printerName,Log.LogType.Error);
return ;
}
// 设置页面打印委托
printDoc。 PrintPage + = new PrintPageEventHandler(PrintPage);
// 打印文档(将其发送到已脱机的打印机)
printDoc .Print();


你好,



我刚刚应用了你聪明的解决方案,已经注意到,有一种新方法可以确定是否设置了landscape参数。



您现在可以将代码重写为至少MS Reports 11直接使用现在可用作ReportPageSettings属性的参数:





if(rps.IsLandscape && rps.PaperSize.Height> ; rps.PaperSize.Width)

{

m_pageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),

rps .PaperSize.Height,rps.PaperSize.Width);

}

else

{

m_pageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.To String(),

rps.PaperSize.Width,rps.PaperSize.Height);

}



BTW你的文章为我节省了很多时间。我能够在注意到它的15分钟内解决这个问题 - 感谢你,代码项目和互联网。



干杯,

Djordje

Hello,
I want to get the PageSize of a localReport. I used the localReport.GetDefaultPageSettings().PageSize but the width and the height are reversed. I put them in rdlc report 11*8.5 i found them 8.5*11.
I found 2 private variables correct in ReportPageSettings object, but i don't know how i can access them.
Can anyone helps, please ?

解决方案

I don't know if you figured this out yet, but MS does this when the report page width is LARGER than the page Height. This is a lame attempt at landscape printing, rather than including a landscape flag in the report design. We have label printers that use labels 4x3, but still print portrait. If you are printing via code, you can override the document page settings. Something like this.

//Printer Name Format:
           //Either a local printer name or network printer e.g. \\fit-app-mobile\App Bagger 3 Mobile
           //Check to see if there are streams
           if (m_streams == null || m_streams.Count == 0)
               return;

           //Generate a new print document
           PrintDocument printDoc = new PrintDocument();

           //Suppress the printing dialog by switching the controller from the default controller to the standard controller
           PrintController printCtl = new System.Drawing.Printing.StandardPrintController();
           printDoc.PrintController = printCtl;

           //Set the number of copies to be printed
           printDoc.PrinterSettings.Copies = copies;


           /**************************************************************************************
            * NOTE! MS BUG/Oversight. Documented lack of landscape printing handling.
            * The height and the width may get reversed for landscape printing. There is no
            * landscape flag in the report design. For labels, the width MAY be wider than the
            * Length causing MS to reverse the Height and width messurments, intending a landscape
            * print, but we may really want a portrait print becuase that is the actual paper size.
            *
            * Look for a report paramater called landscape and check its value. Otherwise ASSUME
            * a portrait print. This means REVERSE the height and width to force portrait when
            * width is greater than height.
            * ************************************************************************************/
           bool forcePortrait = false;

           ReportPageSettings rps = report.GetDefaultPageSettings();
           ReportParameterInfoCollection rc = report.GetParameters();
           foreach (ReportParameterInfo rpi in rc)
           {
               if (rpi.Name.ToUpper() == "FORCEPORTRAIT")
               {
                   forcePortrait = (rpi.Values[0] == "True") ? true : false;
               }
           }

           if (forcePortrait && rps.PaperSize.Height > rps.PaperSize.Width) //Remember MS has reversed these if Width > Height
           {
               //NOTE: Force Portrait printing becuase portrait report paramater is set and height is > width
               //indicating the report size at design time was intended for portait printing
               //on paper that is wider than its height (e.g. labels)
               printDoc.DefaultPageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
                   rps.PaperSize.Height, rps.PaperSize.Width);
           }
           else
           {
               //NOTE: Normal Printing Either Landscape or Normal width < height printing.
               printDoc.DefaultPageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
                rps.PaperSize.Width, rps.PaperSize.Height);
           }
           /*************************************************************************************/

           //Set margins
           printDoc.DefaultPageSettings.Margins = rps.Margins;


           //Set the printer name
           printDoc.PrinterSettings.PrinterName = MapIFSPrinter(printerName);
           if (!printDoc.PrinterSettings.IsValid)
           {
               Log.Write("Print Error! Can't find printer " + printerName, Log.LogType.Error);
               return;
           }
           //Set the page print delegate
           printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
           //Printe the document (send it to the desgnated printer)
           printDoc.Print();


Hello,

I have just applied your clever solution, and have noticed that, there is a new way to find out if the landscape parameter is set.

You code can now, at least for MS Reports 11, be rewritten to directly use the parameter that is now available as a property of ReportPageSettings:


if (rps.IsLandscape && rps.PaperSize.Height > rps.PaperSize.Width)
{
m_pageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
rps.PaperSize.Height, rps.PaperSize.Width);
}
else
{
m_pageSettings.PaperSize = new PaperSize(rps.PaperSize.Kind.ToString(),
rps.PaperSize.Width, rps.PaperSize.Height);
}

BTW Your article has saved me a lot of time. I was able to solve this problem within 15 minutes of noticing it - Thanks to you, codeproject and the internet.

Cheers,
Djordje


这篇关于localReport.GetDefaultPageSettings()。PageSize获取错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆