{"id":153,"date":"2010-02-10T02:13:47","date_gmt":"2010-02-10T00:13:47","guid":{"rendered":"http:\/\/www.viesurip.fr\/?p=153"},"modified":"2010-02-10T14:08:43","modified_gmt":"2010-02-10T12:08:43","slug":"fusionnerdecouper-des-pdfs-directement-dans-dolphin-kde","status":"publish","type":"post","link":"https:\/\/www.viesurip.fr\/en\/2010\/02\/10\/fusionnerdecouper-des-pdfs-directement-dans-dolphin-kde\/","title":{"rendered":"Merge\/split PDF files directly in Dolphin (KDE)"},"content":{"rendered":"<p><\/p>\n<h3>Context<\/h3>\n<p>I have just switched to KDE after using Gnome during many years, and I am quietly getting used to it.<\/p>\n<p>But recently I had to merge 2 PDF files, so I searched for a good solution for KDE. There are many command-line tools to do this on Linux, but the few graphical interfaces are very ugly.<\/p>\n<p>So I thought it would be great to integrate a merge\/split PDF function directly in Dolphin, the KDE file manager. In dolphin when you right-click on a file, a menu pops up with a sub-menu &#8220;Actions&#8221;, where you can add your features. I will now explain how I did this.<\/p>\n<h3>Prerequisites<\/h3>\n<ul>\n<li>You need to be running a recent version of <strong>KDE<\/strong> (using <strong>Dolphin<\/strong> as your file manager). I have the version 4.3.5.<\/li>\n<li>To manipulate your PDF files, you need a command-line tool, I chose <strong>pdftk<\/strong>. You can install the package pdftk on kubuntu, for example by typing in a terminal:\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo apt-get install pdftk<\/pre>\n<\/li>\n<\/ul>\n<h3>Create scripts to merge\/split PDF files automatically<\/h3>\n<p>I created two scripts: one to merge PDF files, and the other one to split them. I put both files in the directory <strong>\/opt\/pdf-service<\/strong>:<\/p>\n<ul>\n<li><strong>\/opt\/pdf-service\/pdf-service-merge.sh<\/strong> (<a title=\"pdf-service-merge.sh source file\" href=\"http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-service-merge.sh\" target=\"_blank\">download<\/a>):\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#!\/bin\/bash\r\n# Run a command to merge PDF files\r\n# Used to add a context menu in Dolphin for PDF files\r\n\r\npdftk &quot;$@&quot; cat output &quot;${1%.pdf}_merged.pdf&quot;<\/pre>\n<\/li>\n<li><strong>\/opt\/pdf-service\/pdf-service-split.sh<\/strong> (<a title=\"pdf-service-split.sh source file\" href=\"http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-service-split.sh\" target=\"_blank\">download<\/a>):\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#!\/bin\/bash\r\n# Run a command to split PDF files\r\n# Used to add a context menu in Dolphin for PDF files\r\n\r\nfor file in &quot;$@&quot;\r\ndo\r\n   out_dir=&quot;${file%.pdf}_pages&quot;\r\n   mkdir -p &quot;$out_dir&quot;\r\n   pdftk &quot;$file&quot; burst output &quot;$out_dir\/page_%04d.pdf&quot;\r\ndone<\/pre>\n<\/li>\n<\/ul>\n<p>Here are the steps you need to follow to get these files properly on your computer:<\/p>\n<ul>\n<li>Create the \/opt\/pdf-service directory: type in a terminal:\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo mkdir \/opt\/pdf-service<\/pre>\n<\/li>\n<li>Download the two files in the directory: type in a terminal:\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">cd \/opt\/pdf-service &amp;&amp; sudo wget http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-service-split.sh http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-service-merge.sh<\/pre>\n<\/li>\n<li>Make the files executable: type in a terminal:\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">sudo chmod a+x \/opt\/pdf-service\/*.sh<\/pre>\n<\/li>\n<\/ul>\n<h3>Add the service to Dolphin<\/h3>\n<p>A service in Dolphin is declared using a simple .desktop file in the directory <strong>\/usr\/share\/kde4\/services\/ServiceMenus\/<\/strong>: Here is the file you should put as <strong>\/usr\/share\/kde4\/services\/ServiceMenus\/pdf-servicemenu.desktop<\/strong> (<a title=\"pdf-servicemenu.desktop source file\" href=\"http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-servicemenu.desktop\" target=\"_blank\">download<\/a>):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">[Desktop Entry]\r\nType=Service\r\nServiceTypes=KonqPopupMenu\/Plugin\r\nMimeType=application\/pdf\r\nActions=split;merge;\r\n\r\n[Desktop Action split]\r\nName=Split PDF pages\r\nName[fr]=D\u00e9couper les pages du PDF\r\nIcon=gnome-mime-application-pdf\r\nExec=\/opt\/pdf-service\/pdf-service-split.sh %F\r\n\r\n[Desktop Action merge]\r\nName=Merge PDF files\r\nName[fr]=Fusionner les PDFs\r\nIcon=gnome-mime-application-pdf\r\nExec=\/opt\/pdf-service\/pdf-service-merge.sh %F<\/pre>\n<p>To install this file, just type in a terminal:<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">cd \/usr\/share\/kde4\/services\/ServiceMenus &amp;&amp; sudo wget http:\/\/www.viesurip.fr\/wp-content\/uploads\/2010\/02\/pdf-servicemenu.desktop<\/pre>\n<h3>Conclusion<\/h3>\n<p>Now you just need to close all opened windows of Dolphin, launch it again, and you should see the menu entries in the Actions submenu when you right-click on a PDF file.<\/p>\n<p>The entries are only available in English and French in my file, but you can easily add another language in the pdf-servicemenu.desktop file.<\/p>\n<p>It would be great to have an user-friendly interface to install packages that add useful submenu entries like that! Some sorf of Dolphin extensions&#8230;<\/p>","protected":false},"excerpt":{"rendered":"<p>Context I have just switched to KDE after using Gnome during many years, and I am quietly getting used to it. But recently I had to merge 2 PDF files, so I searched for a good solution for KDE. There are many command-line tools to do this on Linux, but the few graphical interfaces are [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[62,63,61,28],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-ubuntu-trucs-sympa","tag-bash","tag-dolphin","tag-kde","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":13,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/posts\/153\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.viesurip.fr\/en\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}