PDFsharp(网络应用程序 Blazor)

问题描述 投票:0回答:1

正如我所写,我正在尝试使用 PDFsharp 在我的网络应用程序中创建一个按钮来创建和下载 PDF。我设法放入图像,但我无法写任何东西,我的字体有问题......

这是我的代码:

        @using System.Data
        @inject DataManager DM
        @using System;
        @using System.Diagnostics;
        @using System.IO;
        @using PdfSharp;
        @using PdfSharp.Drawing;
        @using PdfSharp.Pdf;
        @using PdfSharp.Pdf.IO;
        @using PdfSharp.Fonts;
        @using PdfSharp.Snippets.Font;
        PdfDocument document = new PdfDocument();
        document.Info.Title = "Created with PDFsharp";
        PdfPage page = document.AddPage();
        var gfx = XGraphics.FromPdfPage(page);
        
        XFont fontIntestazione = new XFont("Verdana", 10, XFontStyle.Regular);
        gfx.DrawString("Indagine", fontIntestazione, XBrushes.Black, 20, 93);

        const string filename = "Report.pdf";
        document.Save(filename);

但是我收到了 X.fontstyle 不包含常规字体的错误(我也尝试从不同的在线示例复制其他字体,但它们效果不佳。

c# pdfsharp
1个回答
0
投票

阅读过重大变更的人都知道,

XFontStyle
已重命名为
XFontStyleEx

使用新版本的库时,最好使用新版本库的示例代码。

另请参阅:
https://docs.pdfsharp.net/General/Overview/README.html

© www.soinside.com 2019 - 2024. All rights reserved.