-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathQrBillPrinting.cs
More file actions
72 lines (65 loc) · 2.21 KB
/
QrBillPrinting.cs
File metadata and controls
72 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Swiss QR Bill Generator for .NET
// Copyright (c) 2021 Manuel Bleichenbacher
// Licensed under MIT License
// https://opensource.org/licenses/MIT
//
using Codecrete.SwissQRBill.Generator;
using System.Printing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
namespace Codecrete.SwissQRBill.Examples.Wpf
{
/// <summary>
/// Sample class for printing a document with a Swiss QR bill
/// </summary>
internal class QrBillPrinting
{
/// <summary>
/// Print sample document with the specified QR bill
/// </summary>
/// <param name="bill">QR bill to print</param>
internal static void Print(Bill bill)
{
// show print dialog
var pd = new PrintDialog();
pd.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
pd.PrintTicket.PageOrientation = PageOrientation.Portrait;
if (pd.ShowDialog() != true)
return;
// create page
var pageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
var page = new FixedPage
{
Width = pageSize.Width,
Height = pageSize.Height
};
// add title
var text = new TextBlock
{
Text = "Swiss QR Bill",
FontSize = 40,
FontWeight = FontWeights.Bold,
Margin = new Thickness(20 / 25.4 * 96)
};
page.Children.Add(text);
// add QR bill to the bottom
var qrBill = new Image
{
Source = QrBillImage.CreateImage(bill)
};
FixedPage.SetBottom(qrBill, 0);
page.Children.Add(qrBill);
// create document
var document = new FixedDocument();
document.DocumentPaginator.PageSize = pageSize;
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(page);
document.Pages.Add(pageContent);
// print document
pd.PrintDocument(document.DocumentPaginator, "Invoice");
}
}
}