Hi Shashi,
Thanks for your interest in our products.
I tested the scenario with below sample source code using Aspose.Pdf for Java 3.1.0. Resultant PDF documents are attached for your reference. Kindly use the following code with latest version and check if it fits your need.
[Java]
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();
Table table = new Table(sec1);
Row row = table.getRows().add();
Cell cell = row.getCells().add("Check Font Name");
TextInfo info = new TextInfo();
info.setFontName("Times New Roman");
if(info.getFontName().equals("Times New Roman"))
{
cell.getDefaultCellTextInfo().setFontName("Times New Roman");
}
else
{
cell.getDefaultCellTextInfo().setFontName("MS Mincho");
}
cell.setDefaultCellTextInfo(info);
sec1.getParagraphs().add(table);
pdf1.save("d:\\pdffiles\\TimesNewRoman.pdf");
Please feel free to contact support in case you need any further assistance.
Thanks & Regards,
Hi Shashi,
Thanks for your feedback, as per my understanding, you want to set a specific font say "Times New Roman" or "Courier New" when inserting data in a Cell and if your data has a different font name then default "MS Machino" font should be set. Kindly correct me if I am wrong.
In the below code if you set info.setFontName("Font Name"); to any other font except "Times New Roman" or "Courier New" the default font "MS Mincho" font will be set. You can also ignore this line of code info.setFontName("Arial"); as per your requirement.
[Java]
info.setFontName("Arial");
if(info.getFontName().equals("Times New Roman"))
{
cell.getDefaultCellTextInfo().setFontName("Times New Roman");
}
else if(info.getFontName().equals("Courier New"))
{
cell.getDefaultCellTextInfo().setFontName("Courier New");
}
else
{
cell.getDefaultCellTextInfo().setFontName("MS Mincho");
}
Please feel free to contact support in case you need any further assistance.
Thanks & Regards,
shashi2587:What I want is, To set multiple font (Instaed of setting only “MS Mincho”) and achieve following- If the First font (say “Times New Roman”) is available for the string (data to be put into cell) it should use it, else the second font will be used (Say “MS Mincho”)Hello Shashi,Thanks for contacting support.Please allow me to explain what I have understood from your requirement. As per my understanding from above statements, you need to set the font for specific table cell based over the type of contents being placed inside it. Let’s say if the contents being placed inside table cell contain any ASCII character, then any font supporting such contents should be set i.e. Times New Roman. And in case the contents being placed inside table Cell contain any ASCII character, then a font which supports ASCII characters should be applied i.e. MS Mincho.shashi2587:- Related rquirement is: To use font supporting ASCII if there is no Non-ASCII character.You need to use ASCII supporting font when contents being placed inside table cell do not have any Non-ASCII character.shashi2587:Currently I am achieving it by following code.TextInfo info = new TextInfo();if (!isPureAscii(data.toString())) {info.setFontName(“MS Mincho”);}Cell cell = row.getCells().add(" " + data);cell.setDefaultCellTextInfo(info);// isPureAscii(…) methodpublic static boolean isPureAscii(String v) {return Charset.forName(“US-ASCII”).newEncoder().canEncode(v);}Is there a way to set multiple fonts for a cell or table or section or pdf ?As far as I can understand from your above code snippet, you are checking the contents being placed inside table cell that either they contain any ASCII character or not. However you need to know if Aspose.Pdf for Java supports the capability to specify multiple fonts for Table/Cell/Section and in case Times New Roman is applicable, it should be applied and in case there are ASCII characters/Unicode characters, specific font should be applied automatically. Please correct me if I have not properly understood your requirement. We are really sorry for your inconvenience.