<!doctypehtml><html lang=en><meta content="text/html; charset=utf-8"http-equiv=Content-Type><meta content="These examples show you how to perform common PDF tasks from the command-line using pdftk."name=description><meta content=width=device-width,initial-scale=1.0 name=viewport><link href=/s/default.css media=all rel=stylesheet title=default><link media="only screen and (max-width: 950px)"href=/s/narrow.css rel=stylesheet title=default><link media="print, only screen and (max-width: 700px)"href=/s/mobile.css rel=stylesheet title=default><link href=/s/print.css media=print rel=stylesheet title=default><title>
   PDFtk Server Examples
  </title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-6028337-3', 'auto');
  ga('set', 'anonymizeIp', true); // for GDPR per: https://support.google.com/analytics/answer/9019185?hl=en
  ga('send', 'pageview');</script><body><div id=container1><header class=col_half id=site_head><h1><a href=/> <span id=site_logo> </span> PDF Labs </a></h1></header><hr id=top_hr><article class=col_half><header><h2>PDFtk Server Examples</h2><div class=synopsis><p>These examples show you how to perform common PDF tasks from the command-line using pdftk.</div></header><aside class=hl><p style="text-align: center; font-size: larger"><b> Looking for a friendly Windows GUI? <br> Try our <a href=/tools/pdftk-the-pdf-toolkit/> PDFtk Free </a> ! </b></aside><p>Collate scanned pages<blockquote><p><code>
       pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
      </code></blockquote><p>   or if odd.pdf is in reverse order:<blockquote><p><code>
       pdftk A=even.pdf B=odd.pdf shuffle A Bend-1 output collated.pdf
      </code></blockquote><p>Decrypt a PDF<blockquote><p><code>
       pdftk secured.pdf input_pw foopass output unsecured.pdf
      </code></blockquote><p>Encrypt a PDF using 128-bit strength (the default), withhold all permissions (the default)<blockquote><p><code>
       pdftk 1.pdf output 1.128.pdf owner_pw foopass
      </code></blockquote><p>Same as above, except password <i> baz </i> must also be used to open output PDF<blockquote><p><code>
       pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz
      </code></blockquote><p>Same as above, except printing is allowed (once the PDF is open)<blockquote><p><code>
       pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing
      </code></blockquote><p>Join in1.pdf and in2.pdf into a new PDF, out1.pdf<blockquote><p><code>
       pdftk in1.pdf in2.pdf cat output out1.pdf
      </code></blockquote><p>   or (using handles):<blockquote><p><code>
       pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf
      </code></blockquote><p>   or (using wildcards):<blockquote><p><code>
       pdftk *.pdf cat output combined.pdf
      </code></blockquote><p>Remove page 13 from in1.pdf to create out1.pdf<blockquote><p><code>
       pdftk in.pdf cat 1-12 14-end output out1.pdf
      </code></blockquote><p>   or:<blockquote><p><code>
       pdftk A=in1.pdf cat A1-12 A14-end output out1.pdf
      </code></blockquote><aside class=hl><p>When using the Windows command-prompt, it helps to use drag-and-drop from the file manager: drag the input PDF file from the file manager onto the command-prompt, and its full pathname will appear at the prompt.</aside><p>Apply 40-bit encryption to output, revoking all permissions (the default). Set the owner PW to <i> foopass </i> .<blockquote><p><code>
       pdftk 1.pdf 2.pdf cat output 3.pdf encrypt_40bit owner_pw foopass
      </code></blockquote><p>Join two files, one of which requires the password <i> foopass </i> . The output is not encrypted.<blockquote><p><code>
       pdftk A=secured.pdf 2.pdf input_pw A=foopass cat output 3.pdf
      </code></blockquote><p>Uncompress PDF page streams for editing the PDF in a text editor (e.g., vim, emacs)<blockquote><p><code>
       pdftk doc.pdf output doc.unc.pdf uncompress
      </code></blockquote><p>Repair a PDF’s corrupted XREF table and stream lengths, if possible<blockquote><p><code>
       pdftk broken.pdf output fixed.pdf
      </code></blockquote><p>Burst a single PDF document into pages and dump its data to doc_data.txt<blockquote><p><code>
       pdftk in.pdf burst
      </code></blockquote><p>Burst a single PDF document into encrypted pages. Allow low-quality printing<blockquote><p><code>
       pdftk in.pdf burst owner_pw foopass allow DegradedPrinting
      </code></blockquote><p>Write a report on PDF document metadata and bookmarks to report.txt<blockquote><p><code>
       pdftk in.pdf dump_data output report.txt
      </code></blockquote><p>Rotate the first PDF page to 90 degrees clockwise<blockquote><p><code>
       pdftk in.pdf cat 1east 2-end output out.pdf
      </code></blockquote><p>Rotate an entire PDF document to 180 degrees<blockquote><p><code>
       pdftk in.pdf cat 1-endsouth output out.pdf
      </code></blockquote><p><i> Article Author: Sid Steward </i><h3>Notes</h3><p>Pdftk is a command-line program, so you should use your computer terminal or command prompt when first testing these examples.<nav class=article_nav><h3>Related Articles</h3><ul><li><p><a href=/tools/pdftk-the-pdf-toolkit/> PDFtk - The PDF Toolkit </a></p><li><p><a href=/docs/pdftk-man-page/> PDFtk Server Manual </a></p><li><p><a href=/docs/pdftk-license/> PDFtk Server License </a></p><li><p><a href=/docs/pdftk-version-history/> PDFtk Version History </a></p></ul><h3>Article Tags</h3><ul><li><p><a href=/t/pdftk/> pdftk </a></p><li><p><a href=/t/cli/> cli </a></p></ul></nav><hr></article><div id=container2><nav class=col_qtr><h2>Navigation</h2><h3>Site Categories</h3><ul class=links><li><h3><a href=/tools/> Tools </a></h3> <ul><li><a href=/tools/pdftk-the-pdf-toolkit/> PDFtk - The PDF Toolkit </a><li><a href=/tools/pdftk-pro/> PDFtk Pro </a><li><a href=/tools/pdftk-server/> PDFtk Server </a><li><a href=/tools/stamptk-the-pdf-stamp-maker/> STAMPtk - The PDF Stamp Maker </a><li><a href=/tools/gnu-barcode-plus-pdf/> GNU Barcode Plus PDF </a></ul><li><h3><a href=/docs/> Docs </a></h3> <ul><li><a href=/docs/pdftk-pro-guide/> Guide to PDFtk Pro </a><li><a href=/docs/pdftk-man-page/> PDFtk Server Manual </a><li><a href=/docs/pdftk-cli-examples/> PDFtk Server Examples </a><li><a href=/docs/pdftk-license/> PDFtk Server License </a><li><a href=/docs/pdftk-version-history/> PDFtk Version History </a><li><a href=/docs/stamptk-manual/> STAMPtk Manual </a><li><a href=/docs/install-pdftk-on-redhat-or-centos/> Install PDFtk on Red Hat or CentOS </a><li><a href=/docs/how-to-add-headers-footers-watermarks-and-stamps-to-pdf/> How to Add Headers, Footers, Watermarks and Stamps to PDF </a></ul><li><h3><a href=/blog/> Blog </a></h3> <ul><li><a href=/blog/how-to-collate-even-odd-scanned-pages/> How to Collate Even and Odd Scanned PDF Pages </a><li><a href=/blog/export-and-import-pdf-bookmarks/> How to Export and Import PDF Bookmarks </a><li><a href=/blog/enjoy-photos-on-nook-or-kindle-using-pdf-albums/> How to Create Photo Albums for Nook or Kindle </a></ul><li><h3><a href=/company/> Company </a></h3> <ul><li><a href=/company/contact/> Contact PDF Labs </a><li><a href=/company/testimonials/> What People Say </a></ul></ul><h3>Site Tags</h3><ul class=links><li><p><a href=/t/pdftk/> pdftk </a></p><li><p><a href=/t/gui/> gui </a></p><li><p><a href=/t/stamptk/> stamptk </a></p><li><p><a href=/t/cli/> cli </a></p><li><p><a href=/t/barcode/> barcode </a></p><li><p><a href=/t/bookmarks/> bookmarks </a></p><li><p><a href=/t/imagemagick/> imagemagick </a></p><li><p><a href=/t/red%20hat/> red hat </a></p><li><p><a href=/t/centos/> centos </a></p><li><p><a href=/t/rpm/> rpm </a></p></ul><hr></nav><aside class=col_qtr><h2>About PDF Labs</h2><p>Our mission is to make PDF easier to use.<p>PDF Labs is operated by Sid Steward, author of <a href=http://www.amazon.com/exec/obidos/ASIN/0596006551/ref=nosim/pdftk-20> <i> PDF Hacks </i> (O’Reilly) </a> and the popular <a href=http://www.pdftk.com> PDF Toolkit </a> .<p>Please contact Sid Steward by email. Include <i> PDF Labs </i> in the subject to ensure prompt delivery:</p><script><!--
