iTextSharp 5 polish character

后端 未结 5 616
无人共我
无人共我 2020-12-02 00:43

I have problem with polish character using itextSharp. I want to create pdf from html. Everything works fine but polish character are missing. I use function lower:

5条回答
  •  [愿得一人]
    2020-12-02 00:55

    1) iText 5.0.6 was released today with a major overhaul to the HTML->PDF conversion code. I suggest you try the new code instead.

    2) I'm almost positive that setting the directContent like that won't affect the pdf content generated by HTMLWorker. I'm 99% sure that it'll [re]set the font before it draws any text.

    3) Try wrapping your string in tags. I seriously doubt the default font HTMLWorker picks will be up for the job.

    Nope. The default is Helvetica with WinAnsiEncoding. Definitely not suitable to anything outside typical English/German/French/Spanish.

    You should be able to use HTMLWorker.setStyleSheet to set some friendlier defaults. You'll want to set the "face" and "encoding" to something more Polish-Friendly. I recommend "Identity-H" for the encoding, which gives access to all characters in the font you go with, regardless of language. For a font, there's a program called "charmap.exe" in windows since WayBack that will show you which characters a font has available in a given encoding (including unicode). The "Arial" family looks good, as do several others.


    "the new code" probably won't change any behavior you're seeing. It's a refactoring to make future (next release as I understand it) changes easier.

    My suggestion is to go with setStyleSheet():

       // step 3: we create a worker parse the document
       HTMLWorker worker = new HTMLWorker(document);
    
       StyleSheet sheet = new StyleSheet;
    
       HashMap styleMap = new HashMap();
       styleMap.put("face", "Arial"); // default font
       styleMap.put("encoding", "Identity-H"); // default encoding
    
       String tags[] = {"p", "div", ...};
       for (String tag : tags) {
         sheet.applyStyle( tag, styleMap );
       }
    

    I'm not sure, but you might be able to just applyStyle("body", styleMap) and have it cascade down into everything it contains, but I'm not sure. I'm also not sure that this would address your 1-line-test as there are no tags involved. IIRC, we build a body tag if there isn't one, but I'm not at all sure.

提交回复
热议问题