|
@@ -31,10 +31,12 @@ using System.Text.RegularExpressions;
|
|
|
using System.Diagnostics;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Windows.Forms;
|
|
|
+using ComboBox = System.Windows.Controls.ComboBox;
|
|
|
+using CheckBox = System.Windows.Controls.CheckBox;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
{
|
|
|
-
|
|
|
public class HomePagePrinterDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
public IRegionManager printRegion;
|
|
@@ -109,6 +111,13 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
set => SetProperty(ref _maxCopiesNumber, value);
|
|
|
}
|
|
|
|
|
|
+ private Visibility _printPageBorderVisibility = Visibility.Collapsed;
|
|
|
+ public Visibility PrintPageBorderVisibility
|
|
|
+ {
|
|
|
+ get => _printPageBorderVisibility;
|
|
|
+ set => SetProperty(ref _printPageBorderVisibility, value);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 打印机支持的颜色
|
|
|
/// </summary>
|
|
@@ -172,16 +181,13 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
set => _isBothSides = value;
|
|
|
}
|
|
|
|
|
|
- public enum EnumBothSidesStage
|
|
|
- {
|
|
|
- StatusFrontSide,
|
|
|
- StatusBackSide
|
|
|
- }
|
|
|
+ public int printCurrentPageIndex;
|
|
|
+ public bool isCurrentPage;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 双面打印阶段:正面或背面
|
|
|
/// </summary>
|
|
|
- public EnumBothSidesStage BothSidesStage;
|
|
|
+ public EnumBothSidesStage BothSidesStage = EnumBothSidesStage.StatusNone;
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -257,12 +263,37 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
SetReversePageCommand = new DelegateCommand<object>(SetReversePage);
|
|
|
SetPrintBorderCommand = new DelegateCommand<object>(SetPrintBorder);
|
|
|
SetPrintOritationCommand = new DelegateCommand<object>(SetPrintOritation);
|
|
|
- Unicode = Guid.NewGuid().ToString();
|
|
|
+ Unicode = Guid.NewGuid().ToString();
|
|
|
InitComponent();
|
|
|
InitDictionary();
|
|
|
InitParams();
|
|
|
-
|
|
|
+ PageSetupDialog pageSetupDialog = new PageSetupDialog();
|
|
|
+ PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = false;
|
|
|
+ pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
|
|
|
+ if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 1;
|
|
|
+ }
|
|
|
printEvent.GetEvent<SendPrintSettingsModInfoEvent>().Subscribe(RecvPrintSettingsModInfo, e => e.Unicode == Unicode);
|
|
|
+ printEvent.GetEvent<SendDuplexPrintModEvent>().Subscribe(RecvDuplexPrintMod, e => e.Unicode == Unicode);
|
|
|
+
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
|
|
|
+ if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 1;
|
|
|
+ }
|
|
|
+ this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
}
|
|
|
|
|
|
private void InitComponent()
|
|
@@ -281,29 +312,12 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
{
|
|
|
printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
|
|
|
List<PageMediaSize> PageMediaSizeList = new List<PageMediaSize>();
|
|
|
- foreach (PageMediaSize size in printQueue.GetPrintCapabilities().PageMediaSizeCapability)
|
|
|
- {
|
|
|
- if (size == null || size.PageMediaSizeName == null)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (size.PageMediaSizeName == PageMediaSizeName.ISOA4)
|
|
|
- {
|
|
|
- PrintSettingsInfo.PageMediaSize = size;
|
|
|
- }
|
|
|
- PageMediaSizeList.Add(size);
|
|
|
- }
|
|
|
- if (PrintSettingsInfo.PageMediaSize == null)
|
|
|
- {
|
|
|
- PrintSettingsInfo.PageMediaSize = PageMediaSizeList[0];
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void InitPrinterNameList()
|
|
|
{
|
|
|
PrinterNameList = new List<string>();
|
|
|
- PrintDocument printDocument = new PrintDocument();
|
|
|
- string defaultPrinterName = printDocument.PrinterSettings.PrinterName;
|
|
|
foreach (string printerListItem in PrinterSettings.InstalledPrinters)
|
|
|
{
|
|
|
PrinterNameList.Add(printerListItem);
|
|
@@ -346,43 +360,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
GetPrintModNameFromRadioButton.Add("ModBookletRdo", HomePagePrinterModBookletName);
|
|
|
}
|
|
|
|
|
|
- public void AutoOritation()
|
|
|
- {
|
|
|
- //纸张长边为高
|
|
|
- //if (PrintSettingsInfo.PageMediaSize.Height / PrintSettingsInfo.PageMediaSize.Width >= 1)
|
|
|
- //{
|
|
|
- // //PDF长边为高
|
|
|
- // if (PDFViewer.Document.GetPageSize(0).Height / PDFViewer.Document.GetPageSize(0).Width >= 1)
|
|
|
- // {
|
|
|
- // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusPortrait;
|
|
|
- // }
|
|
|
- // //PDF长边为宽
|
|
|
- // else
|
|
|
- // {
|
|
|
- // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
|
|
|
- // }
|
|
|
- //}
|
|
|
- ////纸张短边为高
|
|
|
- //else
|
|
|
- //{
|
|
|
- // //PDF长边为高
|
|
|
- // if (PDFViewer.Document.GetPageSize(0).Height / PDFViewer.Document.GetPageSize(0).Width >= 1)
|
|
|
- // {
|
|
|
- // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
|
|
|
- // }
|
|
|
- // //PDF长边为宽
|
|
|
- // else
|
|
|
- // {
|
|
|
- // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusPortrait;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //PrintOrientationIndex = (int)PrintSettingsInfo.EnumPrintOrientation;
|
|
|
- }
|
|
|
-
|
|
|
- public void InitParamsByPDFView()
|
|
|
- {
|
|
|
- AutoOritation();
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// 选择打印机
|
|
|
/// </summary>
|
|
@@ -398,32 +375,61 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
/// </summary>
|
|
|
public void SetPaper()
|
|
|
{
|
|
|
- printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
|
|
|
- LoadPrinterSettings();
|
|
|
- DialogParameters value = new DialogParameters();
|
|
|
- value.Add("Unicode", Unicode);
|
|
|
- value.Add(ParameterNames.PrintQueue, printQueue);
|
|
|
- printDialogs.ShowDialog(DialogNames.HomePagePrinterPaperSettingsDialog, value, e =>
|
|
|
+ if (true)
|
|
|
{
|
|
|
- if (e.Result == ButtonResult.OK)
|
|
|
+ PageSetupDialog pageSetupDialog = new PageSetupDialog();
|
|
|
+ PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
|
|
|
+ pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
|
|
|
+ if (pageSetupDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
- PrintSettingsInfo.PageMediaSize = e.Parameters.GetValue<PageMediaSize>("PageMediaSize");
|
|
|
- PrintSettingsInfo.Margin.Clear();
|
|
|
- PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginLeft"));
|
|
|
- PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginTop"));
|
|
|
- PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginRight"));
|
|
|
- PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginBottom"));
|
|
|
- AutoOritation();
|
|
|
- this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
-
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
|
|
|
+ if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 1;
|
|
|
+ }
|
|
|
+ this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode }); ;
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
|
|
|
+ LoadPrinterSettings();
|
|
|
+ DialogParameters value = new DialogParameters();
|
|
|
+ value.Add("Unicode", Unicode);
|
|
|
+ value.Add(ParameterNames.PrintQueue, printQueue);
|
|
|
+ printDialogs.ShowDialog(DialogNames.HomePagePrinterPaperSettingsDialog, value, e =>
|
|
|
+ {
|
|
|
+ if (e.Result == ButtonResult.OK)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageMediaSize = e.Parameters.GetValue<PageMediaSize>("PageMediaSize");
|
|
|
+ PrintSettingsInfo.Margin.Clear();
|
|
|
+ PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginLeft"));
|
|
|
+ PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginTop"));
|
|
|
+ PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginRight"));
|
|
|
+ PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginBottom"));
|
|
|
+ this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void ChangePrintMod(object e)
|
|
|
{
|
|
|
- var rdo = e as RadioButton;
|
|
|
+ var rdo = e as System.Windows.Controls.RadioButton;
|
|
|
CurrentHomePagePrinterModName = GetPrintModNameFromRadioButton[rdo.Name];
|
|
|
+ if (CurrentHomePagePrinterModName == "HomePagePrinterModMultipleContent" || CurrentHomePagePrinterModName == "HomePagePrinterModBookletContent")
|
|
|
+ {
|
|
|
+ PrintPageBorderVisibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintPageBorderVisibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
NavigationParameters param = new NavigationParameters();
|
|
|
param.Add("document", PDFViewer.Document);
|
|
|
param.Add("Unicode", Unicode);
|
|
@@ -469,7 +475,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
PrintSettingsInfo.IsGrayscale = false;
|
|
|
}
|
|
|
this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -495,50 +500,106 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
{
|
|
|
var cmb = e as WritableComboBox;
|
|
|
PrintSettingsInfo.PageRangeList.Clear();
|
|
|
- PrintSettingsInfo.EnumPageRange = (EnumPageRange)int.Parse(cmb.SelectedIndex);
|
|
|
if (int.Parse(cmb.SelectedIndex) < cmb.Items.Count - 1)
|
|
|
{
|
|
|
- PrintSettingsInfo.EnumPageRange = (EnumPageRange)int.Parse(cmb.SelectedIndex);
|
|
|
- if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusAllRange)
|
|
|
+ if (!isCurrentPage)
|
|
|
{
|
|
|
- for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
+ PrintSettingsInfo.EnumPageRange = int.Parse(cmb.SelectedIndex);
|
|
|
+ if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusAllRange)
|
|
|
{
|
|
|
- PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusOddRange)
|
|
|
- {
|
|
|
- for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
+ else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusOddRange)
|
|
|
+ {
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusEvenRange)
|
|
|
{
|
|
|
- PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ //TODO: 偶数页页数不够异常
|
|
|
+ if (PDFViewer.Document.PageCount <= 1)
|
|
|
+ {
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusEvenRange)
|
|
|
+ else
|
|
|
{
|
|
|
- //TODO: 偶数页页数不够异常
|
|
|
- if (PDFViewer.Document.PageCount <= 1)
|
|
|
+ PrintSettingsInfo.EnumPageRange = int.Parse(cmb.SelectedIndex);
|
|
|
+ if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusAllRange)
|
|
|
{
|
|
|
for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
{
|
|
|
PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCurrentPage)
|
|
|
{
|
|
|
- for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(printCurrentPageIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusOddRange)
|
|
|
+ {
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
{
|
|
|
PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
}
|
|
|
}
|
|
|
+ else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusEvenRange)
|
|
|
+ {
|
|
|
+ //TODO: 偶数页页数不够异常
|
|
|
+ if (PDFViewer.Document.PageCount <= 1)
|
|
|
+ {
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!isCurrentPage)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange;
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void SetCustomPageRange(object e)
|
|
|
{
|
|
|
- if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusCustomizedRange)
|
|
|
+ if ((PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange&&!isCurrentPage)||(PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange && isCurrentPage))
|
|
|
{
|
|
|
var cmb = e as WritableComboBox;
|
|
|
if (cmb == null)
|
|
@@ -551,17 +612,25 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
MessageBoxEx.Show("输入不对");
|
|
|
return;
|
|
|
}
|
|
|
- PrintSettingsInfo.PageRangeList.Clear();
|
|
|
PrintSettingsInfo.PageRangeList = DocumentTargetPages;
|
|
|
+ this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void SetPrintOritation(object e)
|
|
|
{
|
|
|
var cmb = e as ComboBox;
|
|
|
+ if ((EnumPrintOrientation)cmb.SelectedIndex == EnumPrintOrientation.StatusPortrait)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
|
|
|
+ }
|
|
|
+
|
|
|
PrintSettingsInfo.EnumPrintOrientation = (EnumPrintOrientation)cmb.SelectedIndex;
|
|
|
this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public void SetPrintContent(object e)
|
|
@@ -615,15 +684,19 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
{
|
|
|
if (printModInfoWithUnicode.printModInfo.EnumPrintMod == currentHomePagePrinterMod)
|
|
|
{
|
|
|
- PrintSettingsInfo.printModInfo = printModInfoWithUnicode.printModInfo;
|
|
|
+ PrintSettingsInfo.PrintModInfo = printModInfoWithUnicode.printModInfo;
|
|
|
this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void RecvDuplexPrintMod(EnumDuplexPrintModWithUnicode enumDuplexPrintModWithUnicode)
|
|
|
+ {
|
|
|
+ PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod = enumDuplexPrintModWithUnicode.enumDuplexPrintMod;
|
|
|
+ }
|
|
|
#endregion
|
|
|
public void Cancel()
|
|
|
{
|
|
|
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
}
|
|
|
|
|
|
public void NavigateDocumentRegion()
|
|
@@ -633,6 +706,20 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
param.Add(ParameterNames.PrintSettingsInfo, PrintSettingsInfo);
|
|
|
param.Add("Unicode", Unicode);
|
|
|
printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
|
|
|
+ PageSetupDialog pageSetupDialog = new PageSetupDialog();
|
|
|
+ PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
|
|
|
+ pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
|
|
|
+
|
|
|
+ PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
|
|
|
+ if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PrintOrientationIndex = 1;
|
|
|
+ }
|
|
|
+ this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
|
|
|
}
|
|
|
|
|
|
public void NavigateModRegion()
|
|
@@ -640,35 +727,142 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
NavigationParameters param = new NavigationParameters();
|
|
|
param.Add(ParameterNames.PDFViewer, PDFViewer);
|
|
|
param.Add("Unicode", Unicode);
|
|
|
- printRegion.RequestNavigate(HomePagePrinterModRegionName, HomePagePrinterModSizeName);
|
|
|
+ printRegion.RequestNavigate(HomePagePrinterModRegionName, HomePagePrinterModSizeName, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsBookletSinglePage(PrintModInfo printModInfo)
|
|
|
+ {
|
|
|
+ if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
|
|
|
+ {
|
|
|
+ var bookletInfo = (BookletInfo)printModInfo;
|
|
|
+ if (!(bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsBookletBothPage(PrintModInfo printModInfo)
|
|
|
+ {
|
|
|
+ if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
|
|
|
+ {
|
|
|
+ var bookletInfo = (BookletInfo)printModInfo;
|
|
|
+ if (bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 确认打印,单面或手动双面
|
|
|
+ /// 确认打印,单面,双面或手动双面
|
|
|
+ /// 大小模式支持单面,双面
|
|
|
+ /// 海报模式只支持单面
|
|
|
+ /// 多页模式支持单面,双面
|
|
|
+ /// 小册子模式双面打印:双面
|
|
|
+ /// 仅正面/背面:单面
|
|
|
+ ///
|
|
|
+ /// 单面打印:正常传参
|
|
|
+ ///
|
|
|
+ /// 双面打印:
|
|
|
+ /// 长边翻页,短边翻页
|
|
|
+ ///
|
|
|
+ /// 自动双面打印
|
|
|
+ /// 传值给打印机就行
|
|
|
+ ///
|
|
|
+ /// 手动双面打印
|
|
|
+ /// 长边翻页 先打印奇数页,进入二阶段,正向打印偶数页
|
|
|
+ /// 短边翻页 先打印奇数页,进入二阶段,反向打印偶数页
|
|
|
+ ///
|
|
|
+ /// 异常退出是否要挂起打印机线程?
|
|
|
+ ///
|
|
|
/// </summary>
|
|
|
public void ConfirmPrint()
|
|
|
{
|
|
|
+
|
|
|
printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
|
|
|
LoadPrinterSettings();
|
|
|
- this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode {printQueue= this.printQueue ,Unicode = this.Unicode});
|
|
|
- //Collection<Duplexing> list = new Collection<Duplexing>();
|
|
|
-
|
|
|
- //if (printQueue.GetPrintCapabilities().DuplexingCapability.Count > 0)
|
|
|
- //{
|
|
|
- // list.Clear();
|
|
|
- // for (int temp = 0; temp < printQueue.GetPrintCapabilities().DuplexingCapability.Count; temp++)
|
|
|
- // {
|
|
|
- // list.Add(printQueue.GetPrintCapabilities().DuplexingCapability[temp]);
|
|
|
- // }
|
|
|
- //}
|
|
|
- //if (!IsBothSides)
|
|
|
- //{
|
|
|
- // RequestClose.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
- //}
|
|
|
- //else if (IsBothSides)
|
|
|
- //{
|
|
|
- // MessageBoxEx.Show("翻页");
|
|
|
- //}
|
|
|
+
|
|
|
+
|
|
|
+ Collection<Duplexing> list = new Collection<Duplexing>();
|
|
|
+
|
|
|
+ if (printQueue.GetPrintCapabilities().DuplexingCapability.Count > 0)
|
|
|
+ {
|
|
|
+ list.Clear();
|
|
|
+ for (int temp = 0; temp < printQueue.GetPrintCapabilities().DuplexingCapability.Count; temp++)
|
|
|
+ {
|
|
|
+ list.Add(printQueue.GetPrintCapabilities().DuplexingCapability[temp]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ///单面打印的情况:直接执行
|
|
|
+ if (PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod == EnumDuplexPrintMod.StatusNone && !IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
|
|
|
+ }
|
|
|
+ else if (IsBookletSinglePage(PrintSettingsInfo.PrintModInfo))
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
|
|
|
+ }
|
|
|
+ ///双面打印的情况
|
|
|
+ else if ((int)PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod > 0 || IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
|
|
|
+ {
|
|
|
+ ///支持自动双面
|
|
|
+ if (list.Count > 0)
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ ///手动翻面
|
|
|
+ ///手动翻面需要注意只有一页时和单面打印一致
|
|
|
+ ///那奇数页呢?
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if ((PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusSize && PrintSettingsInfo.PageRangeList.Count == 1) || (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet && PrintSettingsInfo.PageRangeList.Count == 1))
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else if (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusMultiple)
|
|
|
+ {
|
|
|
+ var multipleInfo = (MultipleInfo)PrintSettingsInfo.PrintModInfo;
|
|
|
+ if (PrintSettingsInfo.PageRangeList.Count / (multipleInfo.HorizontalPageNumber * multipleInfo.VerticalPageNumber) == 0)
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ///z
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
|
|
|
+ if (MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
|
|
|
+ if (MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
@@ -686,23 +880,23 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
- if (PDFViewer != null)
|
|
|
+ if (PDFViewer != null && PDFViewer.Document != null)
|
|
|
{
|
|
|
- //文件损坏导致无法读取
|
|
|
- try
|
|
|
+ for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
{
|
|
|
- for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
|
|
|
- {
|
|
|
- PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
- }
|
|
|
- NavigationParameters param = new NavigationParameters();
|
|
|
- NavigateDocumentRegion();
|
|
|
- NavigateModRegion();
|
|
|
- InitParamsByPDFView();
|
|
|
- }catch
|
|
|
+ PrintSettingsInfo.PageRangeList.Add(temp);
|
|
|
+ }
|
|
|
+ if (parameters.TryGetValue<int>(ParameterNames.PrintCurrentPage, out printCurrentPageIndex))
|
|
|
+ {
|
|
|
+ isCurrentPage = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- PDFViewer = null;
|
|
|
- }
|
|
|
+ isCurrentPage = false;
|
|
|
+ }
|
|
|
+ NavigationParameters param = new NavigationParameters();
|
|
|
+ NavigateDocumentRegion();
|
|
|
+ NavigateModRegion();
|
|
|
}
|
|
|
}
|
|
|
}
|