Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

java - 带有阿拉伯文本的FlyingSaucer LTR / RTL / BiDi问题(FlyingSaucer LTR/RTL/BiDi issue with arabic text)

I'm using flying saucer xhtmlrenderer for building pdf documents.

(我正在使用飞碟xhtmlrenderer构建pdf文档。)

Everything worked fine until now - now we should generate arabic text inside pdf.

(到目前为止,一切工作正常-现在我们应该在pdf中生成阿拉伯文本。)

Xhtmlrenderer is rendering Arabic text in reverse order.

(Xhtmlrenderer以相反的顺序呈现阿拉伯文本。)

I've read somewhere on internet (maybe on their own site) that xhtmlrenderer does not support bidi/rtl.

(我在互联网上某个地方(也许在他们自己的网站上)读到xhtmlrenderer不支持bidi / rtl。)

But IText itself contains examples to work with arabic and hebrew via ColumnText and PdfPTable (sources can be found here: http://sourceforge.net/projects/itextpdf/files/Examples/examples-155/examples-155.zip/download - arabic_hebrew.java), and those work fine.

(但是IText本身包含通过ColumnText和PdfPTable使用阿拉伯语和希伯来语的示例(可在此处找到源: http : //sourceforge.net/projects/itextpdf/files/Examples/examples-155/examples-155.zip/download- arabic_hebrew.java),并且工作正常。)

I tried to use itext api in xhtmlrenderer's ReplacedElementFactory/ITextReplacedElement, but could not find good examples for positioning elements.

(我试图在xhtmlrenderer的ReplacedElementFactory / ITextReplacedElement中使用itext api,但找不到用于定位元素的良好示例。)

Does anyone tried to do this?

(有没有人尝试这样做?)

Or maybe there is a simplier (or at least working) solution?

(或者,也许有一个更简单(或至少有效)的解决方案?)

  ask by Askar Kalykov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(我面临的同一问题,我能找到的唯一解决方案是在项目的资源文件夹中使用arial字体import / add arial.ttf和arialbold.ttf文件。)

            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

(在你的CSS使用)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...