无法将固定文档打印为自定义大小



我有一个准备好的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());

相关内容

  • 没有找到相关文章

最新更新