FlyingSaucer LTR/RTL/BiDi issue with arabic text

后端 未结 2 1493
轻奢々
轻奢々 2021-02-15 17:27

I\'m using flying saucer xhtmlrenderer for building pdf documents. Everything worked fine until now - now we should generate arabic text inside pdf. Xhtmlrenderer is rendering A

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-15 17:50

    Same issue I was facing, only solution i can find out was using arial fonts import/add arial.ttf and arialbold.ttf files in resources folder of your project.

                OutputStream outputStream = response.getOutputStream();
            ITextRenderer renderer = new ITextRenderer();
            // renderer.getFontResolver().addFont("/fonts/arialbold.ttf",
            // BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
            renderer.getFontResolver().addFont("/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            renderer.getFontResolver().addFont("/fonts/arialbold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    
            // SharedContext sharedContext = renderer.getSharedContext();
            // sharedContext.setPrint(true);
            // sharedContext.setInteractive(false);
            // sharedContext.setReplacedElementFactory(new B64ImgReplacedElementFactory());
            // sharedContext.getTextRenderer().setSmoothingThreshold(0);
    
            renderer.setDocumentFromString(content);
            renderer.layout();
            renderer.createPDF(outputStream);
            renderer.finishPDF();
            outputStream.close();
    

    in your css use

    html, body {
     margin: 0;
     padding: 0;
     font-family: Arial, Arial Bold;
     font-size: 10px;
     line-height: 14px;
    }
    

提交回复
热议问题