0

I am fairly new to C#, but am using it to convert some older files in a WMF/PMF format to PDF. I have the script working, but some of the fonts in the original document are not coming through. For example, some of these old documents are payroll check runs and the checks use a special MICR font (where the account/routing numbers are displayed). This MICR line comes through the conversion as what appears to be a random base font.

I am simply using iTextSharp to convert the WMF to an image, then adding the image as a page in the PDF.

I have researched embedding fonts, but my problem is that I might not know what the original font name was. These files could be any number of things, and they could be quite old. Is there a way to include a font library that would expand iTextSharp's basic fonts so they are more likely to be recognized during the conversion?

This is the function performing the conversion. All of the WMF files (one for each check) are put in a directory and the function loads them all into a single PDF:

static bool BuildPDF(string pDecodeDir)
{
    Document pdfDoc = new Document();
    DirectoryInfo decodeDir = new DirectoryInfo(pDecodeDir);
    int vCount = 0;

    foreach (var file in decodeDir.GetFiles("*.WMF"))
    {
        try
        {
            iTextSharp.text.Image img1 = ImgWMF.GetInstance(file.FullName);
            if (vCount == 0)
            {
                // in order to inherit the document size properly, we need to load the first image before creating the PDF object
                pdfDoc = new Document(img1);
                PdfWriter.GetInstance(pdfDoc, new FileStream(targetPath, FileMode.Create));
                pdfDoc.Open();
            }
            else
            {
                pdfDoc.NewPage();
            }

            Console.WriteLine("Adding page {0}: {1}", vCount.ToString(), file.Name);

            img1.SetAbsolutePosition(0, 0);
            pdfDoc.Add(img1);

            vCount++;
        }
        catch (System.Exception docerr)
        {
            Console.WriteLine("Doc Error: {0}", docerr.Message);
            return false;
        }
    }

    Console.WriteLine("{0} created!", targetPath);
    pdfDoc.Close();

    return true;
}
Adan Sandoval
  • 436
  • 1
  • 6
  • 18
e.Rock
  • 1
  • 2

0 Answers0