Or lack of fonts. Hello, I'm new to PDFSharp, and I'm struggling to make even basic "Hello world" migradoc sample working.
My project runs on a docker container with Debian GNU/Linux, apparently with no fonts installed. I am forbidden to install it.
I tried to start with implementing a FontResolver (since error message says I must), but only info online I can find says "You must implement the two methods of the interface", with no mention about how. Link to the sample on codeplex does not work.
What can I do? I don't care which font, as long as something works
I added arial.ttf to project assets, and made a FontResolver like this:
Code:
public class CustomFontResolver : IFontResolver
{
public static readonly CustomFontResolver Instance = new CustomFontResolver();
public byte[] GetFont(string faceName)
{
string filePath = Path.Combine(AppContext.BaseDirectory, "src", "Admin", "Common", "Assets", "Arial", "arial.ttf");
if (faceName == "Arial")
{
return File.ReadAllBytes(filePath);
}
throw new System.NotImplementedException();
}
public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
{
if (familyName == "Arial")
{
return new FontResolverInfo("Arial");
}
return null;
}
}
Then, I try to generate PDF like this:
Code:
string testString = "Here be PDF";
GlobalFontSettings.FontResolver = CustomFontResolver.Instance;
var myFont = new XFont("Arial", 10, XFontStyleEx.Regular);
var document = new MigraDoc.DocumentObjectModel.Document();
var section = document.AddSection();
section.AddParagraph(testString);
var pdfRenderer = new MigraDoc.Rendering.PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
Running the code, I receive an error:
"System.InvalidOperationException: The font 'Courier New' cannot be resolved for predefined error font. Use another font name or fix your font resolver.
I am stumped, why does it search for Courier New? And what is Error Font..