[ABU] 28-jan-2017 '''tclMuPdf''' is a porting of the MuPDF framework (see at http://mupdf.com%|%mupdf.com%|%), for fast and high-quality rendering of PDF pages. ***History *** * 13-dec-2016 - '''Version 1.0b1''' (beta) released. No support for MacOS * 15-dec-2016 - '''Version 1.0''' - Support for MacOS. API unchanged, but big internal optimization for reusing opened pages (read * 28-jan-2017 - '''Version 1.1''' - new commands: '''fields''', '''field''', '''anchor''', '''mupdf::libinfo''' . Added package mupdf-notk for tcl-only usage. (read the documentation). Aligned with core library MuPDF v.1.10a ***Download *** Version 1.1 is still distributed in a pre-built package with multi-platform support, but if you only need support for a single platform, you can download a lighter package. Note that a specific platform support (e.g. "Linux 32") is not referred to the hosting O.S. architecture, but it's referred to the architecture of the TclTk interpreter. E.g. if you have a 32-bit TclTk interpreter running on a 64-bit Linux, you need the tclMuPdf package for linux-x32. * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-full-1.1.zip/download] '''FULL (Win 32/64, Linux 32/64, MacOS)''' (Warning: 28 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-win-1.1.zip/download] '''(Win 32/64)''' (11 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-win32-1.1.zip/download] '''(Win 32 only)''' (6 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-win64-1.1.zip/download] '''(Win 64 only)''' (6 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-linux-1.1.zip/download] '''(Linux 32/64)''' (11 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-linux32-1.1.zip/download] '''(Linux 32 only)''' (6 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-linux64-1.1.zip/download] '''(Linux 64 only)''' (6 MB) * [https://sourceforge.net/projects/irrational-numbers/files/tclMuPdf-1.1/tclMuPdf-mac64-1.1.zip/download] '''(MacOS 64 only)''' (6 MB) * --- * [https://sourceforge.net/p/irrational-numbers/code/HEAD/tree/pkgs/tclMuPdf-devkit] tclMuPdf Development-Kit. For developers/maintainers. ***Examples*** %|code|output|% &|$page0 savePNG img0.png -zoom 0.5|[Image tclmupdf-thumb]|& &|$page2 savePNG x2.png -zoom 2.75 -from 50 450 200 700|[Image tclmupdf-particular]|& <> Reference manual ---- '''tclMuPDF 1.1''' ''Tcl meets MuPDF'' Tcl meets MuPDF **SYNOPSIS** package require '''Tcl 8.5''' package require '''mupdf ?1.1?''' * '''mupdf::open''' ''filename'' * ''pdfHandle'' '''npages''' * ''pdfHandle'' '''getpage''' ''n'' * ''pdfHandle'' '''anchor''' ''anchorName'' * ''pdfHandle'' '''openedpages''' * ''pdfHandle'' '''closeallpages''' * ''pdfHandle'' '''fields''' * ''pdfHandle'' '''field''' ''fieldname'' * ''pageHandle'' '''size''' * ''pageHandle'' '''docref''' * ''pageHandle'' '''pagenumber''' * ''pageHandle'' '''savePNG''' ''filename'' ?'''-zoom''' ''zoom''? ?'''-from''' ''x0'' ''y0'' ''x1'' ''y1''? * ''pageHandle'' '''saveImage''' ''image'' ?'''-zoom''' ''zoom''? ?'''-from''' ''x0'' ''y0'' ''x1'' ''y1''? ?'''-to''' ''x0'' ''y0''? * '''mupdf::close''' ''handle'' * '''mupdf::isobject''' ''handle'' * '''mupdf::type''' ''handle'' * '''mupdf::documents''' * '''mupdf::libinfo''' **DESCRIPTION** Package '''mupdf''' integrates the http://mupdf.com%|%MuPDF%|% framework in Tcl. The focus of http://mupdf.com%|%MuPDF%|% is on speed, small code size, and high-quality anti-aliased rendering. The main goal of this integration is to generate images of the pdf pages, in a .png format, or directly in a Tk's photo image type. Thanks to its speed '''mupdf''' can be used for building interactive pdf-viewers with high-quality and real-time zooming. '''mupdf''' is a binary package, distributed in a multi-platform bundle, i.e. it can be used on * Windows 32/64 bit * Linux 32/64 bit * MacOS 64 bit Just an example to get the flavor of how to use '''mupdf''': ====== # open a file and save 1st page as a .png file package require mupdf set pdf [mupdf::open /mydir/sample.pdf] set page [$pdf getpage 0] ;# 0 is the 1st page $page savePNG /mydir/page0.png mupdf::close $pdf ====== **MuPDF with and without Tk** Starting from version 1.1, you can also run '''mupdf''' from a tclsh interpreter, without loading '''Tk'''. The following command ====== package require mupdf-notk ====== can be used in a '''tclsh''' interpreter to load the package without requiring '''Tk''' support. You will be still able to save images as PNG files, but of course some subcommands related to Tk won't be available (e.g '''saveImage''' ) The command ====== package require mupdf ====== loads the full package (and requires '''Tk'''). **mupdf Commands** '''mupdf''' supports the following commands: '''mupdf::open''' ''filename'': This is the main command: it opens the pdf-file ''filename'' and returns a ''pdfHandle'' to be used in subsequent operations. ''pdfHandle'' '''npages''': return the number of pages. ''pdfHandle'' '''getpage''' ''n'': return a ''pageHandle'' to be used in subsequent operations. Note that first page is page 0. Note that if the requested pageis currently opened, '''getpage''' reuses the handle of the opened page. ''pdfHandle'' '''anchor''' ''anchorName'': return the location of ''anchorName'' as list of 3 numbers: * a page number ( -1 if ''anchorName'' is not found ) * x displacement * y displacement x and y are hints for displaying the page: they represent the displacement of the top-left corner of the page relative to the top-left corner of the window. ''pdfHandle'' '''openedpages''': return a list of all ''pageHandles'' currently opened related to ''pdfHandle'' ''pdfHandle'' '''closeallpages''': close all currently opened pages related to ''pdfHandle'' ''pdfHandle'' '''fields''': return a list of field-records. Each field-record is a list of three elements: * the field-name * the field-type ('''pushbutton''', '''radiobutton''', '''checkbox''', '''text''', '''combobox''', '''listbox''', '''signature''' or '''unknown''') * the field-value Note that for a '''signature''' field, if a signature is present the returned value is simply the fixed string '''<>'''. Warning: field-names with accented characters or in general with non-ASCII charaters may require a special care when used. See the section '''Notes about field-names with accented letters''' for details. ''pdfHandle'' '''field''' ''fieldname'': return the field's value, or raise an error if ''fieldname'' is not a valid field. Warning: field-names with accented characters or in general with non-ASCII charaters may require a special care when used. See the section '''Notes about field-names with accented letters''' for details. ''pageHandle'' '''size''': return the physical size of the page as a list of two decimal numbers. Note that page size is expressed in ''points'', i.e. 1/72 inch. ''pageHandle'' '''docref''': return a reference to the related pdf-document as a ''pdfHandle'' ''pageHandle'' '''pagenumber''': return the pagenumber of ''pageHandler'' ''pageHandle'' '''savePNG''' ''filename'' ?'''-zoom''' ''zoom''? ?'''-from''' ''x0'' ''y0'' ''x1'' ''y1''?: render the page in a .png file named ''filename''. With a default '''-zoom''' factor equal to '''1.0''', a page whose size is W x H ''points'' is rendered as a raster image of W x H ''pixels''. If '''-zoom''' is specified, the resulting image size is scaled by a factor of ''zoom''. By default the whole page is rendered; the '''-from''' option, allows you to render only a given rectangler area of the page. ''x0'' ''y0'' are the coords of the top-left corner and ''x1'' ''y1'' are for the bottom-right corner. These coords must be expressed in terms of the physical size of the page, i.e in ''points'' Note that if these coords lies outside of the page, only the ''intersection'' of this area with the page areais rendered. ====== ... set page [$pdf getpage 0] ;# 0 is the 1st page lassign [$page size] dx dy # save just the upper half of the page $page savePNG /mydir/page0.png -zoom 2.25 -from 0 0 $dx [expr $dy/2] mupdf::close $pdf ====== ''pageHandle'' '''saveImage''' ''image'' ?'''-zoom''' ''zoom''? ?'''-from''' ''x0'' ''y0'' ''x1'' ''y1''? ?'''-to''' ''x0'' ''y0''?: render the page in an existing Tk's photo ''image''. The width and/or height of ''image'' are unchanged if the user has set on it an explicit image width or height (with the -width and/or -height configuration options, respectively). About the '''-zoom''' and '''-from''' options, the same rules for the '''savePNG''' apply. Option '''-to''' allows you to place the resulting raster image at the ''x0'' ''y0'' coords of the destination ''image''. By default, is '''-to''' '''0.0''' '''0.0''' NOTE: this command is not available with the package '''mupdf-notk'''. '''mupdf::close''' ''handle'': if ''handle'' refers to a ''pageHandle'', close the page. if ''handle'' refers to a ''pdfHandle'', close the pdf and all its opened pages. '''mupdf::isobject''' ''handle'': return 1 if ''handle'' is a valid reference to a pdf or a page. '''mupdf::type''' ''handle'': return '''document''' or '''page''' if ''handle'' is a valid reference, else raise an error. '''mupdf::documents''' : return a list of currently opened ''pdfHandles'' '''mupdf::libinfo''' : return specific attributes of the underlying MuPdf libray as a list of keywords and their values. The provided keywords are: '''version''': The version of the underlying MuPDf library ..more to come ..: **Notes about field-names with accented letters** Field-names returned by [[''pdfHandle'' '''fields''']] are not standard (Unicode) strings; they are binary string. For 'good plain' field names like "City", there is no difference: the returned binary-string and the literal (Unicode) string "City" are byte-by-byte identical" Now let's consider a field-name like this '''"Città"''' (italian term for "City"): the returned field name, even if it is ''represented'' like "Città", is not comparable with the literal Unicode string "Città", just because the former byte-array is made of 5 bytes (plus a '\0' string-terminator), whereas the unicode string is made of 6 bytes (plus a '\0' string-terminator). This may produce strange results when comparing these values, and in paticular mode, it may cause the '''field''' subcommand to produce unexpected results. Let's try with this interactive example: ====== ... set fields [$pdf fields] # let's suppose the 0-th returned record is about the field "Città" .... # try to get the field value: set value [$pdf field Città] ;# --> error !!! # Workaround: let's take back the fieldname from the $fields list ... set fieldname [lindex $fields 0 0] ;# field name is the 0-th elem of the 0-th record puts "$fieldname" ;# --> Città set value [$pdf field $fieldname] ;# --> ... ok ====== **KEYWORDS** pdf, photo **CATEGORY** pdf parsing and rendering **COPYRIGHT** Copyright (c) 2016, by A.Buratti <> <>PDF | Graphics