package x.util.print;
import dori.jasper.engine.*;
import dori.jasper.engine.base.*;
import dori.jasper.engine.design.*;
import dori.jasper.engine.export.*;
import dori.jasper.engine.util.*;
import dori.jasper.view.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.io.*;
public class PrintTest
{
public static void main(String[] args)
{
File barcode = new File("artikel_barcodelabels.xml"); //xml-report
print(barcode);
}
private static boolean saveReportAsJasperFile(JasperReport pReport, String pDestFile)
{
boolean myBool = false;
try
{
if (pReport != null)
{
JRSaver.saveObject(pReport, pDestFile);
File myFile = new File(pDestFile);
if (myFile.exists())
{
myBool = true;
}
}
}
catch (Exception ex)
{
}
return myBool;
}
public static void print(File file)
{
try
{
String strJasperFileName = file.getAbsolutePath().toLowerCase().replaceAll(".xml", ".jasper"); // JasperFileName als String
JasperReport jasperReport = JasperCompileManager.compileReport(file.getAbsolutePath()); // report compilen
if (saveReportAsJasperFile(jasperReport, strJasperFileName))
{
JasperReport jr = (JasperReport) JRLoader.loadObject((file.getName().replaceAll(".xml", "")) + ".jasper");
BarcodeBean bb = new BarcodeBean();
bb.setTitle("artikel 1");
bb.setImagepath("c:\\barcode.gif");
JasperPrint jasperPrint = JasperFillManager.fillReport(jr, null, new BarcodeDataSource(bb)); //report mit bean füllen...
JasperPrintManager.printReportToPdfFile(jasperPrint, "c:\\barcode.pdf"); //pdf erstellen
JasperPrintManager.printReport(jasperPrint, false); //ausdruck ohne drucker-dialog
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}