提问人:Sephystos 提问时间:10/20/2023 更新时间:11/21/2023 访问量:108
Crystal report 不接受用户的打印机设置
Crystal report does not accept user's printer settings
问:
我是一名 C# 开发人员,我需要将 Crystal Report 用于我的版本。
问题是它只能纵向打印。当我尝试更改打印设置时,它们被忽略。例如,如果我在打印机设置中选择“横向”,它仍然会纵向打印。
我发现了很多关于这个的话题,但没有有效的答案。特别是,我看到您可以取消选中“针对显示优化”,但这不会改变任何事情。
我试图通过创建一个“打印”按钮并自己编码来强制参数来作弊:
private void OnPrintButtonClick(object sender, RoutedEventArgs e)
{
PrintDialog PrintD = new PrintDialog();
Nullable<Boolean> print = false;
try
{
print = PrintD.ShowDialog();
}
catch (Exception exc)
{
MessageBox.Show("Imprimante non trouvée: " + exc.Message, "Erreur");
}
if (print == true)
{
PrintQueue printQueue = PrintD.PrintQueue;
report.PrintOptions.PrinterName = printQueue.FullName;
Debug.WriteLine("Printer Name: " + printQueue.FullName);
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = printQueue.FullName;
report.PrintToPrinter(1, false, 0, 0);
}
}
它适用于大多数打印机,但今天我遇到了一个客户端问题,其中打印导致“System.Runtime.InteropServices.COMException:打印机名称无效”错误。
我猜,理想的情况是让应用程序“原生”地使用用户选择的设置,而不必强制执行任何操作。
我在 CR 13.0.22 上,我已经没有想法了。
答:
1赞
stratov
11/21/2023
#1
我假设您可以使用 .PrintD.PrintTicket.PageOrientation
如何将此值设置为在调用函数之前。report.PrintOptions.PaperOrientation
PrintToPrinter
下面是一个代码示例,您可以尝试一下。
if (print == true)
{
PrintQueue printQueue = PrintD.PrintQueue;
report.PrintOptions.PrinterName = printQueue.FullName;
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = printQueue.FullName;
var orientation = PrintD.PrintTicket.PageOrientation;
if (orientation == PageOrientation.Landscape)
{
report.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
}
if (orientation == PageOrientation.Portrait)
{
report.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;
}
report.PrintToPrinter(1, false, 0, 0);
}
0赞
mbd
11/21/2023
#2
如果您还没有尝试以下方法,可以尝试以下方法吗?从 Crystal Reports 应用程序中打开报告,转到“文件”-“页面设置”,将页面设置为“横向”,然后保存 rpt(并将其部署到应用程序的 rpt 所在的任何位置)。
评论