异步
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
"urls": "http://0.0.0.0:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
||||
"corsUrls": [ "http://localhost:8887", "http://localhost:8886", "http://localhost:9090", "http://localhost:8080" ], //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
|
||||
"Upload": {
|
||||
"rootDirectory": "D:/MES/file",
|
||||
"rootDirectory": "F:/MES/file",
|
||||
"uploadUrl": "http://172.18.32.1:8888", //本地存储资源访问路径
|
||||
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
|
||||
"maxSize": 30, //上传文件大小限制 15M
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
"IsAutoCloseConnection": true,
|
||||
"DbName": "bzfm_mes" //代码生成默认连接数据库,Oracle库是实例的名称
|
||||
},
|
||||
"ShowDbLog": false, //是否打印db日志
|
||||
"urls": "http://0.0.0.0:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
||||
"ShowDbLog": true, //是否打印db日志
|
||||
"urls": "http://*.*.*.*:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
|
||||
"corsUrls": [ "http://localhost:8887", "http://localhost:8886", "http://localhost:9090", "http://localhost:8080" ], //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
|
||||
"Upload": {
|
||||
"rootDirectory": "D:/MES/file",
|
||||
"uploadUrl": "http://127.0.0.1:7000", //本地存储资源访问路径
|
||||
"rootDirectory": "D:/mes/file",
|
||||
"uploadUrl": "http://192.168.1.106:8888", //本地存储资源访问路径
|
||||
"localSavePath": "", //本地上传默认文件存储目录 wwwroot+localSavePath
|
||||
"maxSize": 15, //上传文件大小限制 15M
|
||||
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
|
||||
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ],
|
||||
"requestLimitSize": 1024
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NPOI" Version="2.7.2" />
|
||||
<PackageReference Include="QuestPDF" Version="2024.12.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DOAN.ServiceCore\DOAN.ServiceCore.csproj" />
|
||||
|
||||
@@ -1319,60 +1319,64 @@ namespace DOAN.Service.MES.product
|
||||
var ms = new MemoryStream();
|
||||
Settings.License = LicenseType.Community;
|
||||
Settings.CheckIfAllTextGlyphsAreAvailable = false;
|
||||
var document = QuestPDF.Fluent.Document.Create(container =>
|
||||
await Task.Run(() =>
|
||||
{
|
||||
int PageWidth = 40 * 10;
|
||||
int PageHeight = 30 * 10;
|
||||
for (int i = 0; i < dataList.Count(); i++)
|
||||
var document = QuestPDF.Fluent.Document.Create(container =>
|
||||
{
|
||||
byte[] imageBytes = PrintHelper.CreateBarCode(dataList[i].Workorder, PageWidth * 3, PageHeight);
|
||||
container.Page(page =>
|
||||
int PageWidth = 40 * 10;
|
||||
int PageHeight = 30 * 10;
|
||||
for (int i = 0; i < dataList.Count(); i++)
|
||||
{
|
||||
// 设置页面大小为A4,默认有页边距
|
||||
//page.Size(new PageSize(40*10,30*10)); // 移除默认页边距或设置自定义边距
|
||||
|
||||
page.Size(PageWidth, PageHeight);
|
||||
page.DefaultTextStyle(TextStyle.Default.FontSize(16*2-5));
|
||||
//page.DefaultTextStyle(TextStyle.Default.FontSize(1));
|
||||
page.Content().Column(column =>
|
||||
byte[] imageBytes = PrintHelper.CreateQcCode(dataList[i].Workorder, PageHeight * 40 + 100, PageHeight * 20);
|
||||
container.Page(page =>
|
||||
{
|
||||
column.Item().Table(table =>
|
||||
// 设置页面大小为A4,默认有页边距
|
||||
//page.Size(new PageSize(40*10,30*10)); // 移除默认页边距或设置自定义边距
|
||||
|
||||
page.Size(PageWidth, PageHeight);
|
||||
page.DefaultTextStyle(TextStyle.Default.FontSize(10 * 2 + 2));
|
||||
//page.DefaultTextStyle(TextStyle.Default.FontSize(1));
|
||||
page.Content().Column(column =>
|
||||
{
|
||||
// 动态计算列宽,减去必要的边距
|
||||
float columnWidth = (PageWidth) / 8;
|
||||
|
||||
table.ColumnsDefinition(columns =>
|
||||
column.Item().Table(table =>
|
||||
{
|
||||
// 动态计算列宽,减去必要的边距
|
||||
float columnWidth = (PageWidth) / 8;
|
||||
|
||||
table.ColumnsDefinition(columns =>
|
||||
{
|
||||
for (int j = 0; j < 8; j++)
|
||||
columns.ConstantColumn(columnWidth);
|
||||
});
|
||||
|
||||
// 创建一个单元格跨越所有列,用于放置图片
|
||||
table.Cell().ColumnSpan(8).Height(PageHeight / 14 * 8).Image(imageBytes);
|
||||
|
||||
|
||||
// 剩余内容...
|
||||
// 注意:确保剩余内容的高度不超过剩余的页面空间
|
||||
// 这里只是一个简单的例子,实际应用中你可能需要更复杂的逻辑来计算剩余可用空间
|
||||
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 7).AlignLeft().Padding(1).Text("编号");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].Workorder);
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text("炉号");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].StoveCode);
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text("数量");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].PlanNum);
|
||||
for (int j = 0; j < 8; j++)
|
||||
columns.ConstantColumn(columnWidth);
|
||||
{
|
||||
table.Cell().Border(1).MinHeight(PageHeight / 14).AlignCenter().Text($"[{j + 1}]");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 创建一个单元格跨越所有列,用于放置图片
|
||||
table.Cell().ColumnSpan(8).Image(imageBytes);
|
||||
table.Cell().ColumnSpan(8).MinHeight(PageHeight / 7/4);
|
||||
|
||||
// 剩余内容...
|
||||
// 注意:确保剩余内容的高度不超过剩余的页面空间
|
||||
// 这里只是一个简单的例子,实际应用中你可能需要更复杂的逻辑来计算剩余可用空间
|
||||
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("编号");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].Workorder);
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("炉号");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].StoveCode);
|
||||
table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text("数量");
|
||||
table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight/7).AlignLeft().Padding(1).Text(dataList[i].PlanNum);
|
||||
for (int j = 0; j< 8; j++)
|
||||
{
|
||||
table.Cell().Border(1).MinHeight(PageHeight/7).AlignCenter().Text($"[{j+1}]");
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
document.GeneratePdf(ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
});
|
||||
document.GeneratePdf(ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
var fileName = $"工单({DateTime.Now.ToString("yyyyMMdd")}).pdf";
|
||||
return new(fileName, ms);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<PackageReference Include="AspectCore.Abstractions" Version="2.4.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="QuestPDF" Version="2025.1.0-alpha0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||
<PackageReference Include="JinianNet.JNTemplate" Version="2.4.2" />
|
||||
@@ -23,7 +23,6 @@
|
||||
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
||||
<PackageReference Include="IP2Region.Net" Version="2.0.2" />
|
||||
<PackageReference Include="ZXing.Net" Version="0.16.9" />
|
||||
<PackageReference Include="ZXing.Net.Bindings.ZKWeb.System.Drawing" Version="0.16.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.DrawingCore;
|
||||
using System.DrawingCore.Imaging;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZXing;
|
||||
using ZXing.Common;
|
||||
|
||||
using ZXing.QrCode;
|
||||
//using ZXing.ZKWeb.System.Drawing;
|
||||
|
||||
|
||||
namespace DOAN.Infrastructure.Helper;
|
||||
@@ -19,37 +19,38 @@ public class PrintHelper
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] CreateBarCode(string message, int width, int height)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var w = new ZXing.OneD.Code128Writer();
|
||||
BitMatrix b = w.encode(message, BarcodeFormat.CODE_128, width, height);
|
||||
var zzb = new ZXing.ZKWeb.BarcodeWriter();
|
||||
zzb.Options = new EncodingOptions()
|
||||
{
|
||||
Margin = 0,
|
||||
PureBarcode = false
|
||||
};
|
||||
//public static byte[] CreateBarCode(string message, int width, int height)
|
||||
//{
|
||||
// if (string.IsNullOrWhiteSpace(message))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var w = new ZXing.OneD.Code128Writer();
|
||||
// BitMatrix b = w.encode(message, BarcodeFormat.CODE_128, width, height);
|
||||
// var zzb = new ZXing.ZKWeb.BarcodeWriter();
|
||||
// zzb.Options = new EncodingOptions()
|
||||
// {
|
||||
// Margin = 0,
|
||||
// PureBarcode = false
|
||||
// };
|
||||
|
||||
Bitmap b2 = zzb.Write(b);
|
||||
// Bitmap b2 = zzb.Write(b);
|
||||
|
||||
|
||||
using (var ms = new System.IO.MemoryStream())
|
||||
{
|
||||
b2.Save(ms, ImageFormat.Png);
|
||||
var bytes = ms.ToArray();
|
||||
// using (var ms = new System.IO.MemoryStream())
|
||||
// {
|
||||
// b2.Save(ms, ImageFormat.Png);
|
||||
// var bytes = ms.ToArray();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
// return bytes;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 打印二维码
|
||||
/// https://ironsoftware.com/csharp/barcode/blog/compare-to-other-components/zxing-net-generate-qr-code-barcode-alternatives/
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="width"></param>
|
||||
@@ -61,25 +62,40 @@ public class PrintHelper
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var w = new ZXing.OneD.Code128Writer();
|
||||
BitMatrix b = w.encode(message, BarcodeFormat.QR_CODE, width, height);
|
||||
var zzb = new ZXing.ZKWeb.BarcodeWriter();
|
||||
zzb.Options = new EncodingOptions()
|
||||
Byte[] byteArray;
|
||||
var margin = 0;
|
||||
var qrCodeWriter = new ZXing.BarcodeWriterPixelData
|
||||
{
|
||||
Margin = 0,
|
||||
PureBarcode = false
|
||||
Format = ZXing.BarcodeFormat.QR_CODE,
|
||||
Options = new QrCodeEncodingOptions
|
||||
{
|
||||
Height = height,
|
||||
Width = width,
|
||||
Margin = margin
|
||||
}
|
||||
};
|
||||
|
||||
Bitmap b2 = zzb.Write(b);
|
||||
|
||||
|
||||
using (var ms = new System.IO.MemoryStream())
|
||||
var pixelData = qrCodeWriter.Write(message);
|
||||
// creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
|
||||
using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
|
||||
{
|
||||
b2.Save(ms, ImageFormat.Png);
|
||||
var bytes = ms.ToArray();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
try
|
||||
{
|
||||
// we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
|
||||
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||
byteArray = ms.ToArray();
|
||||
}
|
||||
}
|
||||
return byteArray;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user