var e0= "si";
var e1= "d\x2e";
var e2= "st";
var e3= "ew";
var e4= "ar";
var e5= "d\x40";
var e6= "pd";
var e7= "fl";
var e8= "ab";
var e9= "s\x2e";
var ea= "co";
var eb= "m";
document.write( "\x3cp\x3e\x3ca href="+ "mai"+ "lto\x3a"+ e0+ e1+ e2+ e3+ e4+ e5+ e6+ e7+ e8+ e9+ ea+ eb+ "\x3fsubject\x3dPDF\x2520Labs"+ "\x3e"+ e0+ e1+ e2+ e3+ e4+ e5+ e6+ e7+ e8+ e9+ ea+ eb+ "\x3c/a\x3e\x3c/p\x3e");
//--></script><noscript><p><img alt=email height=17 src=/s/eee.gif width=172></p></noscript><hr><h2>About PDF Hacks</h2><div><a href=http://www.amazon.com/exec/obidos/ASIN/0596006551/ref=nosim/pdftk-20> <img alt="PDF Hacks Cover"height=225 src=/s/pdf_hacks.png width=160> </a></div><p>"If you like pdftk, then you’ll appreciate the other 25 programs and scripts I created for my book, <a href=http://shop.oreilly.com/product/9780596006556.do> PDF Hacks </a> ." –Sid<hr><h2>About PDFtk</h2><p>For ten years, power users have relied on PDFtk for server-side processing of PDF documents. Our command-line PDFtk has been — and always will be — free (as in freedom) software.<p>Today we also offer a convenient graphical application: <a href=/tools/pdftk-pro/> PDFtk Pro </a> . Your purchase of PDFtk Pro will help fund the continued development of our GPL PDFtk.<p>Thank you for your support!<hr></aside></div><footer class=col_half id=foot><p>Copyright © 2004–2020 Steward and Lee, LLC</footer></div>