每张纸或小册子C#多页

时间:2019-06-19 15:01:25

标签: c# printing fo-dicom

我在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的工作方式 但我想控制在没有预览对话框的情况下可以在一页中打印多少页

0 个答案:

没有答案