Aspose.PDF for .NET font selection issue

I have a console application that takes an XML file and generates PDF file. I use the Aspose.PDF for .NET version 4.2.1.0. The console application is invoked from a CGI web application in order to produce PDF output.
I experience very strange issue. On my test Windows Server 2008 64bit (VMware virtual machine with 2GB RAM and 4 vCPU) the generated PDF file looks exactly as I expect, all text is printed with fonts I choose. On our production server (physical server with Windows Server 2008 64bit, 4GB RAM, 1 quad core CPU) the generated PDF output seems to use the “Times New Roman” font for all text output thus causing lineup issues.
I made sure both environments use the same code (along with the dependent DLLs) and I still get the same incorrect PDF output on the production server. I suspect some permissions issue however I was not able to find it (I used Process Monitor on the web server but it did not help).
Has anyone experienced the same issue before? If yes how did you resolve it?
Please help.

Hi,

Thanks for using our products.

Please make sure that the font that you are using in your application is installed over the Production server.

You may also consult the following Technical Article for information on Fonts embedding while creating PDF

In case you still face any problem, please share some sample code so that we can test the scenario at our end (Please don't forget to share the font file).

We apologize for your inconvenience.

Hello,

Thanks for you reply. I only use fonts included with standard Microsoft® Windows® installation (Arial, Courier New, Times new Roman). What I do not understand is why the same piece of code works differently on another server. We use only fonts supplied with the Microsoft® operating systems in order to avoid any missing font related issues.
As I mentioned in my previous post the same code works as expected on my development server which is Microsoft® Windows® Server 2008 Standard Edition 64bit same as the new production server.

Hi,

In case you are using the following code statement pdf.IsTruetypeFontMapCached = true; then please delete the file named TruetypeFontMap.xml from path specified against pdf.TruetypeFontMapPath ="" statement. This file is automatically generated when the code is again executed.

For more related information, you may check the last section of following topic Use TrueType Fonts

In case you still face any problem, please feel free to contact. We apologize for your inconvenience.

Hello,

Thank you for you reply.
I include the code used for printing text and selecting fonts. Please keep in mind the code below os part of a larger project and I am not able to include the entire project here.

Thank you.

// Summary:
// Standard Mitas font definitions
public enum MitasFonts
{
HeaderFont = 1,
SmallHeaderFont = 2,
DetailFont = 3,
TotalFont = 4,
TitleFont = 5,
TextFont = 6,
CourierLandscapeFont = 7,
CourierLandscapeTFont = 8,
CustomFont = 9,
CourierDetailFont = 10,
CourierTotalFont = 11,
PortraitHeaderFont = 12,
PortraitTitleFont = 13,
PortraitTextFont = 14,
PortraitSmallTextFont = 15,
SmallCourierFont = 16,
TimesRoman12Font = 17,
TimesRoman12BoldFont = 18,
TimesRoman12ItalicFont = 19,
TimesRoman12BoldItalicFont = 20,
TimesRoman12UnderlinedFont = 21,
TimesRoman12BoldUnderlinedFont = 22,
TimesRoman12BoldItalicUnderlinedFont = 23,
MICRE13BFont = 24,
Courier16Font = 25,
Courier20Font = 26,
Courier20BoldFont = 27,
Arial10Font = 28,
TimesRoman8Font = 29,
DetailFontArial7 = 30,
HeaderFont2 = 31,
SmallHeaderFont2 = 32,
}

public static class Miscellaneous
{
public const int COLOR_MASK_BLUE = 255;
public const int COLOR_MASK_GREEN = 65280;
public const int COLOR_MASK_RED = 16711680;
public const double MailToAddressrow = 16.5;
public const float MILIMETERS_PER_INCH = 25.5f;
public const string PdfCreator = “Aspose.PDF”;
public const string PdfProducer = “The Mitas Group, Inc.”;
public const float POINTS_PER_INCH = 72f;
public const double ReturnAddressRow = 2.5;
public const float SIGNATURE_HEIGHT_INCHES = 1f;
public const float SIGNATURE_WIDTH_INCHES = 3f;
}


///


/// Select standard Mitas font
///

///
///
private void SetFont(TextInfo currentTextInfo, MitasFonts newFont)
{
TextInfo mTextInfo = new TextInfo();
mTextInfo.IsTrueTypeFontBold = false;
mTextInfo.IsTrueTypeFontItalic = false;
mTextInfo.IsUnderline = false;
switch (newFont)
{

case MitasFonts.HeaderFont:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.HeaderFont2:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 17.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.SmallHeaderFont:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 8;
fColumnSizeInPoints = (int)((1.0 / 14.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.SmallHeaderFont2:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 8;
fColumnSizeInPoints = (int)((1.0 / 17.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.DetailFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 7;
fColumnSizeInPoints = (int)((1.0 / 17.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.DetailFontArial7:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 7;
fColumnSizeInPoints = (int)((1.0 / 17.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}

case MitasFonts.TotalFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 7;
mTextInfo.IsTrueTypeFontBold = true;
fColumnSizeInPoints = (int)((1.0 / 17.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TitleFont:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 11;
mTextInfo.IsTrueTypeFontBold = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TextFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.CourierLandscapeFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 12.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.CourierLandscapeTFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 10;
mTextInfo.IsTrueTypeFontBold = true;
fColumnSizeInPoints = (int)((1.0 / 12.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 8.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.CourierDetailFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 12;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.CourierTotalFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontBold = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.PortraitTitleFont:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 14;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.PortraitHeaderFont:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.PortraitTextFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.PortraitSmallTextFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.SmallCourierFont:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 9;
fColumnSizeInPoints = (int)((1.0 / 12.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.Courier16Font:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 8;
fColumnSizeInPoints = (int)((1.0 / 16.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.Courier20Font:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 6;
fColumnSizeInPoints = (int)((1.0 / 20.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman8Font:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 8;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}

case MitasFonts.TimesRoman12Font:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12BoldFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontBold = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12BoldItalicFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsTrueTypeFontItalic = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12ItalicFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontItalic = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12UnderlinedFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsUnderline = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12BoldUnderlinedFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsUnderline = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.TimesRoman12BoldItalicUnderlinedFont:
{
mTextInfo.FontName = “Times New Roman”;
mTextInfo.FontSize = 12;
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsTrueTypeFontItalic = true;
mTextInfo.IsUnderline = true;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.Arial10Font:
{
mTextInfo.FontName = “Arial”;
mTextInfo.FontSize = 10;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}

case MitasFonts.MICRE13BFont:
{
mTextInfo.FontName = “MICR E13B Match”;
mTextInfo.IsFontEmbedded = true;
mTextInfo.FontSize = 12;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
case MitasFonts.CustomFont:
{
switch (fCustomFontType)
{
case CustomFontFaceNames.Courier:
{
mTextInfo.FontName = “Courier New”;
break;
}
case CustomFontFaceNames.LinePrinter:
{
mTextInfo.FontName = “Courier New”;
break;
}
case CustomFontFaceNames.TimesRoman:
{
mTextInfo.FontName = “Times New Roman”;
break;
}
case CustomFontFaceNames.Universe:
{
mTextInfo.FontName = “Arial”;
break;
}
case CustomFontFaceNames.UniverseFixed:
{
mTextInfo.FontName = “Arial”;
break;
}
default:
{
mTextInfo.FontName = “Courier New”;
break;
}
}
mTextInfo.FontSize = (float)fCustomFontPointSize;
mTextInfo.IsTrueTypeFontBold = false;
mTextInfo.IsTrueTypeFontItalic = false;
mTextInfo.IsUnderline = false;
switch (fCustomFontStyle)
{
case CustomFontStyles.Bold:
{
mTextInfo.IsTrueTypeFontBold = true;
break;
}
case CustomFontStyles.Italic:
{
mTextInfo.IsTrueTypeFontItalic = true;
break;
}
case CustomFontStyles.Underlined:
{
mTextInfo.IsUnderline = true;
break;
}
case CustomFontStyles.BoldItalic:
{
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsTrueTypeFontItalic = true;
break;
}
case CustomFontStyles.BoldUnderlined:
{
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsUnderline = true;
break;
}
case CustomFontStyles.ItalicUnderlined:
{
mTextInfo.IsTrueTypeFontItalic = true;
mTextInfo.IsUnderline = true;
break;
}
case CustomFontStyles.BoldItalicUnderlined:
{
mTextInfo.IsTrueTypeFontBold = true;
mTextInfo.IsTrueTypeFontItalic = true;
mTextInfo.IsUnderline = true;
break;
}
}
fColumnSizeInPoints = (int)((1.0 / fCustomFontHMIndex) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / fCustomFontVMIndex) * Miscellaneous.POINTS_PER_INCH);
break;
}
default:
{
mTextInfo.FontName = “Courier New”;
mTextInfo.FontSize = 8;
fColumnSizeInPoints = (int)((1.0 / 10.0) * Miscellaneous.POINTS_PER_INCH);
fRowSizeInPoints = (int)((1.0 / 6.0) * Miscellaneous.POINTS_PER_INCH);
break;
}
}
fCurrentFont = newFont;

currentTextInfo.FontName = mTextInfo.FontName;
currentTextInfo.FontSize = mTextInfo.FontSize;
currentTextInfo.IsFontEmbedded = mTextInfo.IsFontEmbedded;
currentTextInfo.IsTrueTypeFontBold = mTextInfo.IsTrueTypeFontBold;
currentTextInfo.IsTrueTypeFontItalic = mTextInfo.IsTrueTypeFontItalic;
currentTextInfo.IsUnderline = mTextInfo.IsUnderline;
switch (fAlignment)
{
case Alignments.Right:
{
currentTextInfo.Alignment = Aspose.Pdf.AlignmentType.Right;
break;
}
case Alignments.Center:
{
currentTextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
break;
}
case Alignments.Justify:
{
currentTextInfo.Alignment = Aspose.Pdf.AlignmentType.Justify;
break;
}
case Alignments.FullJustify:
{
currentTextInfo.Alignment = Aspose.Pdf.AlignmentType.FullJustify;
break;
}
default:
{
currentTextInfo.Alignment = Aspose.Pdf.AlignmentType.Left;
break;
}
}
}

///
/// Print a line of text or multiple lines of text
///

/// Row to print on or null to print on current row.
/// Column to print on or null to print in current column.
/// Text to print.
/// A font from the MitasFont class.
/// Text alignment such as Left, Right, Center, or Full Justification
/// Paragraph Width in inches
/// Pass true if no printing is desired, but you need to know the number of rows the paragraph would be to control pagination.
/// Number of rows the Paragraph will cover.
public int PrintText(double? printRow, double? printColumn, Object printMessage, MitasFonts? printFont, Alignments? printAlignment, double printWidth, bool testOnly)
{
if (printMessage is DateTime)
{
return PrintDate(printRow, printColumn, printMessage, printFont, printAlignment);
}

printWidth = (float)(printWidth * 72);

fRow = (printRow == null ? fRow : (double)printRow);
fColumn = (printColumn == null ? fColumn : (double)printColumn);
fAlignment = (printAlignment == null ? fAlignment : (Alignments)printAlignment);
fPrintedMessage = Utils.StringNull(printMessage);

Text pdfText = new Text(fPrintedMessage);
pdfText.Margin.Left = 0.0F;
pdfText.Margin.Top = 0.0F;
pdfText.Margin.Right = 0.0F;
pdfText.Margin.Bottom = 0.0F;
SetFont(pdfText.TextInfo, (printFont == null ? fCurrentFont : (MitasFonts)printFont));

pdfText.Left = GetColumnPosition(fColumn);
pdfText.Top = GetRowPosition(fRow);

switch (fAlignment)
{
case Alignments.Right:
{
pdfText.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Right;
pdfText.TextWidth = (float)(printWidth > 0 ? printWidth : pdfText.Left);
pdfText.Left = 0;
break;
}
case Alignments.Center:
{
pdfText.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
pdfText.TextWidth = (float)(printWidth > 0 ? printWidth : pdfText.Left * 2);
pdfText.Left = 0;
break;
}
default:
{
pdfText.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Left;
pdfText.TextWidth = (float)(printWidth > 0 ? printWidth : 1000 * fPrintedMessage.Length);
break;
}
}

if (!testOnly)
{
FloatingBox fBox = new FloatingBox();
fBox.PositioningType = PositioningType.PageRelative;
fBox.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
fBox.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
fBox.BoxWidth = pdfText.TextWidth;
fBox.Top = pdfText.Top;
fBox.Left = pdfText.Left;
fBox.Paragraphs.Add(pdfText);
fPdfSection.Paragraphs.Add(fBox);
}

return Utils.Round((pdfText.GetTextHeight(fPdf, pdfText.TextWidth) / fRowSizeInPoints), 0).IntNull();

}

Hello,

My font issue is definitely related to permissions/security. When I login to the web server with the user account used by the website’s application pool and I run the console application from a command line the resulting PDF file contains correct fonts. If the same code is invoked from my website (CGI application, native code) the resulting PDF file contains only Times New Roman font.
The console application for creating PDF files is .NET application using .NET framework 3.5.

Could you please provide me with advise about what configuration changes should I make to my web application/server in order to get the PDF file created with correct fonts?

Hi,

Sorry for replying you late.

We are looking into the details of this problem and will update you with the status of correction, shortly.

We apologize for your inconvenience.

Hi,

The issue may be in the IIS authentication mode/impersonation or .NET trusted levels. Please check configuration files (application level, machine level) on the production server and the development machine and note any security configuration differences. Is any permission restriction on the Enterprise, Machine or User level? See also error messages related to authorization faults in event logs, IIS logs (You can use process monitor http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx to get detailed log about file system activity - note any “access denied” messages).