Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Apr 19, 2016 2:15 pm

Hi,

I tried to generate a barcode in a word file and also in a pdf file.
In the first one, there is obviously no problem (see in the Word in attachment), but in the pdf it seems that the font is not applied.
Below is what I do:
Code: Select all
myTextRange.CharacterFormat.FontName = "Bar-Code 39"


In attachment there are the two generated files and the font that I want to apply.

If you install the font, you will see the barcode correctly in the Word contrary to what is in the pdf.

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Wed Apr 20, 2016 6:54 am

Hello,

Thanks for your feedback.
I have tried to generate a barcode with the barcode font you provided in a pdf file using the below code. And in the pdf the font "Bar-Code 39" was applied successfully.

Code: Select all
Document document = new Document();
document.LoadFromFile("sample.docx");
ToPdfParameterList parms = new ToPdfParameterList()
    {
       IsEmbeddedAllFonts=true
    };
document.SaveToFile(resultFileName, parms);


Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Thu Apr 21, 2016 8:10 am

Thanks.

The parameter IsEmbeddedAllFonts allowed me to generate the PDF properly.

But to make it work I had to add a PrivateFontPath to the Code39.ttf font...
Given though it is in the default fonts directory, I don't really understand why I had to do this...

Code: Select all
parms.PrivateFontPaths.Add(New PrivateFontPath("Bar-Code 39", IO.Path.Combine(New IO.DirectoryInfo(Environment.SystemDirectory).Parent.FullName, "Fonts\Code39.ttf")))

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Fri Apr 22, 2016 3:58 am

Hi,

Thanks for your further feedback.
We have two solutions to embed fonts into PDF so that the result pdf can display correctly in other computer without installing the related fonts.
Solution 1:
Code: Select all
Document document = new Document();
            document.LoadFromFile("sample.docx");
            ToPdfParameterList parms = new ToPdfParameterList()
            {
                IsEmbeddedAllFonts = true
            };
            document.SaveToFile("result.pdf", parms);

If you don't want to install the font on your server, you can use the below solution to embedd the font into PDF.
Solution 2:
Code: Select all
Document document = new Document();
document.LoadFromFile("sample.docx");
ToPdfParameterList parms = new ToPdfParameterList()
{
PrivateFontPaths = new List<PrivateFontPath>()

{ new PrivateFontPath("Bar-Code 39","C:\\Windows\\Fonts\\Bar-Code 39.ttf") }
};
document.SaveToFile("result.pdf", parms);

When using solution1 to do the conversion, please ensure your working computer installs the font.
When using solution2, it doesn't need your computer installs the font.

Sincerely,
Caroline
E-iceblue support team
Last edited by caroline.zhang on Fri Apr 22, 2016 8:58 am, edited 1 time in total.
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri Apr 22, 2016 8:33 am

I understand what you say, but I installed the font on the server.
I understood that to embed the font in the PDF, it must be installed.

What I don't understand is that it doesn't find it whereas it is present...

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Fri Apr 22, 2016 9:48 am

Hello,

The reason might be that it has no access to the font file when convert doc to pdf.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Return to Spire.Doc