{"id":539,"date":"2015-05-28T12:08:32","date_gmt":"2015-05-28T09:08:32","guid":{"rendered":"http:\/\/www.bashpi.org\/?page_id=539"},"modified":"2021-02-17T09:34:07","modified_gmt":"2021-02-17T07:34:07","slug":"manipulating-pdf-with-linux-commandline-tools","status":"publish","type":"page","link":"https:\/\/www.bashpi.org\/?page_id=539","title":{"rendered":"Manipulating pdf with Linux commandline tools"},"content":{"rendered":"<p>Few useful tips for manipulating pdf files. Useful if you just want to change few files without installing fancy software with GUI or if you want to make batch jobs.<\/p>\n<ul>\n<li>Merge multiple pdf files into one pdf file<\/li>\n<\/ul>\n<p>Can be done with <em>pdfunite<\/em> tool (package: poppler-utils)<\/p>\n<pre><code class=\"language-bash\">pdfunite inputfileX.pdf inputfileY.pdf inputfileZ.pdf Outputfile.pdf<\/code><\/pre>\n<p>Merging can be done also with <em>pdftk<\/em> (package: pdftk )<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf inputfileY.pdf inputfileZ.pdf output Outputfile.pdf<\/code><\/pre>\n<ul>\n<li>Split pdf file into pages<\/li>\n<\/ul>\n<p>This will split input pdf &#8211; stores each page into separate file named pg_0001.pdf, pg_0002.pdf, etc.<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf burst<\/code><\/pre>\n<p>This will split input pdf &#8211; stores each page into separate file named page_0001.pdf, page_0002.pdf, etc.<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf burst output page_%04d.pdf<\/code><\/pre>\n<p>This will split input pdf and stores only specific pages into single new file.<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf cat 1 2 3 4 9 10 output Outputfile.pdf\nor\npdftk inputfileX.pdf cat 1-4 9-10 output Outputfile.pdf<\/code><\/pre>\n<ul>\n<li>Rotate pdf file<\/li>\n<\/ul>\n<p>Use pdftk. From pdftk man page: Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page&#8217;s rotation.<\/p>\n<p>This will rotate only page one 90 degrees, page two 270 degrees and leaves all other pages unchanged.<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf rotate 1east 2west output Outputfile.pdf<\/code><\/pre>\n<p>This will extract specific pages, rotates them and stores them in different order (4-3-2-1) into single new file.<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf cat 4east 3south 2west 1left output Outputfile.pdf<\/code><\/pre>\n<p>This will rotate entire input document 90 degrees clockwise .<\/p>\n<pre><code class=\"language-bash\">pdftk inputfileX.pdf cat 1-endright output Outputfile.pdf\nor\npdftk inputfileX.pdf rotate 1-endright output Outputfile.pdf<\/code><\/pre>\n<ul>\n<li>Embed file to pdf<\/li>\n<\/ul>\n<p>Use pdftk. pdfdk allows you embed\/attach file to existing pdf and you can also choose on which page embed file is shown. File is &#8220;shown&#8221; as a special bullet on a side, which allows you to extract\/download the attachment.<\/p>\n<pre><code class=\"language-bash\">pdftk original_pdf_file.pdf attach_files attachment.doc to_page 1 output new_pdf_with_attachment.pdf<\/code><\/pre>\n<ul>\n<li>List and extract embed files from pdf<\/li>\n<\/ul>\n<p>For listing embed files use pdfdetach<\/p>\n<pre><code class=\"language-bash\">pdfdetach -list new_pdf_with_attachment.pdf  \n1 embedded files \n1: attachment.doc<\/code><\/pre>\n<p>To extract embed files you can use pdftk or pdfdetach<\/p>\n<pre><code class=\"language-bash\"># extract all files\npdftk new_pdf_with_attachment.pdf unpack_files\npdfdetach -saveall new_pdf_with_attachment.pdf\n\n# extract first embed file and save it as attachment.doc\npdfdetach -save 1 -o attachment.doc new_pdf_with_attachment.pdf<\/code><\/pre>\n<p>If you found this useful, say thanks, click on some banners or <a href=\"http:\/\/www.bashpi.org\/?page_id=105\">donate<\/a>, I can always use some beer money.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Few useful tips for manipulating pdf files. Useful if you just want to change few files without installing fancy software with GUI or if you want to make batch jobs. Merge multiple pdf files into one pdf file Can be done with pdfunite tool (package: poppler-utils) pdfunite inputfileX.pdf inputfileY.pdf inputfileZ.pdf Outputfile.pdf Merging can be done [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":397,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-539","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=539"}],"version-history":[{"count":6,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/539\/revisions"}],"predecessor-version":[{"id":1207,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/539\/revisions\/1207"}],"up":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/397"}],"wp:attachment":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}