- C# Print document | Code Sample | Tall Components PDF C# samples
- Change colors of black-and-white TIFF after converting from PDF
- Convert multiple PDF pages to bitmap
- Convert PDF to an image using a dither matrix
- Convert PDF to JPG in C#
- Convert PDF to multipage TIFF in C# .NET
- Convert PDF to PNG using WPF
- Convert PDF to XPS
- Convert PDF with layers to image
- Display PDF in a WPF app and stay responsive - the code
- Font mapping
- PDF to grayscale TIFF C#
- C# Print PDF documents from a WPF application
- Render a PDF to bitmap
- Render PDF with ResolveFont event handler
- Render PDF to EMF
- Use multiple licenses
- How to use a system font for rendering text
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";
}
}