import win.ui;
import fsys;
import fsys.dlg;
/*DSG{{*/
var winform = win.form(text="PDF浏览器";right=759;bottom=469)
winform.add(
static={cls="static";text="";left=11;top=35;right=745;bottom=455;db=1;dl=1;dr=1;dt=1;transparent=1;z=1}
btn_open={cls="button";text="打开";left=5;top=5;right=45;bottom=30;z=10};
btn_first={cls="button";text="|◀";left=50;top=5;right=80;bottom=30;z=11};
btn_prev={cls="button";text="◀";left=85;top=5;right=115;bottom=30;z=12};
btn_next={cls="button";text="▶";left=120;top=5;right=150;bottom=30;z=13};
btn_last={cls="button";text="▶|";left=155;top=5;right=185;bottom=30;z=14};
btn_zoomin={cls="button";text="➕";left=220;top=5;right=250;bottom=30;z=15};
btn_zoomout={cls="button";text="➖";left=255;top=5;right=285;bottom=30;z=16};
btn_fitpage={cls="button";text="适应页";left=290;top=5;right=340;bottom=30;z=17};
btn_fitwidth={cls="button";text="适应宽";left=345;top=5;right=395;bottom=30;z=18};
btn_actualsize={cls="button";text="100%";left=400;top=5;right=440;bottom=30;z=19};
btn_bookmark={cls="button";text="书签";left=445;top=5;right=485;bottom=30;z=20};
edit_page={cls="edit";left=500;top=6;right=540;bottom=28;edge=1;z=21};
btn_goto={cls="button";text="跳转";left=545;top=5;right=580;bottom=30;z=22};
lbl_page={cls="static";text="0/0";left=590;top=8;right=710;bottom=28;transparent=1;z=23}
);
/*}}*/
import com.lite;
var dll = com.lite(..io.fullpath("/pdfview.ocx"));
var pdfocx = dll.createEmbedEx(winform.static,"{433268D7-2CD4-43E6-AA24-2188672E7252}");
// 更新当前页码显示
var updatePageInfo = function(){
var current = pdfocx.GetCurrentPage();
var total = pdfocx.GetPageTotalCount();
winform.lbl_page.text = (current + 1) + "/" + total;
}
// 打开 PDF 文件
winform.btn_open.oncommand = function(){
var file = fsys.dlg.open("PDF文件|*.pdf||", "请选择PDF文件", , winform);
if(file){
pdfocx.OpenPDF(file, "", "");
updatePageInfo();
}
}
// 翻页
winform.btn_first.oncommand = function(){
pdfocx.ViewFirstPage();
updatePageInfo();
}
winform.btn_prev.oncommand = function(){
pdfocx.ViewPreviousPage();
updatePageInfo();
}
winform.btn_next.oncommand = function(){
pdfocx.ViewNextPage();
updatePageInfo();
}
winform.btn_last.oncommand = function(){
pdfocx.ViewLastPage();
updatePageInfo();
}
// 缩放
winform.btn_zoomin.oncommand = function(){
pdfocx.ZoomIn();
}
winform.btn_zoomout.oncommand = function(){
pdfocx.ZoomOut();
}
winform.btn_fitpage.oncommand = function(){
pdfocx.ZoomFitPage();
}
winform.btn_fitwidth.oncommand = function(){
pdfocx.ZoomFitWidth();
}
winform.btn_actualsize.oncommand = function(){
pdfocx.ZoomActualPage();
}
// 显示/隐藏书签
winform.btn_bookmark.oncommand = function(){
pdfocx.ShowHideBookmarks();
}
// 跳转到指定页码
winform.btn_goto.oncommand = function(){
var num = tonumber(winform.edit_page.text);
if(num && num >= 1){
var total = pdfocx.GetPageTotalCount();
if(num <= total){
pdfocx.ViewGotoPage(num - 1);
updatePageInfo();
}else{
winform.msgbox("页码超出范围", "提示");
}
}
}
// 关闭窗口时清理
winform.onClose = function(){
pdfocx.ClosePDF();
return true;
}
winform.show();
win.loopMessage();