我可以在带有Window.open()的新标签页中打开生成的jasper pdf报告:
Window.open("report.pdf?traceCode=" + traceCode, "_BLANK", "");
如果我想通过点击按钮打印pdf文件,我该怎么办? (Window.print()将打印整个页面)
答案 0 :(得分:4)
您可以创建自己的类,然后单击应用程序中的“打印”按钮,使用本机打印方法可以调用Window.Print()。
GWT UIObject可以用于此目的,方法和它将被转换为字符串。
public class NTPrint {
/**
* If true, use a Timer instead to print the internal frame
*/
public static boolean USE_TIMER = true;
/**
* Time in seconds to wait before printing the internal frame when using Timer
*/
public static int TIMER_DELAY = 1;
public static native void it() /*-{
$wnd.print();
}-*/;
public static void it(String html) {
try{
buildFrame(html);
if (USE_TIMER) {
Timer timer = new Timer() {
public void run() {
printFrame();
}
};
timer.schedule(TIMER_DELAY * 1000);
} else {
printFrame();
}
}
catch (Throwable exc) {
CommonUtil.printStackTrace(exc);
Window.alert(exc.getMessage());
}
}
/**
* This method will be called when you pass Widget without style.
* @param uiObjects
*/
public static void it( UIObject...uiObjects) {
StringBuffer objString= new StringBuffer();
for(UIObject obj: uiObjects)
objString.append(obj.toString());
it("", objString.toString());
}
}
点击“打印”按钮,
/**
* prints all forms
* @param documentInfo
*/
public static void printForms(List<FormTransaction> formTransactions, String documentInfo, List<CellTransaction> cellTransactionList, boolean isComment, Document document) {
String style = "<link rel='styleSheet' type='text/css' href='v4workflow/css/style.css'>"
+ "<link rel='styleSheet' type='text/css' href='v4workflow/css/gwtcontrols.css'>"
+ "<style type='text/css' media='print'>"
+ "@media print {"
+ ".footerText{font-size:13px; font-weight:normal;margin-top:0px;}"
+ ".break {page-break-after:always}"
+ "}" + "</style>";
List<UIObject> uiObjects = new ArrayList<UIObject>();
NTPrintLayout printLayout = new NTPrintLayout();
printLayout.setSelectedDocument(null);
uiObjects.add(createHeader());
NTPrint.it(style,uiObjects);
}
public static FlexTable createHeader(){
FlexTable flexTable = new FlexTable();
flexTable.setWidth("100%");
return flexTable;
}
答案 1 :(得分:0)