PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Font data could not retrieved.
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1163
Page 1 of 1

Author:  realGaurab [ Fri Apr 30, 2010 3:21 pm ]
Post subject:  Font data could not retrieved.

Hi.

I am opening a pdf file from filelocation and drawing header and footer using PdfSharp. The code was working fine. Since yesterday, I started getting this error in the production machine. It was running fine till the day before. It is still running fine in development and test machines.

Here's how I am adding header and footer.

Code:
PdfDocument doc = PdfSharp.Pdf.IO.PdfReader.Open(path);

XFont fontReportHeader = new XFont("Verdana", 16, XFontStyle.Bold);
XFont fontFooterAddress = new XFont("Verdana", 8, XFontStyle.Regular);

XColor myColour = XColor.FromArgb(216, 30, 5);
XPen pen = new XPen(myColour, 1);

Ximage imgLogo = XImage.FromFile(Server.MapPath(@"~/Images/Logo.png"));

foreach (PdfPage page in doc.Pages)
{
            XUnit pageWidth = page.Width;
            XUnit pageHeight = page.Height;

            XUnit headerTop = 25;
            XUnit headerBottom = 50;

            XUnit footerTop = pageHeight - 50;
            XUnit footerBottom = pageHeight - 25;
           
            XLinearGradientBrush brush = new XLinearGradientBrush(new XRect(0, 0, pageWidth, pageHeight), myColour, myColour, XLinearGradientMode.Horizontal);


            XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

            // header
            gfx.DrawLine(pen, 15, headerBottom, pageWidth, headerBottom);
            gfx.DrawString(reportName, fontReportHeader, brush, 15, 45, XStringFormat.Default); // reportName is a string variable

            // footer
            gfx.DrawLine(pen, 15, footerTop, pageWidth, footerBottom);
            gfx.DrawImage(imgLogo, 15, footerTop + imgLogo.PointHeight + 2, imgLogo.PointWidth, imgLogo.PointHeight);
            gfx.DrawString(address, fontFooterAddress, brush, 15, footerTop + imgLogo.PointHeight + 2, XStringFormat.TopLeft); // address is string variable
}

doc.Save(path);


Now, I am logging the expection and get this is what I get.

Error: System.InvalidOperationException: Internal error. Font data could not retrieved.
at PdfSharp.Fonts.OpenType.FontData.CreateGdiFontImage(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)
at PdfSharp.Drawing.XFont.get_Metrics()
at PdfSharp.Drawing.XFont.Initialize()
at GenerateReport.ibtnGeneratePdf_Click(Object sender, EventArgs e)


The error doesn't give the line number where error occurs but it looks like it should be while creating a new instance of XFont.

Have you guys ever come across such problem? What might be the cause of it and what would be the solution to fix it?

Thanks.

Author:  jrm [ Fri Apr 30, 2010 4:53 pm ]
Post subject:  Re: Font data could not retrieved.

I noticed the same thing yesterday after I did a windows update on my server. Today I copied my font from my computer over to the server and it worked! looks like microsoft may have updated the fonts to opentype instead of truetype.

JRM

Author:  realGaurab [ Fri Apr 30, 2010 6:14 pm ]
Post subject:  Re: Font data could not retrieved.

jrm wrote:
I noticed the same thing yesterday after I did a windows update on my server. Today I copied my font from my computer over to the server and it worked! looks like microsoft may have updated the fonts to opentype instead of truetype.

JRM

The verdana fonts in the production server and development/test servers are the same. I even deleted the fonts from production and replaced them with the ones from test machine. I still get the same error.

Author:  jrm [ Fri Apr 30, 2010 7:04 pm ]
Post subject:  Re: Font data could not retrieved.

try pulling from a non server, and hasn't received the latest update.

JRM

Author:  realGaurab [ Fri Apr 30, 2010 8:43 pm ]
Post subject:  Re: Font data could not retrieved.

I checked the server and one update did get installed yeseterday early morning. It is KB980248, which is necessary for Office 2010 installer to update fonts. I asked the server admin to uninstall the update and restart it. He will only do it at night since it is monthend so I hope my problem will be resolved tomorrow.

Author:  jrm [ Fri May 07, 2010 6:27 pm ]
Post subject:  Re: Font data could not retrieved.

did this resolve your issue?

JRM

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/