Render PDF with ResolveFont event handler

When you try to render a PDF which uses non-system fonts, you can add your own specified fonts to make sure it is rendered correctly.

static void Main(string[] args)
{
    using (FileStream fs = new FileStream("input.pdf",FileMode.Open,FileAccess.Read))
    {
        Document d = new Document(fs);
        Page page = d.Pages[0];

        RenderSettings renderSettings = new RenderSettings();
        renderSettings.TextSettings.ResolveFont += new ResolveFontEventHandler(Resolve);

        Bitmap bmp = new Bitmap((int)page.Width * 4, (int)page.Height * 4);
        using (Graphics graphics = Graphics.FromImage(bmp))
        {
            graphics.ScaleTransform(4.0f, 4.0f);
            page.Draw(graphics, renderSettings);
        }
    }
}

// map all non-system fonts to arial
static void Resolve(TextRenderSettings sender, ResolveFontEventArgs args)
{
    if (args.FontLocation != FontLocation.System)
    {
        args.FontRenderMode = FontRenderMode.RenderAsFont;

        if (args.PdfFontName.EndsWith("Bold"))
        {
            args.Bold = true;
        }

        args.SystemFontName = "Arial";
    }
}
Download PDFRasterizer.NET 3.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.