|
@@ -1327,6 +1327,17 @@ namespace XHWK.WKTool
|
1327
|
1327
|
/// <param name="e"></param>
|
1328
|
1328
|
private void BtnAdd_Click(object sender, RoutedEventArgs e)
|
1329
|
1329
|
{
|
|
1330
|
+ // RectangleF rectangleF = new RectangleF();
|
|
1331
|
+ // rectangleF.Width = (float)APP.PageDrawList[0].ImageSizes.CenterX;
|
|
1332
|
+ // rectangleF.Height = (float)APP.PageDrawList[0].ImageSizes.CenterY;
|
|
1333
|
+ // rectangleF.X= (float)APP.PageDrawList[0].ImageLocation.X;
|
|
1334
|
+ // rectangleF.Y = (float)APP.PageDrawList[0].ImageLocation.Y;
|
|
1335
|
+
|
|
1336
|
+ // //CESHI
|
|
1337
|
+ //bool isImg= MergerImg(APP.PageDrawList[0].PageImagePath, @"G:\102H.jpg", rectangleF, out string errmsg);
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
|
1330
|
1341
|
if (APP.pageData.currpage>0)
|
1331
|
1342
|
{
|
1332
|
1343
|
APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
|
|
@@ -1360,7 +1371,11 @@ namespace XHWK.WKTool
|
1360
|
1371
|
{
|
1361
|
1372
|
try
|
1362
|
1373
|
{
|
1363
|
|
- iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
|
|
1374
|
+ //3种情况 1.文档图片 2.截图图片 3.没有图片
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+ iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
|
1364
|
1379
|
//iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
|
1365
|
1380
|
////设置纸张横向
|
1366
|
1381
|
//document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
|
|
@@ -1373,10 +1388,42 @@ namespace XHWK.WKTool
|
1373
|
1388
|
iTextSharp.text.Image image;
|
1374
|
1389
|
for (int i = 0; i < APP.PageDrawList.Count; i++)
|
1375
|
1390
|
{
|
1376
|
|
- if (String.IsNullOrEmpty(APP.PageDrawList[i].PdfImagePath)) break;
|
|
1391
|
+ long ii = Timestamp();
|
|
1392
|
+ string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
|
|
1393
|
+ string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
|
|
1394
|
+ RectangleF rectangleFs = new RectangleF();
|
|
1395
|
+ MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
|
|
1396
|
+ image = iTextSharp.text.Image.GetInstance(filePathOutPut);
|
|
1397
|
+ if (String.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
|
|
1398
|
+ {
|
|
1399
|
+
|
|
1400
|
+ }
|
|
1401
|
+ else if(APP.PageDrawList[i].ImgDocumentation==true)
|
|
1402
|
+ {
|
|
1403
|
+ image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
|
|
1404
|
+ }
|
|
1405
|
+ else
|
|
1406
|
+ {
|
|
1407
|
+ RectangleF rectangleF = new RectangleF();
|
|
1408
|
+ rectangleF.Width = (float)APP.PageDrawList[i].ImageSizes.CenterX;
|
|
1409
|
+ rectangleF.Height = (float)APP.PageDrawList[i].ImageSizes.CenterY;
|
|
1410
|
+ rectangleF.X = (float)APP.PageDrawList[i].ImageLocation.X;
|
|
1411
|
+ rectangleF.Y = (float)APP.PageDrawList[i].ImageLocation.Y;
|
1377
|
1412
|
|
1378
|
1413
|
|
1379
|
|
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PdfImagePath);
|
|
1414
|
+ string msg = string.Empty;
|
|
1415
|
+ bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
|
|
1416
|
+ if(isImg)
|
|
1417
|
+ {
|
|
1418
|
+ image = iTextSharp.text.Image.GetInstance(filePathOutPut);
|
|
1419
|
+ }
|
|
1420
|
+ else
|
|
1421
|
+ {
|
|
1422
|
+ image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
|
|
1423
|
+ }
|
|
1424
|
+ }
|
|
1425
|
+
|
|
1426
|
+
|
1380
|
1427
|
|
1381
|
1428
|
|
1382
|
1429
|
if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
|
|
@@ -1402,6 +1449,23 @@ namespace XHWK.WKTool
|
1402
|
1449
|
{
|
1403
|
1450
|
Console.WriteLine("转换失败,原因:" + ex.Message);
|
1404
|
1451
|
}
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
1405
|
1469
|
//document.Close();
|
1406
|
1470
|
////Console.ReadKey();
|
1407
|
1471
|
if (APP.W_PrintWindow == null)
|
|
@@ -1605,6 +1669,54 @@ namespace XHWK.WKTool
|
1605
|
1669
|
}
|
1606
|
1670
|
}
|
1607
|
1671
|
/// <summary>
|
|
1672
|
+ /// 生成图片
|
|
1673
|
+ /// </summary>
|
|
1674
|
+ /// <param name="_path">图片地址</param>
|
|
1675
|
+ /// <param name="_saveimg">保存位置</param>
|
|
1676
|
+ /// <param name="_rectangle">图片位置</param>
|
|
1677
|
+ /// <param name="errmsg">错误消息</param>
|
|
1678
|
+ /// <returns></returns>
|
|
1679
|
+ private bool MergerImg(string _path,string _saveimg,RectangleF _rectangle, out string errmsg)
|
|
1680
|
+ {
|
|
1681
|
+ errmsg = null;
|
|
1682
|
+ try
|
|
1683
|
+ {
|
|
1684
|
+ Bitmap bitmap = null;
|
|
1685
|
+
|
|
1686
|
+ //创建要显示的图片对象,根据参数的个数设置宽度
|
|
1687
|
+ Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
|
|
1688
|
+ Graphics g = Graphics.FromImage(backgroudImg);
|
|
1689
|
+ //清除画布,背景设置为白色
|
|
1690
|
+ g.Clear(System.Drawing.Color.White);
|
|
1691
|
+
|
|
1692
|
+ if(!string.IsNullOrWhiteSpace(_path))
|
|
1693
|
+ {
|
|
1694
|
+ bitmap = ImageHelper.ReadBitmapFile(_path);
|
|
1695
|
+ g.DrawImage(bitmap, _rectangle);
|
|
1696
|
+ }
|
|
1697
|
+
|
|
1698
|
+
|
|
1699
|
+ backgroudImg.Save(_saveimg);
|
|
1700
|
+
|
|
1701
|
+ g.Dispose();
|
|
1702
|
+ backgroudImg.Dispose();
|
|
1703
|
+ if(bitmap!=null)
|
|
1704
|
+ {
|
|
1705
|
+ bitmap.Dispose();
|
|
1706
|
+ }
|
|
1707
|
+
|
|
1708
|
+ GC.Collect();
|
|
1709
|
+ return true;
|
|
1710
|
+ }
|
|
1711
|
+ catch (Exception ex)
|
|
1712
|
+ {
|
|
1713
|
+ errmsg = ex.Message;
|
|
1714
|
+ LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message,ex);
|
|
1715
|
+ return false;
|
|
1716
|
+ }
|
|
1717
|
+
|
|
1718
|
+ }
|
|
1719
|
+ /// <summary>
|
1608
|
1720
|
/// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
|
1609
|
1721
|
/// "ImageFile", 1, 20, ImageFormat.Png, 256);
|
1610
|
1722
|
/// </summary>
|