picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.58k stars 325 forks source link

WPF: Orientation, PaperSize and resolution do not use selected values #1409

Open cwensley opened 5 years ago

cwensley commented 5 years ago

WPF, Orientation Landscape is still ignored, print is always Portrait. Same for papersize and print-resolution selected in printer-dialog.

document.PrintPage-Eventhandler always comes with the same PageSize. We need to print graphics, images, maps with different paper sizes, orientations, dpi..

How do I get this fixed now? Tried to figure out whats happening under the hood of eto-printing, but its very unclear and difficult to understand or even to modify.

Originally posted by @TomQv in https://github.com/picoe/Eto/issues/1147#issuecomment-493667669

TomQv commented 5 years ago

The bug is in Eto.Wpf.Forms.Printing,PrintSettingsExtensions: SetFromDialog, must look like this::

public static void SetFromDialog(this PrintSettings settings, swc.PrintDialog dialog)
{
    if (dialog == null) return;
    if (settings != null)
    {
         var handler = (PrintSettingsHandler)settings.Handler;
        handler.PrintQueue = dialog.PrintQueue;

        // this was missing:
        handler.Control = dialog.PrintTicket;

         handler.MaximumPageRange = new Range<int>((int)dialog.MinPage, (int)dialog.MaxPage);
        handler.SelectedPageRange = dialog.PageRange.ToEto();
        handler.PrintSelection = dialog.PageRangeSelection.ToEto();
    }
}
TomQv commented 5 years ago

I also changed Eto.Wpf.Forms.Printing.PrintSettingsHandler-constructor to immidiatly have the settings of the standard-printer:

public PrintSettingsHandler()
{
    // tom
    var pd = new swc.PrintDialog();
    Control = pd.PrintTicket;
    PrintQueue = pd.PrintQueue;

    //Control = new sp.PrintTicket();
    //PrintQueue = new swc.PrintDialog().PrintQueue;

    MaximumPageRange = new Range<int>(1, 1);
    SelectedPageRange = new Range<int>(1, 1);
    Collate = true;
    PrintSelection = PrintSelection.AllPages;
}
cwensley commented 5 years ago

Hey @TomQv, thanks for the pointers on what is broken here, it is very useful!

If you have time, creating a PR with the changes would be very appreciated, but otherwise I'll try to get to it when I have time.

Cheers!

TomQv commented 5 years ago

Hi @cwensley, sorry, I don't use GitHub, actually I don't know, how it works, which is no excuse, should not be that difficult.
Btw. in this regard, I must still check the Mac-version, hopefully I'll find time this week.

Serg-Norseman commented 1 year ago

Please make the page size characteristics available before printing (before PrintPage-EventHandler appears) - it is necessary to print very large documents that need to be divided into pages not linearly, but by a matrix. Accordingly, without a known page size, it is impossible to divide a document into pages.