PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 02, 2024 7:17 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Apr 30, 2010 3:21 pm 
Offline

Joined: Wed Mar 31, 2010 2:30 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 30, 2010 4:53 pm 
Offline

Joined: Fri Apr 30, 2010 4:49 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 30, 2010 6:14 pm 
Offline

Joined: Wed Mar 31, 2010 2:30 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 30, 2010 7:04 pm 
Offline

Joined: Fri Apr 30, 2010 4:49 pm
Posts: 3
try pulling from a non server, and hasn't received the latest update.

JRM


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 30, 2010 8:43 pm 
Offline

Joined: Wed Mar 31, 2010 2:30 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 07, 2010 6:27 pm 
Offline

Joined: Fri Apr 30, 2010 4:49 pm
Posts: 3
did this resolve your issue?

JRM


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group