2

我有一个现成的 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;
    }

我能做些什么来解决这个问题?感谢帮助。

4

1 回答 1

0

Calling doc.DocumentPaginator gets the most "up-to-date" paginator. Pagination happens when that call is made, and the size of the page depends on the pages inside the document.

I haven't tried to reproduce the issue, but I have two things that you can try:

Change the size of each FixedPage in the 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());

another option is to try to change the PrintDialog's 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());
于 2014-12-26T21:42:14.210 回答