1
votes

I am using PDFsharp to add text to a pdf. But when I use below code to add the following text with these fonts I am facing problem. After PDF was created using PDFsharp and when it is opened in adobe reader I am getting message like "Cannot find or create the font 'Windings'. Some characters may not display or print correctly." It opens

The source PDF I am trying to modify has fonts Helvetica and Windings(Embedded)

This is part of the code which adds text to PDF

Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Regular)
gfx.DrawString("Hello, World!", font, XBrushes.Black, New XRect(0, 0, page.Width, page.Height), XStringFormats.Center)
font = New XFont("WingDings", 20, XFontStyle.Regular)
gfx.DrawString("llll", font, XBrushes.Black, New XRect(25, 15, page.Width, page.Height), XStringFormats.Center)
font = New XFont("Helvetica", 20, XFontStyle.Regular)
gfx.DrawString("abcd", font, XBrushes.Black, New XRect(50, 25, page.Width, page.Height), XStringFormats.Center)

After using this code text gets added successfully but when I open in PDF Reader I am getting error (see error message above). When I see the fonts in properties of PDF I find following

Helvetica,Verdana,Windings

But Windings(Embedded) was not there which was in source pdf. Also in the created pdf the windings font which was added was showing actual font under it as Unknown(Actual font:Unknown).I think this is the error. How it can be solved? Also I want to know how to add winding-regular(embeded subset) in PDFsharp? This is Source PDF which I used. This is the PDF after created after modifying in PDFsharp which gives error.

1

1 Answers

1
votes

With PDFsharp you have to specify that fonts shall be embedded (using e.g. PdfFontEmbedding.Always, see here).

By default fonts will not be embedded - PDF files will be smaller but problems may occur when they are displayed on computers that do not have this font installed.

AFAIK PDFsharp cannot use fonts that are already embedded in the PDF.