HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › General questions / FAQ › UTF – 8 char issue
- This topic has 6 replies, 2 voices, and was last updated Feb 10, 2012
13:41:20 by PD4ML.
-
AuthorPosts
-
June 30, 2011 at 13:14#26574
Hi,
if i give the html file to pd4ml which is having utf – 8 char for converting to pdf but in pdf file utf – 8 characters render like ?????
means, “期購読お申し込” is replaced with “???????”I have also declare utf-8 charset in my html file using meta tag
we have a licence version of pd4ml eventhoug we are not able to convert such html file to pdf with proper data.
Below is my code :-
public File runConverter(File inputFileName, File outputFileName) throws IOException
{
if (inputFileName != null && outputFileName != null)
{
PD4ML pd4ml = new PD4ML();
pd4ml.enableSmartTableBreaks(true);
if (inputFileName.length() > 0)
{
InputStreamReader isr = new InputStreamReader(new FileInputStream(inputFileName), “UTF-8”);
java.io.FileOutputStream fos = new java.io.FileOutputStream(outputFileName);/* START: CONFIGURATION FOR PAGE ORIENTATION */
try
{
pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
}
catch (Exception e)
{
e.printStackTrace();
}
/* END: CONFIGURATION FOR PAGE ORIENTATION *//* START: CONFIGURATION FOR PAGE ORIENTATION */
pd4ml.setPageInsets(new Insets(10, 10, 10, 10));
/* END: CONFIGURATION FOR PAGE ORIENTATION *//* START: CONFIGURATION FOR PAGE HEADER */
PD4PageMark pageMarkForHeader = new PD4PageMark();
pageMarkForHeader.setAreaHeight(10);
pageMarkForHeader.setHtmlTemplate(“Hi, this is for testing only that page is start
“);
pd4ml.setPageHeader(pageMarkForHeader);
/* END: CONFIGURATION FOR PAGE HEADER */PD4PageMark pageMarkForFooter = new PD4PageMark();
pageMarkForFooter.setAreaHeight(10);
pageMarkForFooter.setInitialPageNumber(10);
pageMarkForFooter.setHtmlTemplate(“Hi, this is for testing only that page is end
“); // ${title} for title, ${page} for page number, ${total} for total number of pages
pd4ml.setPageFooter(pageMarkForFooter);pd4ml.setHtmlWidth(780);
pd4ml.render(isr, fos);
}
}
return outputFileName;
}July 1, 2011 at 11:51#28564In order to display Asian characters you need to utilize TTF embedding feature of PD4ML Pro:
July 4, 2011 at 12:38#28565I have tried with the following text :-
Arabic نيويورك
Japanese 定期購読お申し込みフォーム
Russian Эксперт Online
Other ÆØÅ_æ–øå_ö
中文名的来源and the output is :-
Arabic نيويورك
Japanese
Russian Эксперт Online
Other ÆØÅ_æ–øå_ömeans chiness and japanese char display as blank
i have puted font.jar in web-inf lib folder and i changed my code as you suggested.
new code is :-
public File runConverter(File inputFileName, File outputFileName) throws IOException
{
if (inputFileName != null && outputFileName != null)
{
PD4ML pd4ml = new PD4ML();
pd4ml.enableSmartTableBreaks(true);
if (inputFileName.length() > 0)
{
InputStreamReader isr = new InputStreamReader(new FileInputStream(inputFileName), “UTF-8”);
java.io.FileOutputStream fos = new java.io.FileOutputStream(outputFileName);/* START: CONFIGURATION FOR PAGE ORIENTATION */
try
{
pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
}
catch (Exception e)
{
e.printStackTrace();
}
/* END: CONFIGURATION FOR PAGE ORIENTATION *//* START: CONFIGURATION FOR PAGE ORIENTATION */
pd4ml.setPageInsets(new Insets(10, 10, 10, 10));
/* END: CONFIGURATION FOR PAGE ORIENTATION *//* START: CONFIGURATION FOR PAGE HEADER */
PD4PageMark pageMarkForHeader = new PD4PageMark();pageMarkForHeader.setAreaHeight(10);
pageMarkForHeader.setHtmlTemplate(“Hi, this is for testing only that page is start
“);
pd4ml.setPageHeader(pageMarkForHeader);
/* END: CONFIGURATION FOR PAGE HEADER */PD4PageMark pageMarkForFooter = new PD4PageMark();
pageMarkForFooter.setAreaHeight(10);
pageMarkForFooter.setInitialPageNumber(10);
pageMarkForFooter.setHtmlTemplate(“Hi, this is for testing only that page is end
“); // ${title} for title, ${page} for page number, ${total} for total number of pages
pd4ml.setPageFooter(pageMarkForFooter);URL base = new URL( “file:C:/tempJava/” );
pd4ml.setHtmlWidth(780);
pd4ml.useTTF( “java:fonts”, true );
pd4ml.setDefaultTTFs(“Times New Roman”, “Arial”, “Courier New”);
pd4ml.render(isr, fos, base);}
}
return outputFileName;
}July 5, 2011 at 11:13#28566As I see you packed TTF fonts into a JAR and correctly refer them:
pd4ml.useTTF( “java:fonts”, true )
It looks like your JAR has only popular fonts like Arial, Courier etc. Normally the fonts do not include Asian glyphs. In order to cover the character space please add to the JAR fonts like MS Mincho, MS Gothic, MingLiU and SimSun from any Win32 distribution (you can find them in windowsfonts).
Here are the entire font name lists, PD4ML tries to use in order to display international texts:
post1638.html?#p1638July 5, 2011 at 14:11#28567Thanks sir for your reply but please, Can you provided that fonts.jar file which support all the characters..?
February 10, 2012 at 08:16#28568Hi,
is there any update on my above comment because we want the solution urgently?February 10, 2012 at 13:41#28569Please try the following:
http://pd4ml.com/i/allfonts.zip (34 MB!)
I assume you own at least one license of MS Win, so there is going to be no font licensing issues. -
AuthorPosts
The forum ‘General questions / FAQ’ is closed to new topics and replies.