簡體   English   中英

無法將FixedDocument打印到自定義尺寸

[英]Can't print FixedDocument to custom size

我已經准備好以下面的頁面大小打印的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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM