2

I have a ready FixedDocument to be printed with the below pagesize for the user to choose accordingly:

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

But every time when I print the FixedDocument out via PDFCreator, it always stays as A4 size.

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;
    }

What can I do to fix this? Appreciate the help.

1 Answers1

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());
KCL
  • 113
  • 11