I have generated several images at the runtime and I need to print them. Those are barcodes so the height can be fixed but the number is not know beforehand so more pages might be necessary. Let's say for example that a maximum of 4 images can fit in each A4 page. Below the image a textbox with the content of the barcode might help but it's not necessary.
For printing I use
PrintDialog printDialog = new PrintDialog();
bool? pdResult = printDialog.ShowDialog();
if (pdResult != null && pdResult.Value)
{
FixedDocument document = CreateFixedDocument();
printDialog.PrintDocument(document.DocumentPaginator, "ID Card Printing");
}
and that was easy. But before I need to create the page so
private FixedDocument CreateFixedDocument()
{
FixedDocument fixedDocument = new FixedDocument();
fixedDocument.DocumentPaginator.PageSize = new Size(???); <---have not understood how to set A4 here
//for (int i = 0; i < (numBarcodes/4); i++)
{
PageContent page = new PageContent();
FixedPage fixedPage = CreateOneFixedPage();
((IAddChild)page).AddChild(fixedPage);
fixedDocument.Pages.Add(page);
}
return fixedDocument;
}
and then even more complicated I create one page
private FixedPage CreateOneFixedPage()
{
FixedPage page = new FixedPage();
page.Width = ???
page.Height = ???
TextBlock tbTitle = new TextBlock();
tbTitle.Text = <----------the barcode content
tbTitle.FontSize = 24;
tbTitle.Foreground = new SolidColorBrush(Colors.White);
tbTitle.FontFamily = new FontFamily("Arial");
FixedPage.SetLeft(tbTitle, ????)
FixedPage.SetTop(tbTitle, ?????)
page.Children.Add((UIElement)tbTitle);
Image image = new Image
{
Height = 30,
Width = 30
};
image.Source = imgbarcode.Source;
FixedPage.SetLeft(b, ???);
FixedPage.SetTop(b, ???); // top margin
page.Children.Add((UIElement)b);
//measure size of the layout
Size sz = new Size(???);
page.Measure(sz);
page.Arrange(new Rect(new Point(), sz));
page.UpdateLayout();
return page;
}
Any help is appreciated for I have already printed way too many pages! Thanks