Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Jul 09, 2020 1:11 pm

Dear Support team,
Issue: New Spire.PDF Object, create a table and store as DOCX using: SaveToStream(fileStream, Spire.Pdf.FileFormat.DOCX) I face two issues:

1. Wrong Font:
The Document Font is not Arial but YTOKIT+Arial which is not recognized by Word and therefore the font display (Size and style) is wrong. Open Word, select all and change the font to Arial works.

2. Destroyed Letters
Sometimes the letters in the word document are totally destroyed.

Find attached two sample Word documents showing the issues.

Best regards
Christian

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Fri Jul 10, 2020 3:42 am

Dear Christian,

Thanks for your inquiry.
I tested your scenario with our latest Spire.PDF Pack(Hot Fix) Version:6.7.6, but didn't find the two issues you raised. Below is my testing code and attachment is my generated docx. Please have a check. If your were not using the latest version, please first download it to have a try. If the issuses still happen on your side, to help us investigate your issues further, please provide your full testing code including sample data to fill in table as well as your testing environment, such as OS info (E.g. Windows7, 64bit) and Region setting (E.g. China, Chinese). I am waiting for your feedback.
Code: Select all
//Create a Pdf document
PdfDocument doc = new PdfDocument();

//Add a new page
PdfPageBase page = doc.Pages.Add();

float y = 10;

//Title
PdfBrush brush1 = PdfBrushes.Black;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
y = y + font1.MeasureString("Country List", format1).Height;
y = y + 5;

//Data to fill in table
String[] data
    = {
        "Name;Capital;Continent;Area;Population",
        "Argentina;Buenos Aires;South America;2777815;32300003",
        "Bolivia;La Paz;South America;1098575;7300000",
        "Brazil;Brasilia;South America;8511196;150400000",
        "Canada;Ottawa;North America;9976147;26500000",
        "Chile;Santiago;South America;756943;13200000",
        "Colombia;Bagota;South America;1138907;33000000",
        "Cuba;Havana;North America;114524;10600000",
        "Ecuador;Quito;South America;455502;10600000",
        "El Salvador;San Salvador;North America;20865;5300000",
        "Guyana;Georgetown;South America;214969;800000",
        "Jamaica;Kingston;North America;11424;2500000",
        "Mexico;Mexico City;North America;1967180;88600000",
        "Nicaragua;Managua;North America;139000;3900000",
        "Paraguay;Asuncion;South America;406576;4660000",
        "Peru;Lima;South America;1285215;21600000",
        "United States of America;Washington;North America;9363130;249200000",
        "Uruguay;Montevideo;South America;176140;3002000",
        "Venezuela;Caracas;South America;912047;19700000"
    };

String[][] dataSource
    = new String[data.Length][];
for (int i = 0; i < data.Length; i++)
{
    dataSource[i] = data[i].Split(';');
}

PdfTable table = new PdfTable();
table.Style.CellPadding = 2;
table.Style.HeaderSource = PdfHeaderSource.Rows;
table.Style.HeaderRowCount = 1;
table.Style.ShowHeader = true;
table.DataSource = dataSource;
//Draw table
PdfLayoutResult result = table.Draw(page, new PointF(60, y));

//Save the document to stream
MemoryStream stream=new MemoryStream();
doc.SaveToStream(stream, FileFormat.DOCX);
File.WriteAllBytes("result.docx", stream.ToArray());

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Jul 10, 2020 6:38 am

Hi Nina,
issue seems to be related to PDFGrid. Since I use a couple of Spire Products I am forced to use Spire.Office, latest version 5.5.1
System:
Microsoft Windows Server 2016 Standard
Region Settings: Locale: Austria, Language: German


Code: Select all
//Create a Pdf document
PdfDocument doc = new PdfDocument();

//Add a new page
PdfPageBase page = doc.Pages.Add();

PdfGrid grid = new PdfGrid();
grid.Columns.Add(1);
PdfGridRow headerRow = grid.Headers.Add(1)[0];

headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
headerRow.Cells[0].Value = "Check my Font supposed to be Arial 11";
headerRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
grid.Draw(page, new PointF(0, 10));

//Save the document to stream
MemoryStream stream = new MemoryStream();
doc.SaveToStream(stream, FileFormat.DOCX);
File.WriteAllBytes("result.docx", stream.ToArray());

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Fri Jul 10, 2020 10:15 am

Hi,

Thanks for your quick reply.
I have reproduced the "YTOKIT+Arial" font issue with your code. This issue has been logged into our bug tracking system with the ticket number SPIREPDF-3407. Once it is resolved or there is any update for you, I will let you know immediately. Sorry for the inconvenience caused.
In addition, as for the "destroyed letters" issue, please also provide the sample code to help us investigate accurately. Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Jul 13, 2020 11:29 am

Hi,

Thanks for your patient waiting.
I got news from our Dev team about the "YTOKIT+Arial" font issue. Actually, the cause of the issue is the "true" parameter in "PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true)", it is used to create the "type0" font, which is a compound font whose name is prefixed with the random uppercase in order to distinguish from common fonts. Hence, this behavior is not a bug. For your case, please remove the "true" parameter like follows, this way will create a normal font without prefix. If there is any question, please feel free to write back.
Code: Select all
headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Jul 13, 2020 12:59 pm

Hi Nina,

ok, I will remove the parameter, but your documentation says that this parameter is the Unicode flag!
https://www.e-iceblue.com/api_documents/5e4e0b69721393-11731598/res/html/2da2367e-2d26-b136-d4ad-c101e2755937.htm

regards
Christian

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Tue Jul 14, 2020 1:49 am

