我有一个准备好的FixedDocument打印下面的pagesize,供用户选择:
if (Globals.LayoutSettings.paperSize.ToUpper() == "LETTER")
doc.DocumentPaginator.PageSize = new System.Windows.Size(8.5 * 96, 11 * 96);
else if (Globals.LayoutSettings.paperSize.ToUpper() == "A4")
doc.DocumentPaginator.PageSize = new System.Windows.Size(8.3 * 96, 11.7 * 96);
else
doc.DocumentPaginator.PageSize = new System.Windows.Size(8.5 * 96, 11 * 96);
但每当我通过PDFCreator打印出FixedDocument时,它总是保持A4尺寸。
private bool printDocument(FixedDocument doc)
{
bool printed = false;
try
{
System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
//pd.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "TempLabel_" + DateTime.Now.Ticks.ToString());
pd.PrintDocument(doc.DocumentPaginator, "TempLabel_" + DateTime.Now.Ticks.ToString());
printed = true;
}
catch (Exception ex)
{
MessageBox.Show("Error in printing document: " + ex.ToString(), "Error in printing");
}
return printed;
}
我该怎么做才能解决这个问题?感谢帮助。
答案 0 :(得分:0)
调用doc.DocumentPaginator
获取最“最新”的分页符。进行调用时会发生分页,页面大小取决于文档内的页面。
我没有尝试重现这个问题,但我有两件事你可以尝试:
更改FixedPage
中每个FixedDocument
的尺寸:
var sizeOfPage = GetPageSizeToPrint(Globals.LayoutSettings.paperSize.ToUpper());
foreach(var page in doc.Pages)
{
page.Child.Height = sizeOfPage.Height;
page.Child.Width = sizeOfPage.Width;
}
pd.PrintDocument(doc.DocumentPaginator, "TempLabel_" + DateTime.Now.Ticks.ToString());
另一个选择是尝试更改PrintDialog
的{{1}}:
PrintTicket