我可以打開生成的PDF格式碧玉報告,在新標籤頁中Window.open():打印生成的PDF與GWT
Window.open("report.pdf?traceCode=" + traceCode, "_BLANK", "");
如果我想通過點擊一個按鈕,打印的PDF文件,是我應該做的? (Window.print()將打印整個頁面)
我可以打開生成的PDF格式碧玉報告,在新標籤頁中Window.open():打印生成的PDF與GWT
Window.open("report.pdf?traceCode=" + traceCode, "_BLANK", "");
如果我想通過點擊一個按鈕,打印的PDF文件,是我應該做的? (Window.print()將打印整個頁面)
您可以通過使用本機的打印方法,你可以調用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());
}
}
打印按鈕的的OnClick,
/**
* 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;
}
不推薦,但有可能只與其他實用工具 - http://stackoverflow.com/questions/205180/ how-to-print-a-pdf-from-the-browser – SSR 2013-03-18 17:08:02