Barcode font not displaying PDF

I've been sucessfully using Aspose.Words and Aspose.PDF for about a year to create PDF documents and it's been working great.

Now I need to add a Code 39 barcode to my documents. A font TTF file was provided to me by the third party that will be reading the barcode. On my local PC, I installed the font and it displays correctly in MS Word. However when I save my document to PDF using Aspose, instead of the barcode font, the text displays in what looks to be Adobe Sans MM font.

I read an earlier post regarding Aspose not supporting embedded fonts, but I don't think my font is embedded in my Word doc as I'm doing all this on my local PC.

Any suggestions would be most appreciated.

Thanks,
John

Hello John,

Thanks for considering Aspose.

Can you please share the resource word document and the font file that you are using, so that we can test the issue at our end.

We apologize for your inconvenience.

Font and Word doc are attached.

Hello John,

Please first install the font over your system and then try using the Direct to PDF Save method of Aspose.Words. I've tested the scenario and the resultant PDF is being generated correctly. I've used the following code snippet to convert the word file into PDF.

[C#]

Document doc = new Document(@"D:\pdftest\test+barcode.doc")
doc.Save(@"D:\pdftest\test+barcode_Direct.pdf");

The resultant PDF document is in attachment, please take a look.

For further information regarding Direct 2 PDF save method of Aspose.Words, please visit Saving Documents

Thanks for the quick response. Perhaps I simplified my example a bit too much. The part that's not displaying the barcode font is a mail merge that returns the PDF to the browser as a byte array. I'm using Doc.Save, but as a memory stream so my web service can pass a byte array back to my web page. Everything else in the mail merge works fine, it's just the barcode displays the literal text *SIC1* instead of the barcode.

Here's my .NET code

...

// merge the letter template with the data

doc.MailMerge.Execute(myDataTable);

// convert the document to a PDF so can return a byte array to the front end

MemoryStream xmlStream = new MemoryStream();

doc.Save(xmlStream, SaveFormat.AsposePdf);

//Seek to the beginning so it can be read by Aspose.Pdf.

xmlStream.Seek(0, SeekOrigin.Begin);

//Load the XML document into Aspose.Pdf

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

//Make sure the images that were saved by Aspose.Words into Windows temporary

//folder are automatically deleted by Aspose.Pdf when they are no longer needed.

pdf.IsImagesInXmlDeleteNeeded = true;

pdf.BindXML(xmlStream, null);

pdf.IsTruetypeFontMapCached = true;

pdf.TruetypeFontMapPath = ConfigurationManager.AppSettings["Aspose.TruetypeFontMapPath"];

if (pdf.TruetypeFontMapPath == null) {

pdf.TruetypeFontMapPath = System.IO.Path.GetTempPath();

}

// store the completed letter as byte array in the value property of the return object

rba.Value = pdf.GetBuffer();

return rba;

..

then later,

Response.ContentType = "Application/pdf";

Response.BinaryWrite(rba.Value);

Response.End();

I'm also not sure what you mean by "first install the font over your system"

I just dragged the .TTF file into the FONTS folder and it automatically installed. I can tell it's installed because it works in Word. Is there something else I'm missing with the installation?

Hello John,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for replying you late.

In my previous reply when I've mentioned "first install the font over your system" I meant exactly what you have specified "I just dragged the .TTF file into the FONTS folder and it automatically installed"

Regarding displaying the mail merge contents in proper format, the contents must be displayed using the proper font. So in order to embed the font information into the resultant PDF file, please try using the following code line after you have called the BindXML (...) method.

[C#]

// use this option to embed the font information in resultant file
pdf.TextInfo.IsFontEmbedded = true;

I've tried the above specified mechanism and the resultant PDF is being generated fine. In case you still face any problem, please feel free to share.

Please note that, when using this property the size of the resultant PDF might be larger, as it also contains the font file information along with PDF contents.

Thanks for your help. I'm making some progress...

I added in pdf.TextInfo.IsFontEmbedded = true; and the font displayed correctly.

However, I noticed that my document size grew from 2K to 233K with the embedded fonts. Since I'm generating thousands of documents, size is a concern.

Next I tried removing the pdf.TextInfo.IsFontEmbedded = true; line and surprisingly the font continued to display correctly in the PDF and the document was back to the smaller size.

I really can't add that line and then remove it when I deploy the .NET code to the server, so I need to get it working consistently.

I'm on version 3.6.2.5 of Aspose.PDF and 5.2.0.0 of Aspose.Words. Have any updates since addressed this type of issue? Any other ideas?

Thanks,

John

Hello John,

When using the IsFontEmbedded property the complete font file is embedded into the PDF document so the size of the resultant PDF is increased. Beside this, we have a method named SetUnicode() which only embeds the font subset being used in the document instead of including the complete font file. During my test I've noticed that the resultant PDF file generated in this case is 3.92KB and the file is also in attachment, please take a look.

In order to use this method properly, first please delete the existing "Aspose.Pdf.TruetypeFontMap.xml" from Temp folder as you have specified the location of file as System.IO.Path.GetTempPath(); after the font "Mb020.ttf" is installed the file information needs to be updated. When you would recompile the code, the file with updated information is generated. Please try using the following code line and in case you still face any problem, please feel free to contact.

[C#]

// Call this line of code to embed the font Subset information into resultant pdf file
pdf11.SetUnicode();

I would also recommend you to visit the following link for related information. Fonts embedding while creating PDF

PS, I've tested the scenario using Aspose.Pdf 4.0.0.0 and Aspose.Words 6.4.0.0.