iReport - How to change report direction to RTL?

空扰寡人 提交于 2019-12-13 05:16:20

问题


How can I change the page direction to RTL in iReport, as am working on a report that should be displayed in english & arabic, I am using local for the text to appear in both languages but I can't find anything to change the direction

I know this question was asked before but I didn't find any answer: How to make a report page direction to change to "rtl"?


回答1:


As far as I searched there is no property, you can use below util class:

package foo.bar.utils.export;

import java.util.Iterator;
import java.util.List;

import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.JRPrintFrame;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JasperPrint;

/**
 * Report utilities
 * Please refer to: http://community.jaspersoft.com/questions/523041/right-left-arabic-reports
 * There is another solution at: http://jaspermirror.sourceforge.net/
 * which is not used here
 * @author AFattahi
 *
 */
public class ReportUtils {

    private ReportUtils(){

    }
    /**
     * mirror each page layout
     * @param print
     */
    public static void mirrorLayout(JasperPrint print) {
        int pageWidth = print.getPageWidth();
        for (Object element : print.getPages()) {
            JRPrintPage page = (JRPrintPage) element;
            mirrorLayout(page.getElements(), pageWidth);
        }
    }

    /**
     * mirror a list of elements
     * @param print
     */
    protected static void mirrorLayout(List<?> elements, int totalWidth) {
        for (Iterator<?> it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = (JRPrintElement) it.next();
            int mirrorX = totalWidth - element.getX() - element.getWidth();
            element.setX(mirrorX);

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                mirrorLayout(frame.getElements(), frame.getWidth());
            }
        }
    }
}


来源:https://stackoverflow.com/questions/23324264/ireport-how-to-change-report-direction-to-rtl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!