C # несколько страниц на листе или буклете - PullRequest
0 голосов
/ 19 июня 2019

Я работаю в программе DICOM, которая получает страницы и печатает их и если есть более одной страницы, он печатает его на одной странице я хочу контролировать их печать в виде буклета или 2 страниц на листе без предварительного просмотра

  private void DoPrint()
  {
     PrintDocument printDocument = null;
     try
     {
        Status = PrintJobStatus.Printing;
        OnStatusUpdate("Printing Started");

        var printerSettings = new PrinterSettings
        {
           PrinterName = "Microsoft XPS Document Writer",
           PrintToFile = true,
           PrintFileName =
                                          string.Format(
                                              "{0}\\{1}.xps",
                                              FullPrintJobFolder,
                                              SOPInstanceUID.UID)
        };

        printDocument = new PrintDocument
        {
           PrinterSettings = printerSettings,
           DocumentName = Thread.CurrentThread.Name,
           PrintController = new StandardPrintController()
        };

        printDocument.QueryPageSettings += OnQueryPageSettings;
        printDocument.PrintPage += OnPrintPage;

        printDocument.Print();

        Status = PrintJobStatus.Done;

        OnStatusUpdate("Printing Done");
     }
     catch (Exception e)
     {
        Status = PrintJobStatus.Failure;
        OnStatusUpdate($"Printing failed, exception: {e}");
     }
     finally
     {
        if (printDocument != null)
        {
           //dispose the print document and unregister events handlers to avoid memory leaks
           printDocument.QueryPageSettings -= OnQueryPageSettings;
           printDocument.PrintPage -= OnPrintPage;
           printDocument.Dispose();
        }
     }
  }

  private void OnPrintPage(object sender, PrintPageEventArgs e)
  {
     _currentFilmBox.Print(e.Graphics, e.MarginBounds, 100);

     _currentFilmBox = null;
     _currentPage++;

     e.HasMorePages = _currentPage < FilmBoxFolderList.Count;
  }

  private void OnQueryPageSettings(object sender, QueryPageSettingsEventArgs e)
  {
     OnStatusUpdate(string.Format("Printing film {0} of {1}", _currentPage + 1, FilmBoxFolderList.Count));
     var filmBoxFolder = string.Format("{0}\\{1}", FullPrintJobFolder, FilmBoxFolderList[_currentPage]);
     var filmSession = FilmSession.Load(string.Format("{0}\\FilmSession.dcm", filmBoxFolder));
     _currentFilmBox = FilmBox.Load(filmSession, filmBoxFolder);

     e.PageSettings.Margins.Left = 25;
     e.PageSettings.Margins.Right = 25;
     e.PageSettings.Margins.Top = 25;
     e.PageSettings.Margins.Bottom = 25;

     e.PageSettings.Landscape = _currentFilmBox.FilmOrientation == "LANDSCAPE";
  }

я понимаю, как работает и работает OnPrintPage но я хочу контролировать, сколько страниц можно распечатать на одной странице без предварительного просмотра

...