【发布时间】:2018-07-27 03:34:59
【问题描述】:
我在我的 Web 应用程序 (ASP.NET Core 2) 中使用 PDFsharp 1.50rc2 来生成 PDF。 我已经在 PDFsharp 网站上关注了example。但生成它时遇到问题,可能与 System.Drawing 中的 FontFamily 有关。没有把握。下面是我生成 PDF 的代码。
using PdfSharp.Pdf;
using PdfSharp.Drawing;
namespace WebApp.Controllers
{
public class HomeController : Controller {
public IActionResult Index()
{
// creating the PDF
CreatePDF();
return View();
}
public void CreatePDF()
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
// PROBLEM IN HERE (new XFONT)
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
// Save the document...
const string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
}
}
错误
对“FontFamily”类型的引用声称它定义在 'System.Drawing',但可以找到
【问题讨论】:
-
没有 MCVE,没有详细信息。问题的原因可能在此处显示的 sn-p 之外。
标签: pdf asp.net-core pdf-generation pdfsharp