Great working on my side! I have attached a new version of the script, changes:
- handle file name with multiple dots - create the PDF - open the PDF with a tool (default evince), can be configured with a preference. - fix title layout - purge exported images at the end Maybe time to push it into the Lua repository? -- Pascal Obry / Magny Les Hameaux (78) The best way to travel is by means of imagination http://v2p.fr.eu.org http://www.obry.net gpg --keyserver keys.gnupg.net --recv-key F949BD3B
--[[ This file is part of darktable, copyright (c) 2015 Jérémy Rosen & Pascal Obry darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. darktable is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with darktable. If not, see <http://www.gnu.org/licenses/>. ]] --[[ SELECTION_TO_PDF Generates a PDF file (via Latex) containing all selected images USAGE * require this file from your main lua config file: This plugin will add a new exporter that will allow you to generate the pdf file ]] local dt = require "darktable" dt.configuration.check_version(...,{2,0,0}) dt.preferences.register ("pdf","Open with","string", "a pdf viewer", "Can be an absolute pathname or the tool may be in the PATH", "evince") local title_widget = dt.new_widget("entry") local widget = dt.new_widget("box") { orientation=horizontal, dt.new_widget("label"){label = "Title"}, title_widget } local ending = [[ \end{document} ]] local thumbs_per_line=4; local width = 1/thumbs_per_line-0.01 local filename =dt.configuration.tmp_dir.."/pdfout.tex" local function my_write(arg) local res,errmsg = latexfile:write(arg) if not res then dt.print(errmsg) error(errmsg) end end local function thumbnail(i,image,file) local title if image.title == "" then title = image.filename if image.duplicate_index > 0 then title = title.."["..image.duplicate_index.."]" end else title = image.title end -- fact is that latex will get confused if the filename has multiple dots. -- so \includegraphics{file.01.jpg} wont work. We need to output the filename -- and extention separated, e.g: \includegraphics{{file.01}.jpg} filenoext=string.gsub(file, "(.*)(%..*)", "%1") ext=string.gsub(file, "(.*)(%..*)", "%2") my_write("\\begin{minipage}[b]{"..width.."\\textwidth}\n") my_write("\\includegraphics[width=\\textwidth]{{"..filenoext.."}"..ext.."}\\newline\n") my_write("\\centering{"..i..": \\verb|"..title.."|}\n") my_write("\\end{minipage}\\quad\n") end dt.register_storage("export_pdf","Export thumbnails to pdf", nil, function(storage,image_table) local preamble = [[ \documentclass[a4paper,10pt]{article} \usepackage{graphicx} \pagestyle{empty} \parindent0pt \usepackage{geometry} \geometry{a4paper,left=5mm,right=5mm, top=5mm, bottom=5mm} \begin{document} {\Large\bfseries ]]..title_widget.text..[[} \\ \bigskip\bigskip ]] local errmsg latexfile,errmsg=io.open(filename,"w") if not latexfile then dt.print(errmsg) error(errmsg) end my_write(preamble) local i = 1 for img,file in pairs(image_table) do thumbnail(i,img,file) if i % thumbs_per_line == 0 then my_write("\n\\bigskip\n") end i = i+1 end my_write(ending) latexfile:close() -- convert to PDF dir=string.gsub(filename, "(.*/)(.*)", "%1") locfile=string.gsub(filename, "(.*/)(.*)", "%2") command = "pdflatex -halt-on-error -output-directory "..dir.." "..locfile os.execute(command) dt.print(command) -- open the PDF pdffile=string.gsub(filename, ".tex", ".pdf") command = dt.preferences.read("pdf","Open with","string") command = command.." "..pdffile os.execute(command) -- finally do some clean-up for img,file in pairs(image_table) do os.remove(file) end end,nil,nil,widget) -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
------------------------------------------------------------------------------
_______________________________________________ darktable-devel mailing list darktable-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/darktable-devel