|
@@ -1,31 +1,17 @@
|
|
using ComPDFKit.Controls.Printer;
|
|
using ComPDFKit.Controls.Printer;
|
|
using ComPDFKit.Import;
|
|
using ComPDFKit.Import;
|
|
using ComPDFKit.PDFPage;
|
|
using ComPDFKit.PDFPage;
|
|
-using ComPDFKit.Tool.Help;
|
|
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Drawing;
|
|
-using System.Drawing.Imaging;
|
|
|
|
-using System.IO;
|
|
|
|
-using System.Linq;
|
|
|
|
|
|
+using System.Printing;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.CompilerServices;
|
|
-using System.Runtime.InteropServices;
|
|
|
|
-using System.Text;
|
|
|
|
-using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
-using System.Windows.Data;
|
|
|
|
-using System.Windows.Documents;
|
|
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
-using System.Windows.Media;
|
|
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Imaging;
|
|
-using System.Windows.Navigation;
|
|
|
|
-using System.Windows.Shapes;
|
|
|
|
-using System.Xml.Linq;
|
|
|
|
-using static System.Windows.Forms.AxHost;
|
|
|
|
using Color = System.Drawing.Color;
|
|
using Color = System.Drawing.Color;
|
|
-using Pen = System.Drawing.Pen;
|
|
|
|
using Point = System.Drawing.Point;
|
|
using Point = System.Drawing.Point;
|
|
using Rectangle = System.Drawing.Rectangle;
|
|
using Rectangle = System.Drawing.Rectangle;
|
|
|
|
|
|
@@ -40,21 +26,20 @@ namespace ComPDFKit.Controls.PDFControl
|
|
private double mmToDpiRatio = 100 / 25.4;
|
|
private double mmToDpiRatio = 100 / 25.4;
|
|
|
|
|
|
private PrintSettingsInfo printSettingsInfo;
|
|
private PrintSettingsInfo printSettingsInfo;
|
|
- private Bitmap blankPageBitmap;
|
|
|
|
|
|
|
|
private int originalPaperIndex;
|
|
private int originalPaperIndex;
|
|
private string _paperIndex = "1";
|
|
private string _paperIndex = "1";
|
|
public string PaperIndex
|
|
public string PaperIndex
|
|
{
|
|
{
|
|
get
|
|
get
|
|
- {
|
|
|
|
|
|
+ {
|
|
return _paperIndex;
|
|
return _paperIndex;
|
|
}
|
|
}
|
|
set
|
|
set
|
|
{
|
|
{
|
|
if (int.TryParse(value, out int paperIndex))
|
|
if (int.TryParse(value, out int paperIndex))
|
|
{
|
|
{
|
|
- if (paperIndex > 0 && paperIndex <= TargetPaperList.Count)
|
|
|
|
|
|
+ if (paperIndex > 0 && paperIndex <= printSettingsInfo.TargetPaperList.Count)
|
|
{
|
|
{
|
|
originalPaperIndex = paperIndex;
|
|
originalPaperIndex = paperIndex;
|
|
if (UpdateProper(ref _paperIndex, value))
|
|
if (UpdateProper(ref _paperIndex, value))
|
|
@@ -123,9 +108,18 @@ namespace ComPDFKit.Controls.PDFControl
|
|
set => UpdateProper(ref _priviewBitmapSource, value);
|
|
set => UpdateProper(ref _priviewBitmapSource, value);
|
|
}
|
|
}
|
|
|
|
|
|
- public List<int> TargetPaperList = new List<int>();
|
|
|
|
|
|
+ private Thickness _margins;
|
|
|
|
+ public Thickness Margins
|
|
|
|
+ {
|
|
|
|
+ get => _margins;
|
|
|
|
+ set => UpdateProper(ref _margins, value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private int _targetPaperIndex = 0;
|
|
private int _targetPaperIndex = 0;
|
|
|
|
+
|
|
|
|
+ private Bitmap blankPageBitmap;
|
|
|
|
+
|
|
public int TargetPaperIndex
|
|
public int TargetPaperIndex
|
|
{
|
|
{
|
|
get => _targetPaperIndex;
|
|
get => _targetPaperIndex;
|
|
@@ -144,31 +138,67 @@ namespace ComPDFKit.Controls.PDFControl
|
|
{
|
|
{
|
|
ViewBoxHeight = "248.0";
|
|
ViewBoxHeight = "248.0";
|
|
ViewBoxWidth = (width / height * 248.0).ToString();
|
|
ViewBoxWidth = (width / height * 248.0).ToString();
|
|
|
|
+ Margins = new Thickness()
|
|
|
|
+ {
|
|
|
|
+ Left = printSettingsInfo.Margins.Left * (248.0 / printSettingsInfo.PaperSize.Height),
|
|
|
|
+ Right = printSettingsInfo.Margins.Right * (248.0 / printSettingsInfo.PaperSize.Height),
|
|
|
|
+ Top = printSettingsInfo.Margins.Top * (248.0 / printSettingsInfo.PaperSize.Height),
|
|
|
|
+ Bottom = printSettingsInfo.Margins.Bottom * (248.0 / printSettingsInfo.PaperSize.Height)
|
|
|
|
+ };
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
ViewBoxWidth = "180.0";
|
|
ViewBoxWidth = "180.0";
|
|
ViewBoxHeight = (height / width * 180.0).ToString();
|
|
ViewBoxHeight = (height / width * 180.0).ToString();
|
|
|
|
+ Margins = new Thickness()
|
|
|
|
+ {
|
|
|
|
+ Left = printSettingsInfo.Margins.Left * (180.0 / printSettingsInfo.PaperSize.Width),
|
|
|
|
+ Right = printSettingsInfo.Margins.Right * (180.0 / printSettingsInfo.PaperSize.Width),
|
|
|
|
+ Top = printSettingsInfo.Margins.Top * (180.0 / printSettingsInfo.PaperSize.Width),
|
|
|
|
+ Bottom = printSettingsInfo.Margins.Bottom * (180.0 / printSettingsInfo.PaperSize.Width)
|
|
|
|
+ };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void SetPreviewBox()
|
|
private void SetPreviewBox()
|
|
{
|
|
{
|
|
PaperKind = printSettingsInfo.PaperSize.Kind.ToString();
|
|
PaperKind = printSettingsInfo.PaperSize.Kind.ToString();
|
|
- if (printSettingsInfo.PrintOrientation == PrintOrientation.Portrait)
|
|
|
|
|
|
+ if (printSettingsInfo.PrintOrientation == PageOrientation.Portrait)
|
|
{
|
|
{
|
|
- PaperWidth = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Width));
|
|
|
|
- PaperHeight = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Height));
|
|
|
|
|
|
+ SetPortrait();
|
|
|
|
+ }
|
|
|
|
+ else if (printSettingsInfo.PrintOrientation == PageOrientation.Landscape)
|
|
|
|
+ {
|
|
|
|
+ SetLandscape();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- PaperWidth = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Height));
|
|
|
|
- PaperHeight = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Width));
|
|
|
|
|
|
+ CPDFPage page = printSettingsInfo.Document.PageAtIndex(printSettingsInfo.TargetPaperList[TargetPaperIndex]);
|
|
|
|
+ if (page.PageSize.height > page.PageSize.width)
|
|
|
|
+ {
|
|
|
|
+ SetPortrait();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ SetLandscape();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!(printSettingsInfo.PrintMode is PosterModeInfo))
|
|
if (!(printSettingsInfo.PrintMode is PosterModeInfo))
|
|
{
|
|
{
|
|
SetViewBox(double.Parse(PaperHeight), double.Parse(PaperWidth));
|
|
SetViewBox(double.Parse(PaperHeight), double.Parse(PaperWidth));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ void SetPortrait()
|
|
|
|
+ {
|
|
|
|
+ PaperWidth = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Width));
|
|
|
|
+ PaperHeight = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Height));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void SetLandscape()
|
|
|
|
+ {
|
|
|
|
+ PaperWidth = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Height));
|
|
|
|
+ PaperHeight = string.Format("{0:F1}", (printSettingsInfo.PaperSize.Width));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
internal void Init(PrintSettingsInfo printSettingsInfo, bool needPageReset = false)
|
|
internal void Init(PrintSettingsInfo printSettingsInfo, bool needPageReset = false)
|
|
@@ -182,15 +212,18 @@ namespace ComPDFKit.Controls.PDFControl
|
|
|
|
|
|
private void CreateBlankBitmap()
|
|
private void CreateBlankBitmap()
|
|
{
|
|
{
|
|
- int width = printSettingsInfo.PrintOrientation == PrintOrientation.Portrait
|
|
|
|
- ? printSettingsInfo.PaperSize.Width
|
|
|
|
- : printSettingsInfo.PaperSize.Height;
|
|
|
|
|
|
+ CPDFPage page = printSettingsInfo.Document.PageAtIndex(printSettingsInfo.TargetPaperList[TargetPaperIndex]);
|
|
|
|
+ double height = 0;
|
|
|
|
+ double width = 0;
|
|
|
|
+ width = printSettingsInfo.PrintOrientation == PageOrientation.Portrait
|
|
|
|
+ ? printSettingsInfo.ActualWidth
|
|
|
|
+ : printSettingsInfo.ActualHeight;
|
|
|
|
|
|
- int height = printSettingsInfo.PrintOrientation == PrintOrientation.Portrait
|
|
|
|
- ? printSettingsInfo.PaperSize.Height
|
|
|
|
- : printSettingsInfo.PaperSize.Width;
|
|
|
|
|
|
+ height = printSettingsInfo.PrintOrientation == PageOrientation.Portrait
|
|
|
|
+ ? printSettingsInfo.ActualHeight
|
|
|
|
+ : printSettingsInfo.ActualWidth;
|
|
|
|
|
|
- blankPageBitmap = new Bitmap(width, height);
|
|
|
|
|
|
+ blankPageBitmap = new Bitmap((int)width, (int)height);
|
|
|
|
|
|
using (Graphics g = Graphics.FromImage(blankPageBitmap))
|
|
using (Graphics g = Graphics.FromImage(blankPageBitmap))
|
|
{
|
|
{
|
|
@@ -200,15 +233,15 @@ namespace ComPDFKit.Controls.PDFControl
|
|
|
|
|
|
public void CalculatePaperCollection(bool needPageReset = false)
|
|
public void CalculatePaperCollection(bool needPageReset = false)
|
|
{
|
|
{
|
|
- TargetPaperList = new List<int>(printSettingsInfo.PageRangeList);
|
|
|
|
|
|
+ printSettingsInfo.TargetPaperList = new List<int>(printSettingsInfo.PageRangeList);
|
|
if (printSettingsInfo.IsReverseOrder)
|
|
if (printSettingsInfo.IsReverseOrder)
|
|
{
|
|
{
|
|
- TargetPaperList.Reverse();
|
|
|
|
|
|
+ printSettingsInfo.TargetPaperList.Reverse();
|
|
}
|
|
}
|
|
if (needPageReset)
|
|
if (needPageReset)
|
|
{
|
|
{
|
|
PaperIndex = "1";
|
|
PaperIndex = "1";
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public PrintPreviewControl()
|
|
public PrintPreviewControl()
|
|
@@ -220,11 +253,10 @@ namespace ComPDFKit.Controls.PDFControl
|
|
private readonly object lockObject = new object();
|
|
private readonly object lockObject = new object();
|
|
private void PaintPageByCurrentPreviewIndex()
|
|
private void PaintPageByCurrentPreviewIndex()
|
|
{
|
|
{
|
|
- CreateBlankBitmap();
|
|
|
|
- SetPreviewBox();
|
|
|
|
lock (lockObject)
|
|
lock (lockObject)
|
|
{
|
|
{
|
|
- PreviewPageBySizeMode(TargetPaperList[TargetPaperIndex]);
|
|
|
|
|
|
+ CreateBlankBitmap();
|
|
|
|
+ PreviewPageBySizeMode(printSettingsInfo.TargetPaperList[TargetPaperIndex]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -288,7 +320,7 @@ namespace ComPDFKit.Controls.PDFControl
|
|
|
|
|
|
if (page != null)
|
|
if (page != null)
|
|
{
|
|
{
|
|
- page.RenderPageBitmapWithMatrix((float)1, pageRect, 0xFFFFFFFF, bmpData, printSettingsInfo.IsPrintAnnot?1:0, printSettingsInfo.IsPrintForm);
|
|
|
|
|
|
+ page.RenderPageBitmapWithMatrix((float)1, pageRect, 0xFFFFFFFF, bmpData, printSettingsInfo.IsPrintAnnot ? 1 : 0, printSettingsInfo.IsPrintForm);
|
|
Point startPoint = new Point(0, 0);
|
|
Point startPoint = new Point(0, 0);
|
|
|
|
|
|
Bitmap bitmap = PrintHelper.BuildBmp((int)pageRect.width(), (int)pageRect.height(), bmpData);
|
|
Bitmap bitmap = PrintHelper.BuildBmp((int)pageRect.width(), (int)pageRect.height(), bmpData);
|
|
@@ -302,15 +334,31 @@ namespace ComPDFKit.Controls.PDFControl
|
|
{
|
|
{
|
|
int resizedHeight = 0;
|
|
int resizedHeight = 0;
|
|
int resizedWidth = 0;
|
|
int resizedWidth = 0;
|
|
- if (bitmap.Height / bitmap.Width >= (float.Parse(PaperHeight) / float.Parse(PaperWidth)))
|
|
|
|
|
|
+ if (bitmap.Height / bitmap.Width >= (printSettingsInfo.ActualHeight / printSettingsInfo.ActualWidth))
|
|
{
|
|
{
|
|
- resizedHeight = (int)(float.Parse(PaperHeight));
|
|
|
|
- resizedWidth = (int)((float.Parse(PaperHeight) / bitmap.Height * bitmap.Width));
|
|
|
|
|
|
+ if (printSettingsInfo.PrintOrientation == PageOrientation.Portrait)
|
|
|
|
+ {
|
|
|
|
+ resizedHeight = (int)printSettingsInfo.ActualHeight;
|
|
|
|
+ resizedWidth = (int)(printSettingsInfo.ActualHeight / bitmap.Height * bitmap.Width);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ resizedWidth = (int)printSettingsInfo.ActualHeight;
|
|
|
|
+ resizedHeight = (int)(printSettingsInfo.ActualHeight / bitmap.Height * bitmap.Width);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- resizedWidth = (int)(float.Parse(PaperWidth));
|
|
|
|
- resizedHeight = (int)((float.Parse(PaperWidth) / bitmap.Width * bitmap.Height));
|
|
|
|
|
|
+ if (printSettingsInfo.PrintOrientation == PageOrientation.Portrait)
|
|
|
|
+ {
|
|
|
|
+ resizedWidth = (int)printSettingsInfo.ActualWidth;
|
|
|
|
+ resizedHeight = (int)(printSettingsInfo.ActualWidth / bitmap.Width * bitmap.Height);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ resizedHeight = (int)printSettingsInfo.ActualWidth;
|
|
|
|
+ resizedWidth = (int)(printSettingsInfo.ActualWidth / bitmap.Height * bitmap.Width);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
bitmap = Resize(bitmap, resizedWidth, resizedHeight);
|
|
bitmap = Resize(bitmap, resizedWidth, resizedHeight);
|
|
@@ -325,11 +373,11 @@ namespace ComPDFKit.Controls.PDFControl
|
|
startPoint.X = (blankPageBitmap.Width - bitmap.Width) / 2;
|
|
startPoint.X = (blankPageBitmap.Width - bitmap.Width) / 2;
|
|
startPoint.Y = (blankPageBitmap.Height - bitmap.Height) / 2;
|
|
startPoint.Y = (blankPageBitmap.Height - bitmap.Height) / 2;
|
|
printBitmap = PrintHelper.CombineBitmap(blankPageBitmap, bitmap, startPoint);
|
|
printBitmap = PrintHelper.CombineBitmap(blankPageBitmap, bitmap, startPoint);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- // 按比例缩小bitmap
|
|
|
|
float scale = sizeModeInfo.SizeType == SizeType.Customized ? sizeModeInfo.Scale : 1;
|
|
float scale = sizeModeInfo.SizeType == SizeType.Customized ? sizeModeInfo.Scale : 1;
|
|
bitmap = PrintHelper.ResizeBitmap(bitmap, scale);
|
|
bitmap = PrintHelper.ResizeBitmap(bitmap, scale);
|
|
startPoint.X = (blankPageBitmap.Width - bitmap.Width) / 2;
|
|
startPoint.X = (blankPageBitmap.Width - bitmap.Width) / 2;
|
|
@@ -354,7 +402,7 @@ namespace ComPDFKit.Controls.PDFControl
|
|
{
|
|
{
|
|
if (object.Equals(properValue, newValue))
|
|
if (object.Equals(properValue, newValue))
|
|
return false;
|
|
return false;
|
|
-
|
|
|
|
|
|
+
|
|
properValue = newValue;
|
|
properValue = newValue;
|
|
OnPropertyChanged(properName);
|
|
OnPropertyChanged(properName);
|
|
return true;
|
|
return true;
|
|
@@ -382,7 +430,7 @@ namespace ComPDFKit.Controls.PDFControl
|
|
|
|
|
|
private void txbPageIndex_LostFocus(object sender, RoutedEventArgs e)
|
|
private void txbPageIndex_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
- if(PaperIndex == string.Empty)
|
|
|
|
|
|
+ if (PaperIndex == string.Empty)
|
|
{
|
|
{
|
|
PaperIndex = (originalPaperIndex).ToString();
|
|
PaperIndex = (originalPaperIndex).ToString();
|
|
}
|
|
}
|
|
@@ -390,8 +438,8 @@ namespace ComPDFKit.Controls.PDFControl
|
|
|
|
|
|
private void txbPageIndex_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
|
private void txbPageIndex_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
|
{
|
|
{
|
|
- if (e.NewFocus is Button button && (button == btnNextButton||button == btnPreButton))
|
|
|
|
- {
|
|
|
|
|
|
+ if (e.NewFocus is Button button && (button == btnNextButton || button == btnPreButton))
|
|
|
|
+ {
|
|
e.Handled = true;
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|