As I wrote, I’m trying to use PDFsharp to create a button in my webapp to create and download a PDF. I managed to put images in, but I’m not able to write anything, I’m having problems with the font…

This is my code:

@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";

But I’m receiving the error that X.fontstyle doesn’t contain regular (I have also tried to copy other fonts from different online examples, but they didn’t work as well.

Those who read about the Breaking Changes know that XFontStyle was renamed to XFontStyleEx.

When using a new version of a library, it is good practise to use sample code for the new version of the library.

See also: