StimVinsh / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

how can xdocreport supply the Chinese character. #81

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

i retrieved my older project, i find iText can't supply Chinese words, but if u 
add iTextAsian.jar ,it will be ok.

Pls download the accessories . 

 in the project of accessories, run ReportConfigUtil.java main(), code like this:
public static void main(String[] args){
        //ReportConfigUtil.getReportConfig("/com/dbet/cfg/myreport.xml").test();
        ReportData rd = new ReportData();
        rd.addParam("nowDate",new Date().toLocaleString())
          .addParam("person", "郭州伟")
          .addParam("first","2000年01月01日")
          .addParam("last","2008年12月31日");
        ReportConfig cfg = ReportConfigUtil.getReportConfig("/com/dbet/cfg/myreport.xml");
        ReportFactoryUtil.writePdf("c:/demo.pdf",cfg,rd);
    }

it'll create c:/demo.pdf with Chinese charaters. 

so i think if xdocreport add iTextAsian.jar, it also can supply Chinese 
chararter.

Original issue reported on code.google.com by guozwh...@gmail.com on 26 Feb 2012 at 10:14

GoogleCodeExporter commented 8 years ago
Hi,

Many thanks for your zip and explanation. Today I have not time to study it.

@Leszek : do you think it's possible for you to study Chinese character with 
our ODT converter? I could modify our Docx converter like ODT converterif you 
have time to fix this problem.

If it's possible for Leszek, I think Guo, you should attach an ODT and Docx 
with Chinese character.

Many thanks

Regards Angelo

Original comment by angelo.z...@gmail.com on 26 Feb 2012 at 10:44

GoogleCodeExporter commented 8 years ago
Actually I have no much time to investigate the issue.

Guo - first try to set font encoding. See wiki
http://code.google.com/p/xdocreport/wiki/ODFDOMConverterPDFViaIText
http://code.google.com/p/xdocreport/wiki/ODTReportingJavaMainConverter
how to do this. Maybe this will work??

Also I think that you don't need iTextAsian.jar. Xdocreport converter scans 
directories like 'c:/windows/fonts' and should be able to find operating system 
fonts.

Regards
Leszek

Original comment by abe...@gmail.com on 1 Mar 2012 at 8:13

GoogleCodeExporter commented 8 years ago
Hi,

Leszek, I have quicly tested the Chinese docx and it doesn't works. It seems 
that with iText you should use embedded character 
http://stackoverflow.com/questions/5785775/japanese-chinese-text-in-pdf-using-it
ext-java

But our converter doesn't support that (how to manage that?) But I think there 
is too problem with docx converter to retreives thewell font. For the moment no 
time to investigate to the docx converter.

I have added the chinese docx in the JUNit 
http://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.apa
che.poi.xwpf.converter/src/test/java/org/apache/poi/xwpf/converter/itext/XWPFPOI
2PDFViaiTextConverterTest.java which uses the docx 
http://xdocreport.googlecode.com/git/thirdparties-extension/org.apache.poi.xwpf.
converter/src/test/resources/org/apache/poi/xwpf/converter/TestChineseCharacters
.docx

Guo, if you wish help us to support Chinese character for docx/odt converter, 
you are welcome!

Regards Angelo

Original comment by angelo.z...@gmail.com on 2 Apr 2012 at 3:47

GoogleCodeExporter commented 8 years ago
It is possible to make font embedded by passing extra parameter to getFont 
method
Now we use:
FontFactory.getFont( familyName, encoding, size, style, color );

but there is variant with embedded parameter:
FontFactory.getFont( familyName, encoding, embedded, size, style, color );

I think the bigger problem is how to search for a font
In example in an ODT document in style-text-properties we have:

style:font-name="Times New Roman" fo:font-size="12pt" 
style:font-name-asian="Lucida Sans Unicode" style:font-size-asian="12pt" 
style:language-asian="zxx" style:country-asian="none" 
style:font-name-complex="Tahoma" style:font-size-complex="12pt"

so there is three font names. I don't know for now which to use and in what 
circumstances. If I have ODT example and Chinese fonts I could do some 
experiments.

Regards
Leszek

Original comment by abe...@gmail.com on 3 Apr 2012 at 8:01

GoogleCodeExporter commented 8 years ago
Hi Leszek,

Many thanks for your answer. I will try to see how to docx works with chinese 
characters and it's the same problem than ODT.

Guo could you attach to this issue please an ODT with Chinese characters.

Many thanks.

Regards Angelo

Original comment by angelo.z...@gmail.com on 3 Apr 2012 at 8:34

GoogleCodeExporter commented 8 years ago
A chinese people have blogged "How can XDocReport (to PDF) supply the Chinese 
character ". See  
http://acai-hsieh.blogspot.fr/2012/08/how-can-xdocreport-to-pdf-supply.html

It explains how to it has modified the docx converter to manage chine 
character. here her code : 

--------------------------------------------------------------------------------
----
// Get font
        Font font =
            XWPFFontRegistry.getRegistry().getFont( fontFamily, options.getFontEncoding(), fontSize, fontStyle,
                                                    fontColor );

        // 繁體中文
        BaseFont bfChinese = BaseFont.createFont("c:/Windows/Fonts/arialuni.ttf",                            BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font fontChinese = new Font(bfChinese, font.getSize(), font.getStyle(), font.getColor());
        if (fontFamily != null)
           fontChinese.setFamily(fontFamily);
        font = fontChinese;
--------------------------------------------------------------------------------
----

It forces the font to Arial Uni. I don't understand how docx manage font. It's 
my big problem. If anybody can explain me how docx manage font (how to choose 
arial unicode when chinese character is used?) it should be very cool to help 
me.

Many thank's

Regards Angelo

Original comment by angelo.z...@gmail.com on 28 Sep 2012 at 9:20

GoogleCodeExporter commented 8 years ago
I have added a new interface IFontProvider for ODT and DOCX PDF converter that 
you can set it in the PdfOptions to manage as you wish the Font creation. So 
with 1.0.0 you can do that:

-------------------------------------------------------------------------
PdfOptions options = PdfOptions.create();
        options.fontProvider( new IFontProvider()
        {

            public Font getFont( String familyName, String encoding, float size, int style, Color color )
            {
                try
                {
                    BaseFont bfChinese =
                        BaseFont.createFont( "c:/Windows/Fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED );
                    Font fontChinese = new Font( bfChinese, size, style, color );
                    if ( familyName != null )
                        fontChinese.setFamily( familyName );
                    return fontChinese;
                }
                catch ( Exception e )
                {
                    e.printStackTrace();
                    return null;
                }
            }
        } );
        PdfConverter.getInstance().convert( document, out, options );
-------------------------------------------------------------------------

It's not a clean solution but now I can convert the chinese character. It shoul 
dbe cool if chinese people coul dexplain us how docx manage chinese characters 
(I don't understand nothing?)

Regards Angelo

Original comment by angelo.z...@gmail.com on 5 Oct 2012 at 2:57

GoogleCodeExporter commented 8 years ago
Hi,

I have added Junit with docx and odt chinese characters for pdf converter : 

1) for odt : 
http://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.odf
toolkit.odfdom.converter.pdf/src/test/java/org/odftoolkit/odfdom/converter/pdf/P
dfConvertChineseTestCase.java

2) for docx : 
http://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.apa
che.poi.xwpf.converter.pdf/src/test/java/org/apache/poi/xwpf/converter/pdf/PdfCo
nvertChineseTestCase.java

Regards Angelo

Original comment by angelo.z...@gmail.com on 9 Oct 2012 at 9:25

GoogleCodeExporter commented 8 years ago
Hi,

My notebook environment characters is big5,please find the test result at the 
attachment.

a cai

Original comment by chief...@gmail.com on 15 Oct 2012 at 5:42

GoogleCodeExporter commented 8 years ago
Hi cai,

I'm sorry, but I don't understand your problem?

Could you explain me what is the problem.

Thank's

Regards Angelo

Original comment by angelo.z...@gmail.com on 15 Oct 2012 at 7:14

GoogleCodeExporter commented 8 years ago
Hi Angelo,

Just provide test results in order to facilitate reference.
TestChineseCharacters.docx has two pages and TestChineseCharacters.docx.pdf has 
five pages,TestChineseCharacters.docx.pdf of 2~4 pages are blank pages.

Thank's

a cai

Original comment by chief...@gmail.com on 15 Oct 2012 at 8:07

GoogleCodeExporter commented 8 years ago
Hi cai,

I have noticed this problem, but it doesn't linked to the chinese characters. I 
will study this problem.

Regards Angelo

Original comment by angelo.z...@gmail.com on 15 Oct 2012 at 8:50

GoogleCodeExporter commented 8 years ago
Hi cai,

Problem is fixed. You can test it with our live demo 
http://xdocreport-converter.opensagres.cloudbees.net/

There is just again a problem with first row of table which is start on the 
first page although it should start of the second page.

Regards Angelo

Original comment by angelo.z...@gmail.com on 18 Oct 2012 at 2:37

GoogleCodeExporter commented 8 years ago
Can reference "Test XDocReport v1.0.0". 
http://acai-hsieh.blogspot.tw/2013/02/test-xdocreport-v100.html

Original comment by chief...@gmail.com on 21 Jun 2013 at 1:23

GoogleCodeExporter commented 8 years ago
Hi cai,

Many thank's for your article. For your information, Leszek and me are 
improving (planned for 1.0.3) the pdf font in our converter and it should fix 
problem whith chinese character (no need to force the use of a font with 
"c:/Windows/Fonts/arialuni.ttf" (which works only with windows OS).

Regards Angelo

Original comment by angelo.z...@gmail.com on 21 Jun 2013 at 5:27

GoogleCodeExporter commented 8 years ago
Thank's,I received.

Original comment by chief...@gmail.com on 21 Jun 2013 at 6:22

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 7 Aug 2014 at 8:59

GoogleCodeExporter commented 8 years ago
cleanup

Original comment by pascal.leclercq on 10 Oct 2014 at 7:37