使用一个可以一次性收据的小工具。这是由于我们的ERP系统打印收据,但仅接受三张纸,并且没有提供打印单张纸的方式。
在此之前,我写了一个很好的工具,但是它在WinForms中,并且将其移到WPF中。我已经获得了基本的概念证明,但是不确定如何在页面上精确放置元素,或者如何设置页面大小。 (单张纸大约是8.5 x 11页的高度的1/3。)
这是测试应用程序中的代码。
private void Button_Click(object sender, RoutedEventArgs e)
{
Address printAddress = new Address();
fillDoc(printAddress);
MessageBox.Show($"{printAddress.firstName} - {printAddress.lastName} - {printAddress.street_address} - {printAddress.city} - {printAddress.state} - {printAddress.postalcode} ", "Button has been clicked");
PrintDialog pd = new PrintDialog();
if(pd.ShowDialog() == true)
{
FixedDocument doc = new FixedDocument();
doc.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
FixedPage p1 = new FixedPage();
p1.Width = doc.DocumentPaginator.PageSize.Width;
p1.Height = doc.DocumentPaginator.PageSize.Height;
TextBlock firstNameText = new TextBlock();
firstNameText.Text = printAddress.firstName + " " + printAddress.lastName;
firstNameText.FontSize = 40;
firstNameText.Margin = new Thickness(96);
TextBlock address = new TextBlock();
address.Text = printAddress.street_address + "/n" + printAddress.city + " " + printAddress.state + " " + printAddress.postalcode;
address.Margin = new Thickness(128);
address.FontSize = 40;
p1.Children.Add(firstNameText);
p1.Children.Add(address);
PageContent p1c = new PageContent();
((IAddChild)p1c).AddChild(p1);
doc.Pages.Add(p1c);
pd.PrintDocument(doc.DocumentPaginator, "Initial Test");
}
}
我有三个问题: