c# - 在 C# 中创建 PDF 文件 - 文本不适合页面
问题描述
我有一个按钮,可以创建一个带有一些文本的 pdf,到目前为止,我有这个:
private void button_Click(object sender, EventArgs e)
{
PdfDocument pdf = new PdfDocument();
pdf.Info.Title = "My First PDF";
PdfPage pdfPage = pdf.AddPage();
XGraphics graph = XGraphics.FromPdfPage(pdfPage);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
graph.DrawString("Example long text for stack overflow to see that it doesn't fit.",
font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.Center);
string pdfFilename = "example.pdf";
pdf.Save(pdfFilename);
Process.Start(pdfFilename);
}
它工作得很好,但是我插入的字符串没有被格式化以适合页面,所以单词会被删掉。像这样的东西:https ://prnt.sc/1xdcsqi ,我希望它像普通文本一样适合页面。我试过 \n 但它对我不起作用。
提前感谢那些提供帮助的人。
解决方案
推荐阅读
- amazon-web-services - 为多个应用程序使用网络负载平衡器
- python - 两个相关模型的 Django 查询
- dart - Dart:为什么原始类型表现得像引用类型?
- angular - 更新 *ngFor Angular 上的变量
- scala - Scala:在函数接口中使用隐式
- sql - 我可以使用 RowNumber 对我的结果集进行分类吗?
- azure-cosmosdb - CosmosDB:只有一列的 DISTINCT
- python - Pandas - 嵌套的 json 文件
- python - 无法从 Amazon EC2 中的私有 pypi 服务器获取包
- javascript - 如何从 Zapier CLI 加载可自定义的输入字段