Pdf Manipulation and Hints

Reference: http://www.pdflabs.com/docs/pdftk-cli-examples/

Collate scanned pages

pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf

or if odd.pdf is in reverse order:

pdftk A=even.pdf B=odd.pdf shuffle A Bend-1 output collated.pdf

Decrypt a PDF

pdftk secured.pdf input_pw foopass output unsecured.pdf

Encrypt a PDF using 128-bit strength (the default), withhold all permissions (the default)

pdftk 1.pdf output 1.128.pdf owner_pw foopass

Same as above, except password baz must also be used to open output PDF

pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz

Same as above, except printing is allowed (once the PDF is open)

pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing

Join in1.pdf and in2.pdf into a new PDF, out1.pdf

pdftk in1.pdf in2.pdf cat output out1.pdf

or (using handles):

pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf

or (using wildcards):

pdftk *.pdf cat output combined.pdf

Remove page 13 from in1.pdf to create out1.pdf

pdftk in.pdf cat 1-12 14-end output out1.pdf

or:

pdftk A=in1.pdf cat A1-12 A14-end output out1.pdf

Apply 40-bit encryption to output, revoking all permissions (the default). Set the owner PW to foopass.

pdftk 1.pdf 2.pdf cat output 3.pdf encrypt_40bit owner_pw foopass

Join two files, one of which requires the password foopass. The output is not encrypted.

pdftk A=secured.pdf 2.pdf input_pw A=foopass cat output 3.pdf

Uncompress PDF page streams for editing the PDF in a text editor (e.g., vim, emacs)

pdftk doc.pdf output doc.unc.pdf uncompress

Repair a PDF’s corrupted XREF table and stream lengths, if possible

pdftk broken.pdf output fixed.pdf

Burst a single PDF document into pages and dump its data to doc_data.txt

pdftk in.pdf burst

Burst a single PDF document into encrypted pages. Allow low-quality printing

pdftk in.pdf burst owner_pw foopass allow DegradedPrinting

Write a report on PDF document metadata and bookmarks to report.txt

pdftk in.pdf dump_data output report.txt

Rotate the first PDF page to 90 degrees clockwise

pdftk in.pdf cat 1east 2-end output out.pdf

Rotate an entire PDF document to 180 degrees

pdftk in.pdf cat 1-endsouth output out.pdf

 

Centos 6 Build

Build goes here

Install python2.7 without breaking Centos internals. (link)

sudo yum update # update yum 
sudo yum install centos-release-scl # install SCL
sudo yum install python27 # install Python 2.7
scl enable python27 bash
cd /opt/rh/python27/root/usr/bin/ # cd to the directory where SCL installs python 
sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./easy_install-2.7 pip
sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./pip2.7 install requests

Note that using the SCL python2.7 is not as straight forward as it should be. (link)

 

If using “Let’s Encrypt” then you’ll need to update to python 2.7

Windows Batch Script Notes

For the folder name and drive, you can use:

echo %~dp0 

You can get a lot more information using different modifiers:

%~I - expands %I removing any surrounding quotes (") 
%~fI - expands %I to a fully qualified path name 
%~dI - expands %I to a drive letter only 
%~pI - expands %I to a path only 
%~nI - expands %I to a file name only 
%~xI - expands %I to a file extension only 
%~sI - expanded path contains short names only 
%~aI - expands %I to file attributes of file 
%~tI - expands %I to date/time of file 
%~zI - expands %I to size of file The modifiers can be combined to get compound results: 
%~dpI - expands %I to a drive letter and path only 
%~nxI - expands %I to a file name and extension only 
%~fsI - expands %I to a full path name with short names only 

This is a copy paste from the “for /?” command on the prompt. Hope it helps.

Related

Top 10 DOS Batch tips (Yes, DOS Batch…) shows batchparams.bat (link to source as a gist):

C:\Temp>batchparams.bat c:\windows\notepad.exe 
%~1 = c:\windows\notepad.exe 
%~f1 = c:\WINDOWS\NOTEPAD.EXE 
%~d1 = c: 
%~p1 = \WINDOWS\ 
%~n1 = NOTEPAD 
%~x1 = .EXE 
%~s1 = c:\WINDOWS\NOTEPAD.EXE 
%~a1 = --a------ 
%~t1 = 08/25/2005 01:50 AM 
%~z1 = 17920 %~$PATHATH:1 = 
%~dp1 = c:\WINDOWS\ 
%~nx1 = NOTEPAD.EXE 
%~dp$PATH:1 = c:\WINDOWS\ 
%~ftza1 = --a------ 08/25/2005 01:50 AM 17920 c:\WINDOWS\NOTEPAD.EXE

Page archived on 7/19/2012 from here.

 

 

 

Sky Drive

It’s 25 gb of free online storage. This isn’t a backup, since there is no file history but it is a decent off-site for non private data.

Sky Drive
If you run under linux there is a process for using it with some limitations, and you have to have mono installed on the system.  Here are the instructions for getting it to work.  And here is where the project to run under linux.