How to set font when I convert a dwg file to pdf file?

I convert a dwg file to pdf, but the font in pdf is not what I want. How can I set the font. I have tried the following code, but does not work. And I can see the lines in the graph are too thick in the exported pdf. Can I also set the size of the line when converting dwg file to pdf file?

// Iterate over the items of CadStyleDictionary
for (CadStyleTableObject style : (Iterable)objImage.getStyles())
{
// Set the font name
style.setPrimaryFontName(“sans-serif.ttf”);
}

@Min_Shi

You need to please ensure that the fonts that have been referred in your application are actually available on your machine. You may please try using latest version on your end and if there is still an issue then please share the working sample code along with source file, generated output and used sample code with us.

Here is my code to convert the dwg to pdf:

public static void convert(String input_file, String output_file, float pageWidth, float pageHeight) throws Exception{
CadImage objImage = (CadImage) Image.load(input_file);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(pageWidth);
rasterizationOptions.setPageHeight(pageHeight);
rasterizationOptions.setExportAllLayoutContent(true);
rasterizationOptions.setLayouts(new String[] {“Model”});

// Iterate over the items of CadStyleDictionary
for (CadStyleTableObject style : (Iterable)objImage.getStyles())
{
// Set the font name
style.setPrimaryFontName(“Manjari-Thin.otf”);
}

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);

objImage.save(output_file, pdfOptions);
}

I have ubuntu 18.04, I have this font in my local PC, the font path is /usr/share/fonts/opentype/malayalam/Manjari-Thin.otf. Should I specify the path to the font some where?

@Min_Shi

Please provide the source DWG file along with generated output PDF file. Please also share the snapshot of comparison between DWG and PDF where issue is exisiting.

Nothing wrong with the dwg file and the exported pdf. My purpose is to set customized font in the exported pdf. So I would like to know the right way to do that.

@Min_Shi

In your sample code you have already set the font. How we can help you further with this.

Ok, I could upload some example. The attachment files are screenshot of the font file Manjari-Thin.otf and the exported pdf. You can see that the exported pdf has different font. So I do not think the correct font is applied. How the aspose api knows the path of the font? Could you share a full example code to set font, including setting the path of the font. I tried to add path into setPrimaryFontName, but it does not work.

Screenshot from 2020-10-05 13-30-18.png (85.3 KB)
output_font.png (5.4 KB)

@Min_Shi

Can you please try using following on your end.

FontSettings.SetFontsFolder("fonts folder");

I added this line FontSettings.SetFontsFolder(“fonts folder”), but it still does not work.

@Min_Shi

Please provide the source file, generated output file and desired output file along with used fonts. We will be able to investigate it further on our end on provision of requested information.