c# - 如何使用 Windows 窗体在 C# 中将 Listboxtext 打印为 pdf?
问题描述
我一直在开发一个应用程序,并且正在使用dapper来映射来自数据库的数据和数据访问。
我有一个球队和球员的表格。我进行了编码,以便当我单击团队名称时,它会显示该团队中的球员。我想将特定球队的球员打印到pdf 文件中。以下是我正在尝试做的代码;此外,我附上图片以便更好地理解。
我想将播放器中的播放器打印listbox
到 pdf 文件中,其中包含每个播放器的图片。
private void printButton_Click(object sender, EventArgs e)
{
if (teamsListBox.SelectedItem is TeamModel selectedTeam)
{
playersListBox.DataSource = selectedTeam.Players;
nameValue.Text = playersListBox.Name;
printDialog1.Document = printDocument1;
nameValue.Text = playersListBox.Name;
SetBindings();
string items = "";
for (int i = 0; i < selectedTeam.Players.Count; i++)
{
PlayerModel item = selectedTeam.Players[i];
items += Name.ToString() + " ";
}
MessageBox.Show(items);
myReader = new StringReader(items);
if (printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}
}
解决方案
您需要做的就是循环播放播放器名称和图像路径并将它们发送到您的 pdf 文件,这是使用PDFFlow 库创建带有播放器列表的 PDF 的简单代码
{
var imagePath = "imageFile.png";
var numType = NumerationStyle.Arabic;
DocumentBuilder.New()
.AddSection()
.AddParagraph("Cristiano Ronaldo").SetListNumbered(numType, 1).AddInlineImage(imagePath, 20, 20, ScalingMode.UserDefined).ToSection()
.AddParagraph("Lionel Messi").SetListNumbered(numType, 1).AddInlineImage(imagePath, 20, 20, ScalingMode.UserDefined).ToSection()
.AddParagraph("Ronaldinho").SetListNumbered(numType, 1).AddInlineImage(imagePath, 20, 20, ScalingMode.UserDefined).ToDocument()
.Build("Result.pdf");}
结果将是这样的:
推荐阅读
- matlab - 如何获取存储在 4D 矩阵中的矩阵的索引?
- java - 转换地图> 到地图> 使用流
- tree - 我的归纳证明中的错误在哪里?
- mongodb - 使用 zsh 在 Mac 上找不到 Mongo 命令?
- c - “在 '->' 标记之前应有 '='、','、';'、'asm' 或 '__attribute__'
- c++ - 在 Chromebook 上构建 OpenCV 时链接 stdlib.h 时出错
- python - python中的多线程真的需要同步吗?
- c# - 如何跨多维数组(linq 或简单算法)中的列运行逻辑“xnor”?
- azure-devops - DevOps:新 DevOps(VSTS)中的非交互式登录无法正常工作,出现错误“TF30063:您无权访问
- ios - Xcode 10.2.1 命令 PhaseScriptExecution 失败,退出代码为非零