|
@@ -42,6 +42,10 @@ namespace XHWK.WKTool
|
42
|
42
|
public event ChangeTextHandler ChangeTextEvent;
|
43
|
43
|
//定义委托
|
44
|
44
|
public delegate void ChangeTextHandler(string text);
|
|
45
|
+ /// <summary>
|
|
46
|
+ /// 图片
|
|
47
|
+ /// </summary>
|
|
48
|
+ string [] ImgPDFPath = new string[300];
|
45
|
49
|
#endregion
|
46
|
50
|
|
47
|
51
|
#region 初始化
|
|
@@ -86,6 +90,8 @@ namespace XHWK.WKTool
|
86
|
90
|
drawingAttributes.IgnorePressure = false;
|
87
|
91
|
blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
|
88
|
92
|
wfhCamera.Visibility = Visibility.Hidden;
|
|
93
|
+ ImgPDFPath = null;
|
|
94
|
+ ImgPDFPath = new string[300];
|
89
|
95
|
}
|
90
|
96
|
#endregion
|
91
|
97
|
|
|
@@ -505,7 +511,7 @@ namespace XHWK.WKTool
|
505
|
511
|
Thread.Sleep(400);
|
506
|
512
|
Dispatcher.Invoke(new Action(() =>
|
507
|
513
|
{
|
508
|
|
- OpenDialogPPT();
|
|
514
|
+ OpenDialog();
|
509
|
515
|
}
|
510
|
516
|
));
|
511
|
517
|
})
|
|
@@ -519,36 +525,6 @@ namespace XHWK.WKTool
|
519
|
525
|
}
|
520
|
526
|
}
|
521
|
527
|
private void OpenDialog()
|
522
|
|
- {
|
523
|
|
- result = ofd.ShowDialog();
|
524
|
|
- if (result == System.Windows.Forms.DialogResult.OK)
|
525
|
|
- {
|
526
|
|
- if (ofd.FileName != "")
|
527
|
|
- {
|
528
|
|
- string filepath = ofd.FileName;
|
529
|
|
- string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
|
530
|
|
- APP.Paths = ConvertWordToImage(filepath, path, "", 0, 0, null, 0).ToArray();
|
531
|
|
-
|
532
|
|
- for (int i = 0; i < APP.Paths.Length; i++)
|
533
|
|
- {
|
534
|
|
- APP.pageData.pagenum += 1;
|
535
|
|
- }
|
536
|
|
- if (APP.pageData.pagenum > 1)
|
537
|
|
- {
|
538
|
|
- APP.pageData.pagenum -= 1;
|
539
|
|
- }
|
540
|
|
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
|
541
|
|
- {
|
542
|
|
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
|
543
|
|
- }
|
544
|
|
- else
|
545
|
|
- {
|
546
|
|
- imgCanvas.Source = null;
|
547
|
|
- }
|
548
|
|
- }
|
549
|
|
- }
|
550
|
|
- }
|
551
|
|
- private void OpenDialogPPT()
|
552
|
528
|
{
|
553
|
529
|
result = ofd.ShowDialog();
|
554
|
530
|
if (result == System.Windows.Forms.DialogResult.OK)
|
|
@@ -558,68 +534,110 @@ namespace XHWK.WKTool
|
558
|
534
|
#region PPT转PDF
|
559
|
535
|
string filepath = ofd.FileName;
|
560
|
536
|
string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
|
561
|
|
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
|
562
|
|
- path = pathTemp + path + ".pdf";
|
563
|
|
- //PPT转PDF
|
564
|
|
- Presentation ppt = new Presentation(filepath);
|
565
|
|
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
|
566
|
|
- #endregion
|
567
|
|
-
|
568
|
|
-
|
569
|
|
- #region PDF转图片
|
570
|
|
- // 图片绝对路径集合
|
571
|
|
- List<string> images = new List<string>();
|
572
|
|
- string directoryPath = pathTemp;
|
573
|
|
- //aspose许可证
|
574
|
|
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
|
575
|
|
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
|
576
|
|
- //l.SetLicense(licenseName);
|
577
|
|
- //定义Jpeg转换设备
|
578
|
|
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
|
579
|
|
- var device = new Aspose.Pdf.Devices.JpegDevice();
|
580
|
|
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
|
581
|
|
- //directoryPath += quality;
|
582
|
|
- Directory.CreateDirectory(directoryPath);
|
583
|
|
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
|
584
|
|
- device = new Aspose.Pdf.Devices.JpegDevice(100);
|
585
|
|
- //遍历每一页转为jpg
|
586
|
|
- for (var i = 1; i <= document.Pages.Count; i++)
|
|
537
|
+ string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
|
|
538
|
+ if (type.Contains("typezsygppt"))
|
587
|
539
|
{
|
588
|
|
- long ii = Timestamp();
|
589
|
|
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
|
590
|
|
- images.Add(filePathOutPut);
|
591
|
|
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
|
592
|
540
|
try
|
593
|
541
|
{
|
594
|
|
- device.Process(document.Pages[i], fs);
|
595
|
|
- fs.Close();
|
|
542
|
+ string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
|
|
543
|
+ path = pathTemp + path + ".pdf";
|
|
544
|
+ //PPT转PDF
|
|
545
|
+ Presentation ppt = new Presentation(filepath);
|
|
546
|
+ ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
|
|
547
|
+ #endregion
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+ #region PDF转图片
|
|
551
|
+ // 图片绝对路径集合
|
|
552
|
+ List<string> images = new List<string>();
|
|
553
|
+ string directoryPath = pathTemp;
|
|
554
|
+ //aspose许可证
|
|
555
|
+ //Aspose.Pdf.License l = new Aspose.Pdf.License();
|
|
556
|
+ //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
|
|
557
|
+ //l.SetLicense(licenseName);
|
|
558
|
+ //定义Jpeg转换设备
|
|
559
|
+ Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
|
|
560
|
+ var device = new Aspose.Pdf.Devices.JpegDevice();
|
|
561
|
+ //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
|
|
562
|
+ //directoryPath += quality;
|
|
563
|
+ Directory.CreateDirectory(directoryPath);
|
|
564
|
+ //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
|
|
565
|
+ device = new Aspose.Pdf.Devices.JpegDevice(100);
|
|
566
|
+ //遍历每一页转为jpg
|
|
567
|
+ for (var i = 1; i <= document.Pages.Count; i++)
|
|
568
|
+ {
|
|
569
|
+ long ii = Timestamp();
|
|
570
|
+ string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
|
|
571
|
+ images.Add(filePathOutPut);
|
|
572
|
+ FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
|
|
573
|
+ try
|
|
574
|
+ {
|
|
575
|
+ device.Process(document.Pages[i], fs);
|
|
576
|
+ fs.Close();
|
|
577
|
+ }
|
|
578
|
+ catch (Exception ex)
|
|
579
|
+ {
|
|
580
|
+ fs.Close();
|
|
581
|
+ File.Delete(filePathOutPut);
|
|
582
|
+ }
|
|
583
|
+ }
|
|
584
|
+ #endregion
|
|
585
|
+
|
|
586
|
+ APP.Paths = images.ToArray();
|
|
587
|
+ ImgPDFPath = images.ToArray();
|
|
588
|
+ for (int i = 0; i < APP.Paths.Length; i++)
|
|
589
|
+ {
|
|
590
|
+ APP.pageData.pagenum += 1;
|
|
591
|
+ }
|
|
592
|
+ if (APP.pageData.pagenum > 1)
|
|
593
|
+ {
|
|
594
|
+ APP.pageData.pagenum -= 1;
|
|
595
|
+ }
|
|
596
|
+ if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
|
|
597
|
+ {
|
|
598
|
+ imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
|
|
599
|
+ }
|
|
600
|
+ else
|
|
601
|
+ {
|
|
602
|
+ imgCanvas.Source = null;
|
|
603
|
+ }
|
596
|
604
|
}
|
597
|
605
|
catch (Exception ex)
|
598
|
606
|
{
|
599
|
|
- fs.Close();
|
600
|
|
- File.Delete(filePathOutPut);
|
|
607
|
+ LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
|
601
|
608
|
}
|
602
|
|
- }
|
603
|
|
- #endregion
|
604
|
|
-
|
605
|
|
- APP.Paths = images.ToArray();
|
606
|
|
-
|
607
|
|
- for (int i = 0; i < APP.Paths.Length; i++)
|
608
|
|
- {
|
609
|
|
- APP.pageData.pagenum += 1;
|
610
|
|
- }
|
611
|
|
- if (APP.pageData.pagenum > 1)
|
612
|
|
- {
|
613
|
|
- APP.pageData.pagenum -= 1;
|
614
|
|
- }
|
615
|
|
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
|
616
|
|
- {
|
617
|
|
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
|
618
|
609
|
}
|
619
|
610
|
else
|
620
|
611
|
{
|
621
|
|
- imgCanvas.Source = null;
|
|
612
|
+ try
|
|
613
|
+ {
|
|
614
|
+ string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
|
|
615
|
+ APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
|
|
616
|
+
|
|
617
|
+ for (int i = 0; i < APP.Paths.Length; i++)
|
|
618
|
+ {
|
|
619
|
+ APP.pageData.pagenum += 1;
|
|
620
|
+ }
|
|
621
|
+ if (APP.pageData.pagenum > 1)
|
|
622
|
+ {
|
|
623
|
+ APP.pageData.pagenum -= 1;
|
|
624
|
+ }
|
|
625
|
+ if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
|
|
626
|
+ {
|
|
627
|
+ imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
|
|
628
|
+ }
|
|
629
|
+ else
|
|
630
|
+ {
|
|
631
|
+ imgCanvas.Source = null;
|
|
632
|
+ }
|
|
633
|
+ }
|
|
634
|
+ catch (Exception ex)
|
|
635
|
+ {
|
|
636
|
+ LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
|
|
637
|
+ }
|
622
|
638
|
}
|
|
639
|
+
|
|
640
|
+
|
623
|
641
|
}
|
624
|
642
|
}
|
625
|
643
|
}
|
|
@@ -923,6 +941,63 @@ namespace XHWK.WKTool
|
923
|
941
|
/// <param name="e"></param>
|
924
|
942
|
private void BtnPrint_Click(object sender, RoutedEventArgs e)
|
925
|
943
|
{
|
|
944
|
+ if (APP.IsLoginType == false)
|
|
945
|
+ {
|
|
946
|
+ Login();
|
|
947
|
+ return;
|
|
948
|
+ }
|
|
949
|
+
|
|
950
|
+ //for(int i=0;i< APP.pageData.pagenum; i++)
|
|
951
|
+ //{
|
|
952
|
+
|
|
953
|
+ //}
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+ ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
|
|
958
|
+ iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
|
|
959
|
+ try
|
|
960
|
+ {
|
|
961
|
+ //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
|
|
962
|
+ //设置纸张横向
|
|
963
|
+ document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+ iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
|
|
967
|
+ document.Open();
|
|
968
|
+ iTextSharp.text.Image image;
|
|
969
|
+ for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
|
|
970
|
+ {
|
|
971
|
+ if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+ image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+ if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
|
|
978
|
+ {
|
|
979
|
+ image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
|
|
980
|
+ }
|
|
981
|
+ else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
|
|
982
|
+ {
|
|
983
|
+ image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
|
|
984
|
+ }
|
|
985
|
+ image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
|
|
986
|
+ document.NewPage();
|
|
987
|
+ document.Add(image);
|
|
988
|
+ //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
|
|
989
|
+ //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
|
|
990
|
+ //p1.Leading = 150; //行间距
|
|
991
|
+ //document.Add(p1);
|
|
992
|
+ }
|
|
993
|
+ Console.WriteLine("转换成功!");
|
|
994
|
+ }
|
|
995
|
+ catch (Exception ex)
|
|
996
|
+ {
|
|
997
|
+ Console.WriteLine("转换失败,原因:" + ex.Message);
|
|
998
|
+ }
|
|
999
|
+ document.Close();
|
|
1000
|
+ ////Console.ReadKey();
|
926
|
1001
|
|
927
|
1002
|
}
|
928
|
1003
|
/// <summary>
|
|
@@ -947,6 +1022,21 @@ namespace XHWK.WKTool
|
947
|
1022
|
{
|
948
|
1023
|
if (APP.pageData.currpage > 1)
|
949
|
1024
|
{
|
|
1025
|
+ try
|
|
1026
|
+ {
|
|
1027
|
+ Dispatcher.Invoke(() =>
|
|
1028
|
+ {
|
|
1029
|
+ string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
|
|
1030
|
+ FileToolsCommon.CreateDirectory(filePath);
|
|
1031
|
+ string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
|
|
1032
|
+ ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
|
|
1033
|
+ ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
|
|
1034
|
+ });
|
|
1035
|
+ }
|
|
1036
|
+ catch (Exception ex)
|
|
1037
|
+ {
|
|
1038
|
+ LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
|
|
1039
|
+ }
|
950
|
1040
|
APP.pageData.currpage -= 1;
|
951
|
1041
|
myblackboard.changepage(APP.pageData.currpage - 1);
|
952
|
1042
|
if (APP.Paths.Length > 0)
|
|
@@ -976,11 +1066,26 @@ namespace XHWK.WKTool
|
976
|
1066
|
{
|
977
|
1067
|
if (APP.pageData.currpage < APP.pageData.pagenum)
|
978
|
1068
|
{
|
|
1069
|
+ try
|
|
1070
|
+ {
|
|
1071
|
+ Dispatcher.Invoke(() =>
|
|
1072
|
+ {
|
|
1073
|
+ string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
|
|
1074
|
+ FileToolsCommon.CreateDirectory(filePath);
|
|
1075
|
+ string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
|
|
1076
|
+ ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
|
|
1077
|
+ ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
|
|
1078
|
+ });
|
|
1079
|
+ }
|
|
1080
|
+ catch (Exception ex)
|
|
1081
|
+ {
|
|
1082
|
+ LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
|
|
1083
|
+ }
|
979
|
1084
|
APP.pageData.currpage += 1;
|
980
|
1085
|
myblackboard.changepage(APP.pageData.currpage - 1);
|
981
|
1086
|
if (APP.Paths.Length > 0)
|
982
|
1087
|
{
|
983
|
|
-
|
|
1088
|
+
|
984
|
1089
|
if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
|
985
|
1090
|
{
|
986
|
1091
|
imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
|