We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Chinese charecter support only Arial unicode ms font in aspose.pdf.genrator

hi,

I am using Chinese character including html tag like this “政府关系
am not using Arial Unicode MS, please suggest me how it will take font automatically in aspose Pdf genrator.
I am also tried …

pdf1.IsTruetypeFontMapCached = true;
pdf1.TruetypeFontMapPath = @"C:\Windows\Fonts"; 
pdf1.SetUnicode();
 pdf1.TextInfo.IsUnicode = true;

 row = GetAsposeRow(tableq, 5, 5, 5, 5);
                        row.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.Bottom | (int)Aspose.Pdf.Generator.BorderSide.Top, 0.1F, new Aspose.Pdf.Generator.Color("#3399cc"));
                        Cell = GetAsposeCell(row, "White", 1, 3);
                        Cell.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.Bottom | (int)Aspose.Pdf.Generator.BorderSide.Top, 0.1F, new Aspose.Pdf.Generator.Color("#3399cc"));
                        txt = GetAsposeText(questionstext, "#blue", 8f, false, false, false);
                        
                        txt.IsHtmlTagSupported = true;
                        txt.IsHtml5Supported = true;
                            txt.IfHtmlTagSupportedOverwriteHtmlFontNames = true;                       
                        Cell.Paragraphs.Add(txt);
                        row.Cells.Add(Cell);

it support only Arial Unicode MS font in aspose Pdf genrator. I would not prefer to use font name but it will automatically take font .
please provide any solution…

@jitendra1

Thank you for contacting support.

I have observed the code shared by you and have noticed that you are using Generator approach, which is an old model and is going to be obsolete soon. The advanced and enhanced approach to work with Aspose.Pdf API is Document Object Model (DOM) approach, using which a correct output can be achieved as per your requirements.

With latest version of Aspose.Pdf, i.e Aspose.Pdf for .NET 17.11, while using DOM approach, you do not need to specify fonts. Instead, Aspose.Pdf API automatically loads all the fonts installed on a system. Please try using below code sample which adds Chinese text as well as HTML text in a table cell.

        // Load source PDF document
        Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

        //Add a page to PDF document
        doc.Pages.Add();

        // Initializes a new instance of the Table
        Aspose.Pdf.Table table = new Aspose.Pdf.Table();
        // Set the table border color as LightGray
        table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
        // Set the border for table cells
        table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
        // Create a loop to add 10 rows
        for (int row_count = 1; row_count <= 5; row_count++)
        {
            // Add row to table
            Aspose.Pdf.Row row = table.Rows.Add();
            // Add table cells
            row.Cells.Add("Column (" + row_count + ", 1)");
            row.Cells.Add("Column (" + row_count + ", 2)");
        }

        //Adding text to a table
        TextFragment text = new TextFragment("政府关系");
        text.TextState.ForegroundColor = Color.Red;

        table.Rows[1].Cells[1].Paragraphs.Clear();
        table.Rows[1].Cells[1].Paragraphs.Add(text);

        //Adding HTML text in table
        HtmlFragment title = new HtmlFragment("<fontsize=10><b><i>HTML Test</i></b></fontsize>");
        table.Rows[4].Cells[0].Paragraphs.Clear();
        table.Rows[4].Cells[0].Paragraphs.Add(title);

        // Add table object to first page of input document
        doc.Pages[1].Paragraphs.Add(table);
        dataDir = dataDir + "Table_DOM.pdf";
        
        // Save updated document containing table object
        doc.Save(dataDir);

I have attached generated output file for your kind reference Table_DOM.pdf. For further information on working with tables, you may visit this documentation article.

In case you face any issue, please share your source files and a code snippet reproducing the issue. We will be pleased to help.

Thanks, for your reply @Farhan.Raza. It has really helped me,I am looking forward to have more information from your side in future.

regards,
JITENDRA

@jitendra1

Thank you for your kind feedback.

It is good to know that your problem has been resolved by suggested approach. Please keep using our API and in event of any other query, feel free to ask.

my apologies for reviving an old thread, but I’m struggling with showing chinese characters as well.

could you try “入能加团动队” as the text in the above example and confirm that the last 3 are blank squares? I’m willing to create a new thread if that’s proper procedure.

@joshih0830

Please check the attached document which was created at our side while using above code snippet and Aspose.PDF for .NET 20.12.

Table_DOM.pdf (149.1 KB)

We did not notice any blank squares in the table.

hey @asad.ali, it says the file is private

here’s a clip of what I’m seeing. I’m using Aspose.PDF 20.12
image.png (8.5 KB)

@joshih0830

Would you please make sure to use a licensed version of the API or please apply for a free 30-days temporary license in order to evaluate the API. Furthermore, also check if all windows essential fonts are present/installed in your system. In case issue still persists, please share complete environment details where you are facing it. We will further proceed to assist you accordingly.

attached is the resultant pdf from the code snippet. I did set the license (no watermark) that we have and tried to run it again, but am still getting the 3 blank tiles.

any other ideas or solutions would be appreciated.

help.pdf (128.9 KB)

@joshih0830

Please try to install Arial Unicode MS Font in your system and run the code again. This MS Font contains maximum support for non-English language characters.

Hi @asad.ali

I have been troubleshooting issues in aspose.pdf html to pdf conversion in different languages this past week and I have ultimately determined that our issue is due to Arial Unicode MS not being installed and no longer being included on Windows machines. It seems like aspose is highly reliant on this font to find all characters within the Chinese language…

My question is, are there alternative fonts that your team would recommend using? non-proprietary fonts would be great.

Also, instead of having to manually install this unicode font on each machine where our application runs, is there a way to include this font within the application and have aspose reference the font at runtime/document generation?

Thanks

@rcha

We recommend installing all MS Core Fonts in the system while working with the Aspose.PDF. Furthermore, there are no such recommendations or specifications for non-proprietary fonts as you can use any custom font as per your choice. You can surely distribute the fonts along with your application. You would need to set the font directory for the API so that it can use and search the required fonts. You can set the font directory like below:

FolderFontSource fs = new FolderFontSource(@"path\to\my\folder");
FontRepository.Sources.Add(fs);