miniMu

a mini MuPdf viewer

ABU 17-dec-2016

A very simple Pdf viewer built using tclMuPdf.

Here is a screenshot from MacOS

miniMu-sample1

package require mupdf

 # just a bare GUI - a label containing an image "imagePage"
image create photo imagePage
label .page -image imagePage -padx 5 -pady 5
pack .page -expand 1 -fill both
label .info -text "Press Up / Down keys" -relief groove
pack .info -fill x -padx 2 -pady 2

bind .page <Key-Up> {showPage $pdf [prevPage]}
bind .page <Key-Down> {showPage $pdf [nextPage]}


proc showPage {pdf n} {
        set page [$pdf getpage $n]
        imagePage blank  ;# just in case the new page is smaller than previous
        $page saveImage imagePage -zoom 0.5
}

proc nextPage {} {
        global gApp
        if { $gApp(currpage) < $gApp(lastpage) } {
                incr gApp(currpage)
        }
        return $gApp(currpage)        
}
proc prevPage {} {
        global gApp
        if { $gApp(currpage) > 0 } {
                incr gApp(currpage) -1
        }
        return $gApp(currpage)        
}

 # ---

set pdfFileName [tk_getOpenFile -filetypes {{Pdf .pdf}} \
  -message "Choose a Pdf .."]

set pdf [mupdf::open $pdfFileName]

set gApp(currpage) 0
set gApp(lastpage) [expr [$pdf npages]-1]

showPage $pdf 0
focus .page