异步
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user