public class ReportUtils { public static void mirrorLayout(JasperPrint print) { int pageWidth = print.getPageWidth(); for (Iterator it = print.getPages().iterator(); it.hasNext();) { JRPrintPage page = (JRPrintPage) it.next(); mirrorLayout(page.getElements(), pageWidth); } }
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);
2. Call this method from your present Class, like follows
try { Connection con = JavaConnection.GetCon(); JasperDesign jd = JRXmlLoader.load("report1.jrxml"); // your report path and name JasperReport jr = JasperCompileManager.compileReport(jd); JasperPrint jp = JasperFillManager.fillReport(jr, null, con); ReportUtils.mirrorLayout(print); //for Arabic print right to left mirror JasperPrintManager.printReport(jp,false);// it will send print directly to printer } catch (JRException e) { JOptionPane.showMessageDialog(null, e); }
Right to left arabic Reports
in Products
Posted
1.Create a Class as follows:-
public class ReportUtils
{
public static void mirrorLayout(JasperPrint print)
{
int pageWidth = print.getPageWidth();
for (Iterator it = print.getPages().iterator(); it.hasNext();)
{
JRPrintPage page = (JRPrintPage) it.next();
mirrorLayout(page.getElements(), pageWidth);
}
}
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());
}
}
}
}
2. Call this method from your present Class, like follows
try {
Connection con = JavaConnection.GetCon();
JasperDesign jd = JRXmlLoader.load("report1.jrxml"); // your report path and name
JasperReport jr = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport(jr, null, con);
ReportUtils.mirrorLayout(print); //for Arabic print right to left mirror
JasperPrintManager.printReport(jp,false);// it will send print directly to printer
} catch (JRException e) {
JOptionPane.showMessageDialog(null, e);
}