[英]GTK# - printing: How to set the paper size
I'm printing some text with GTK# similar to the demo code you can find here: 我正在用GTK#打印一些文本,类似于您可以在此处找到的演示代码:
https://github.com/mono/gtk-sharp/blob/master/sample/GtkDemo/DemoPrinting.cs https://github.com/mono/gtk-sharp/blob/master/sample/GtkDemo/DemoPrinting.cs
The text is printed correctly, but I'd like to have a page with a different paper size as output. 文本可以正确打印,但是我希望页面输出的纸张尺寸不同。
How can I setup the paper size programmatically? 如何以编程方式设置纸张尺寸?
PrintOperation print = new PrintOperation();
print.BeginPrint += new BeginPrintHandler(OnBeginPrint);
print.DrawPage += new DrawPageHandler(OnDrawPage);
print.EndPrint += new EndPrintHandler(OnEndPrint);
print.Run(PrintOperationAction.Print, null);
EDIT I found out that the PrintOperation
class has two members called DefaultPageSetup
and PrintSettings
, which contains a PaperSize, but these objects are null after creating ( new PrintOperation()
). 编辑我发现,
PrintOperation
类有两个成员,分别称为DefaultPageSetup
和PrintSettings
,它们包含一个PaperSize,但是这些对象在创建后为null( new PrintOperation()
)。 And at OnBeginPrint
these values are already set. 并且在
OnBeginPrint
上已经设置了这些值。
I finally found out how to set a custom paper size! 我终于找到了如何设置自定义纸张尺寸的方法! You have to set the
DefaultPageSetup
and PrintSettings
of the PrintOperation
: 您必须设置
PrintSettings
的DefaultPageSetup
和PrintOperation
:
PrintSettings settings = new PrintSettings();
settings.PaperSize = new PaperSize("XXX", "XXX", 500, 5000);
PageSetup setup = new PageSetup();
setup.SetBottomMargin(0, Unit.Pixel);
setup.SetTopMargin(0, Unit.Pixel);
setup.SetLeftMargin(0, Unit.Pixel);
setup.SetRightMargin(0, Unit.Pixel);
setup.PaperSize = settings.PaperSize;
PrintOperation print = new PrintOperation();
print.DefaultPageSetup = setup;
print.PrintSettings = settings;
print.BeginPrint += new BeginPrintHandler(OnBeginPrint);
print.DrawPage += new DrawPageHandler(OnDrawPage);
print.EndPrint += new EndPrintHandler(OnEndPrint);
print.Run(PrintOperationAction.Print, null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.