When I try to generate pdf which contains rare chinese characters,the chars displayed incorrectly which means some parts are beyond cell boundaries.The font has been installed correctly on system.And these rare chars can be displayed correctly in iText7.The main difference between normal char and rare char is that one rare chinese character may contains two unicode while a normal char only contains one.
Here is the resouces to recur the problem.
Code:
import com.aspose.pdf.Cell;
import com.aspose.pdf.Document;
import com.aspose.pdf.Font;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.HorizontalAlignment;
import com.aspose.pdf.MarginInfo;
import com.aspose.pdf.Page;
import com.aspose.pdf.Paragraphs;
import com.aspose.pdf.Row;
import com.aspose.pdf.Table;
import com.aspose.pdf.TextDefaults;
import com.aspose.pdf.TextFragment;
import org.junit.Test;
public class FallbackFontTest {
@Test
public void testFallback() {
// Added document
Document doc = new Document();
Table table = new Table();
table.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 1.0f));
table.setColumnWidths("66.6");
MarginInfo margin = new MarginInfo();
margin.setLeft(2.0f);
table.setDefaultCellPadding(margin);
// Added page.
Page curPage = doc.getPages().add();
Row row = table.getRows().add();
row.setFixedRowHeight(216.0);
// set font strategy
TextDefaults.setDefaultFontStrategy(TextDefaults.DefaultFontStrategy.ListOfFonts);
Font font1 = FontRepository.findFont("JinbiaoSong");
Font font3 = FontRepository.findFont("JinbiaoSongExt");
TextDefaults.getDefaultFonts().add(font1);
TextDefaults.getDefaultFonts().add(font3);
createCell1(row);
Paragraphs paragraphs = curPage.getParagraphs();
paragraphs.add(table);
// save Pdf document
doc.save("outFile4.pdf");
String notifications = curPage.getNotifications();
System.out.println(notifications);
}
private static void createCell1(Row row) {
Cell cell1 = row.getCells().add();
// A paragraph of text containing both normal and rare characters
TextFragment text = new TextFragment("这里是正常字1㐀2䶮3\uE8634鿎5\uD840\uDD646\uD86C\uDDED7\uD86D\uDFA98\uD871\uDF2C0\uE43B9\uD87A\uDDF50\uE43B1\uE3FE2\uD870\uDF863\uD883\uDFAB1㐀2鿎3\uD840\uDD644\uD86C\uDDED5\uD86D\uDFA96\uD871\uDF2C7\uD870\uDF868\uD852\uDE4A");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
cell1.setAlignment(HorizontalAlignment.Center);
}
}
font files:
JinbiaoSong.zip (9.6 MB)
Another font file is prohibited from uploading because it has 18M after zip. I can send email if necessary.
pdf file:
outFile4.pdf (502.4 KB)
screenshort:
CorrectResult.png (22.5 KB)
@bigdamage
You can please upload the other font file to some public file hosting service and share the link with us. Also, please try using 23.8 version with a valid or 30-days free temporary license before sharing the font file. In case issue still persists, please let us know and we will further proceed accordingly.
Thanks for your reply.
I tried 23.8 version and it still has the same problem.Here is the result.
outFile4.pdf (600.7 KB)
And here is the second font file:
https://fine-build.oss-cn-shanghai.aliyuncs.com/test/JinbiaoSongExt.ttf
@bigdamage
When we opened the generated PDF file in Adobe Reader, we noticed that all characters were rendered correctly except, they were not aligned properly. image.png (30.7 KB)
The alignment of the characters/words are off in the PDF generated using Aspose.PDF as compared to one that you generated using iText. Can you please confirm if our understandings are correct?
Yes,your understandings are correct.
In addition, when I try to add more rare chars in other cell,aspose throws exception:
com.aspose.pdf.internal.ms.System.l7k: Format of font "Helvetica" is not supported for new composite fonts
Here is the demo:
import com.aspose.pdf.Cell;
import com.aspose.pdf.Document;
import com.aspose.pdf.Font;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.HorizontalAlignment;
import com.aspose.pdf.MarginInfo;
import com.aspose.pdf.Page;
import com.aspose.pdf.Paragraphs;
import com.aspose.pdf.Row;
import com.aspose.pdf.Table;
import com.aspose.pdf.TextDefaults;
import com.aspose.pdf.TextFragment;
import org.junit.Test;
public class RareCharTest {
@Test
public void testWordBreak() {
// Added document
Document doc = new Document();
Table table = new Table();
table.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 1.0f));
// table.setColumnWidths("66.6 69.75 82.799995 63.75 57.75 68.25");
table.setColumnWidths("66.6 69.75 82.799995");
MarginInfo margin = new MarginInfo();
margin.setLeft(2.0f);
table.setDefaultCellPadding(margin);
// Added page.
Page curPage = doc.getPages().add();
Row row = table.getRows().add();
row.setFixedRowHeight(216.0);
TextDefaults.setDefaultFontStrategy(TextDefaults.DefaultFontStrategy.ListOfFonts);
Font font1 = FontRepository.findFont("JinbiaoSong");
Font font3 = FontRepository.findFont("JinbiaoSongExt");
TextDefaults.getDefaultFonts().add(font1);
TextDefaults.getDefaultFonts().add(font3);
createCell1(row);
createCell2(row);
createCell3(row); // throws exception
// createCell4(row);
// createCell5(row);
// createCell6(row);
Paragraphs paragraphs = curPage.getParagraphs();
paragraphs.add(table);
// save Pdf document
doc.save("RareCharTest.pdf");
String notifications = curPage.getNotifications();
System.out.println(notifications);
}
private static void createCell1(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("这里是正常字1㐀2䶮3\uE8634鿎5\uD840\uDD646\uD86C\uDDED7\uD86D\uDFA98\uD871\uDF2C0\uE43B9\uD87A\uDDF50\uE43B1\uE3FE2\uD870\uDF863\uD883\uDFAB1㐀2鿎3\uD840\uDD644\uD86C\uDDED5\uD86D\uDFA96\uD871\uDF2C7\uD870\uDF868\uD852\uDE4A");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
private static void createCell2(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("测试字体正常显示有限责任公司测试字体遮挡效果图图土土");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
private static void createCell3(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("1㔠㔡㔢㔣㔤㔥㔦㔧㔨㔩㔪㔫㔬㔭㔮㔯2\uD840\uDD00\uD840\uDD01\uD840\uDD02\uD840\uDD03\uD840\uDD04\uD840\uDD05\uD840\uDD06\uD840\uDD07\uD840\uDD08\uD840\uDD09\uD840\uDD0A\uD840\uDD0B\uD840\uDD0C\uD840\uDD0D\uD840\uDD0E\uD840\uDD0F3\uD86A\uDCB0\uD86A\uDCB1\uD86A\uDCB2\uD86A\uDCB3\uD86A\uDCB4\uD86A\uDCB5\uD86A\uDCB6\uD86A\uDCB7\uD86A\uDCB8\uD86A\uDCB9\uD86A\uDCBA\uD86A\uDCBB\uD86A\uDCBC\uD86A\uDCBD\uD86A\uDCBE\uD86A\uDCBF4\uD86E\uDC00\uD86E\uDC01\uD86E\uDC02\uD86E\uDC03\uD86E\uDC04\uD86E\uDC05\uD86E\uDC06\uD86E\uDC07\uD86E\uDC08\uD86E\uDC09\uD86E\uDC0A\uD86E\uDC0B\uD86E\uDC0C\uD86E\uDC0D\uD86E\uDC0E\uD86E\uDC0F5\uD86E\uDD10\uD86E\uDD11\uD86E\uDD12\uD86E\uDD13\uD86E\uDD14\uD86E\uDD15\uD86E\uDD16\uD86E\uDD17\uD86E\uDD18\uD86E\uDD19\uD86E\uDD1A\uD86E\uDD1B\uD86E\uDD1C\uD86E\uDD1D\uD86E\uDD1E\uD86E\uDD1F6\uD873\uDF20\uD873\uDF21\uD873\uDF22\uD873\uDF23\uD873\uDF24\uD873\uDF25\uD873\uDF26\uD873\uDF27\uD873\uDF28\uD873\uDF29\uD873\uDF2A\uD873\uDF2B\uD873\uDF2C\uD873\uDF2D\uD873\uDF2E\uD873\uDF2F");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
private static void createCell4(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("A㐀㐁㐂㐃㐄㐅㐆㐇㐈㐉㐊㐋㐌㐍㐎㐏㐐㐑㐒㐓㐔㐕㐖㐗㐘㐙㐚㐛㐜㐝B\uD840\uDC00\uD840\uDC01\uD840\uDC02\uD840\uDC03\uD840\uDC04\uD840\uDC05\uD840\uDC06\uD840\uDC07\uD840\uDC08\uD840\uDC09\uD840\uDC0A\uD840\uDC0B\uD840\uDC0C\uD840\uDC0D\uD840\uDC0E\uD840\uDC0F\uD840\uDC10\uD840\uDC11\uD840\uDC12\uD840\uDC13\uD840\uDC14\uD840\uDC15\uD840\uDC16\uD840\uDC17\uD840\uDC18\uD840\uDC19\uD840\uDC1A\uD840\uDC1B\uD840\uDC1C\uD840\uDC1DPUA㧑\uD84A\uDC5F\uD86D\uDCE9㛃䴖\uD87A\uDDF5\uD883\uDFAB");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
private static void createCell5(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("C\uD869\uDF00\uD869\uDF01\uD869\uDF02\uD869\uDF03\uD869\uDF04\uD869\uDF05\uD869\uDF06\uD869\uDF07\uD869\uDF08\uD869\uDF09\uD869\uDF0A\uD869\uDF0B\uD869\uDF0C\uD869\uDF0D\uD869\uDF0E\uD869\uDF0F\uD869\uDF10\uD869\uDF11\uD869\uDF12\uD869\uDF13\uD869\uDF14\uD869\uDF15\uD869\uDF16\uD869\uDF17\uD869\uDF18\uD869\uDF19\uD869\uDF1A\uD869\uDF1B\uD869\uDF1C\uD869\uDF1DD\uD86D\uDF40\uD86D\uDF41\uD86D\uDF42\uD86D\uDF43\uD86D\uDF44\uD86D\uDF45\uD86D\uDF46\uD86D\uDF47\uD86D\uDF48\uD86D\uDF49\uD86D\uDF4A\uD86D\uDF4B\uD86D\uDF4C\uD86D\uDF4D\uD86D\uDF4E\uD86D\uDF4F\uD86D\uDF50\uD86D\uDF51\uD86D\uDF52\uD86D\uDF53\uD86D\uDF54\uD86D\uDF55\uD86D\uDF56\uD86D\uDF57\uD86D\uDF58\uD86D\uDF59\uD86D\uDF5A\uD86D\uDF5B\uD86D\uDF5C\uD86D\uDF5D");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
private static void createCell6(Row row) {
Cell cell1 = row.getCells().add();
TextFragment text = new TextFragment("E\uD86E\uDC20\uD86E\uDC21\uD86E\uDC22\uD86E\uDC23\uD86E\uDC24\uD86E\uDC25\uD86E\uDC26\uD86E\uDC27\uD86E\uDC28\uD86E\uDC29\uD86E\uDC2A\uD86E\uDC2B\uD86E\uDC2C\uD86E\uDC2D\uD86E\uDC2E\uD86E\uDC2F\uD86E\uDC30\uD86E\uDC31\uD86E\uDC32\uD86E\uDC33\uD86E\uDC34\uD86E\uDC35\uD86E\uDC36\uD86E\uDC37\uD86E\uDC38\uD86E\uDC39\uD86E\uDC3A\uD86E\uDC3B\uD86E\uDC3C\uD86E\uDC3DF\uD873\uDEB0\uD873\uDEB1\uD873\uDEB2\uD873\uDEB3\uD873\uDEB4\uD873\uDEB5\uD873\uDEB6\uD873\uDEB7\uD873\uDEB8\uD873\uDEB9\uD873\uDEBA\uD873\uDEBB\uD873\uDEBC\uD873\uDEBD\uD873\uDEBE\uD873\uDEBF\uD873\uDEC0\uD873\uDEC1\uD873\uDEC2\uD873\uDEC3\uD873\uDEC4\uD873\uDEC5\uD873\uDEC6\uD873\uDEC7\uD873\uDEC8\uD873\uDEC9\uD873\uDECA\uD873\uDECB\uD873\uDECC\uD873\uDECD");
text.getTextState().setFontSize(12);
cell1.getParagraphs().add(text);
// 水平
cell1.setAlignment(HorizontalAlignment.Center);
}
}
It throws exception in method createCell3
.
I cannot figure out the reason for the exception.
Here is the right result:
Cell3RightResult.png (8.6 KB)
@bigdamage
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-43114
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.