Dear

Thanks for your feedback.
The Unicode means mapping characters to the bytecode value represented by two bytes. In fact, setting it as "true" will process it into "type0" font, this is determined by the internal mechanism of our Spire.PDF.
Besides, as for the "destroyed letters" issue, has it been resolved on your side? If not, please provide the sample code which can reproduce the issue to help us investigate accurately. Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Sep 09, 2020 5:39 am

Dear Nina,
as recommended I changed the parameter, but now all special characters are not displayed anymore (Unicode Characters like Δ) . But I need unicode support and I need valid Word fonts so what do you recommend?
regards Christian

Code: Select all
           //Create a Pdf document
            PdfDocument doc = new PdfDocument();

            //Add a new page
            PdfPageBase page = doc.Pages.Add();
           
            PdfGrid grid = new PdfGrid();
            grid.Columns.Add(1);
            PdfGridRow headerRow1 = grid.Headers.Add(1)[0];
            PdfGridRow headerRow2 = grid.Headers.Add(1)[1];

            //HEADER WITHOUT UNCICODE SUPPORT BUT VALID WORD FONT
            headerRow1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            headerRow1.Cells[0].Value = "This Δ is supposed to be a Delta sign in Arial 11";
            headerRow1.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            //HEADER WITH UNCICODE SUPPORT BUT INVALID WORD FONT AND SIZE
            headerRow2.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold),true);
            headerRow2.Cells[0].Value = "This Δ is supposed to be a Delta sign in Arial 11";
            headerRow2.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);


            grid.Draw(page, new PointF(0, 10));

            //Save the document to stream
            MemoryStream stream = new MemoryStream();
            doc.SaveToStream(stream, FileFormat.DOCX);
            File.WriteAllBytes("result.docx", stream.ToArray());

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Wed Sep 09, 2020 7:07 am

Hi,

Thanks for your feedback.
The special character "Δ" has to use the font that contains true parameter, otherwish, it will not dispaly correctly. I'm sorry there is no good way to fulfill your requirment in the two aspects. For your current situation, you could spilt the normal characters and special character and draw them with different fonts in grid cell. See the following code.
Code: Select all
//Create a Pdf document
PdfDocument doc = new PdfDocument();

//Add a new page
PdfPageBase page = doc.Pages.Add();

PdfGrid grid = new PdfGrid();
grid.Columns.Add(1);
PdfGridRow headerRow1 = grid.Headers.Add(1)[0];

//Define two fonts
PdfTrueTypeFont fontSpecial = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
PdfTrueTypeFont fontNormal = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));

PdfGridCellContentList list = new PdfGridCellContentList();

PdfGridCellContent text1 = new PdfGridCellContent();
text1.Font = fontNormal;
text1.Text = "This ";
list.List.Add(text1);

PdfGridCellContent text2 = new PdfGridCellContent();
text2.Font = fontSpecial;
text2.Text = " Δ ";
list.List.Add(text2);

PdfGridCellContent text3 = new PdfGridCellContent();
text3.Font = fontNormal;
text3.Text = " is supposed to be a Delta sign in Arial 11";
list.List.Add(text3);

headerRow1.Cells[0].Value = list;
headerRow1.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

//Draw the grid on page
grid.Draw(page, new PointF(0, 10));

//Save the document to stream
MemoryStream stream = new MemoryStream();
doc.SaveToStream(stream, FileFormat.DOCX);
File.WriteAllBytes("result.docx", stream.ToArray());

Sincerely,
Nina
E-iceblue support team
Last edited by Nina.Tang on Thu Sep 10, 2020 7:10 am, edited 1 time in total.
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Sep 09, 2020 7:34 am

Hi Nina,
thanks for your quick response but I dont understand "your requirment...". This is just a bug. Using the parameter kills word exports and without the parameter Unicode characters are invalid.
Scanning and splitting all texts for unicode letters is not a usefull approach.

Please find a way to solve this bug.
regards Christian

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Wed Sep 09, 2020 9:09 am

Dear ,

Thanks for your quick reply.
As I explained before, the "true" parameter is to create the "type0" font, which is a compound font whose name is prefixed with the random uppercase in order to distinguish from common fonts. This is decided by the internal mechanism of our Spire.PDF. It is not a bug.
In addition, I still posted your need to our Dev team, they will investigate if there is any other way to get font name without prefix after converting to Word. If there is any update, I will inform you.

Sinecrely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu Sep 10, 2020 9:33 am

Hi Nina,
I am glad that you are working on a solution.
On the other hand, I would be interested in how the prefix in the font name should help in Word anyway. As soon as a font is used that does not exist (for example "XX-Arial") a fallback Times new Roman look a like font is automatically used and is therefore completely worthless.
Fallback.png

regards
Christian

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Thu Sep 10, 2020 10:21 am

Hi,

Thanks for your inquiry.
During conversion, our Spire.PDF will process fonts internally to ensure the fonts can be mapped. That is to say, when converting to Word, the font name with prefix is mapped to the correct font file. In your case, you forced to change the font prefix so that the font mapping was broken, which led to the unmatched font. Hope you can understand.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu Sep 10, 2020 11:52 am

Hi,
ok - I see. So I hope you find a way how to use unicode characters in PDF and store to WORD conversion.

Thanks for your support
Christian

PrintPro
 
Posts: 55
Joined: Tue Apr 16, 2019 6:17 pm

Fri Sep 11, 2020 3:05 am

Dear Christian,

Thanks for your feedback.
Sure, I will infom you once there is any good news.
Have a nice day!

Sinecrely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF