我有一个带有代码的打印按钮:
PrintDialog printDlg = new PrintDialog();
FlowDocumentPageViewer docpv = new FlowDocumentPageViewer();
FlowDocument doc = new FlowDocument();
doc.PagePadding = new Thickness(10);
doc.PageWidth = 793;// a4 width in px
Section sec = new Section();
Paragraph p = new Paragraph();
p = new Paragraph(new Run(Setup.GUI_texts_collection[193] + " " + vInvoice.Id.ToString()));
p.Margin = new Thickness(10);
p.FontSize = 30;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
p.TextAlignment = TextAlignment.Center;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Type_lbl.Content + ": " + this.TypeComboBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Code_lbl.Content + ": " + vInvoice.Code));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Date_lbl.Content + ": " + this.DateTextBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Sender_lbl.Content + ": " + this.SenderComboBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Receiver_lbl.Content + ": " + this.ReceiverComboBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.From_stock_lbl.Content + ": " + this.From_stockComboBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.To_stock_lbl.Content + ": " + this.To_stockComboBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Cash_lbl.Content + ": " + this.Paid_by_cashTextBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Bank_lbl.Content + ": " + this.Paid_by_bankTextBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Debt_lbl.Content + ": " + this.DebtTextBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
p = new Paragraph(new Run(this.Total_amount_lbl.Content + ": " + this.Total_amountTextBox.Text));
p.Margin = new Thickness(5);
p.FontSize = 20;
p.FontFamily = new FontFamily("Arial");
p.FontWeight = FontWeights.Bold;
sec.Blocks.Add(p);
//// Create first Paragraph
doc.Blocks.Add(sec);
doc.Name = "FlowDoc";
IDocumentPaginatorSource idpSource = doc;
if (printDlg.ShowDialog() == true)
{
printDlg.PrintDocument(idpSource.DocumentPaginator,"Invoice " + vInvoice.Id.ToString());
}
但是结果是我得到了文档Printed result
所以,为什么p.TextAlignment = TextAlignment.Center;不要将第一段移到文档的中心。它看起来像放在文档一半的中央。 我做错了什么? 预先感谢您的帮助