gpt4 book ai didi

c# - 无法将 FixedDocument 打印到自定义尺寸

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:04 25 4
gpt4 key购买 nike

我有一个现成的 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 获取最新的分页器。进行该调用时会发生分页,页面的大小取决于文档中的页面。

我没有尝试重现该问题,但我有两件事您可以尝试:

更改 FixedDocument 中每个 FixedPage 的大小:

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());

另一种选择是尝试更改 PrintDialogPrintTicket:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com