我已经准备好要打印的FixedDocument,并以下面的页面尺寸供用户选择:
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;
}
我该怎么做才能解决此问题?感谢帮助。
最佳答案
调用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
的PrintTicket
:var sizeOfPage = GetPageSizeToPrint(Globals.LayoutSettings.paperSize.ToUpper());
pd.PrintTicket.PageMediaSize = new PageMediaSize(sizeOfPage.Width, sizeOfPage.Height);
pd.PrintDocument(doc.DocumentPaginator, "TempLabel_" + DateTime.Now.Ticks.ToString());
关于c# - 无法将FixedDocument打印到自定义尺寸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25779048/