Re: trying to script a command line

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Craig White
Date:  
To: Main PLUG discussion list
Subject: Re: trying to script a command line
pdftk isn't all that friendly towards scripting...I'll say that much.

I am going to work on this tomorrow...but to give you some feedback -
and I appreciate all of the thinking that you did on this..

$ cat I-A-files.txt | sed 's/ /\\ /g' | xargs cat | pdftk - output
I-A.pdf verbose

result, only last pdf in list was inserted in output file

$ cat I-A-files.txt |xargs -i pdftk "{}" cat output I-A.pdf verbose
-sh-3.2$ FILES=`cat file.txt | sed 's/ /\\ /g' |xargs`; pdftk $FILES cat
output I-a.pdf
cat: file.txt: No such file or directory
Error: No input files. Exiting.
Errors encountered. No output created.
Done. Input errors, so no output created.

$ mkdir temp; IFS=$'\n'; for file in `cat I-A-files.txt | sed
's/ /\ /g'`; do cp -v "$file" temp; done; cd temp; pdftk *.pdf cat
output ../I-a.pdf verbose ; unset IFS

This last one sort of worked...It's fixable/workable anyway.

Imagine publishing a book that is 400+ pages all separate Microsoft Word
documents (now being converted to OpenOffice, adding form elements and
then exporting into single page PDF documents...and I'm trying to script
the collection into a single PDF book. Nothing about this has been easy.

Thanks Charles

Craig

On Tue, 2008-03-04 at 20:53 -0700, Charles Jones wrote:
> Ahh yeah...can't believe I didn't think of that. BTW, for pdftk,
> "cat" is a command line option, not referring to the cat we know and
> love.
>
> I think the final ver of the command would be:
>
> cat I-A-files.txt |xargs -i pdftk "{}" cat output I-A.pdf verbose
>
> Okay...my head hurts now :)
>
> -Charles
>
> Erich Newell wrote:
> > xargs has additional flexibility...try using the "replace string"
> > parameter
> >
> > So do:
> >
> > cat list.txt | xargs -i cat "{}" | pdftk output -
> >
> > The curly braces indicate where the input goes...in this case,
> > between the quotes. Should handle those pesky spaces for you.
> >
> > Looks like this will dump a ton of pdf content to stdout....is that
> > what you really want?
> >
> >
> >
> >
> > On Tue, Mar 4, 2008 at 7:22 PM, Craig White <>
> > wrote:
> >         Again, that works but it fails because the PDF includes on
> >         the last file. As I said, I don't think an xargs thing is
> >         going to work at all because as the man page states...the
> >         '-' option is to pass only a single file via stdin.

> >
> >         Craig

> >
> >         On Tue, 2008-03-04 at 19:10 -0700, Charles Jones wrote:
> >         > Ah those darn spaces sure cause problems :)  Give this a
> >         try:
> >         >
> >         > $ cat I-A-files.txt | sed 's/ /\\ /g' | xargs cat | pdftk
> >         - output
> >         > I-a.pdf verbose

> >         >
> >         > It works for my test case:
> >         > $ cat file.txt
> >         > file with spaces
> >         > some other file

> >         >
> >         > $ cat "file with spaces"
> >         > This is the contents of a file with spaces
> >         > $ cat some\ other\ file
> >         > This is some other file

> >         >
> >         > $ cat file.txt | sed 's/ /\\ /g' |xargs cat
> >         > This is the contents of a file with spaces
> >         > This is some other file

> >         >
> >         > Probably a more elegant way to do it, but I'm late for
> >         dinner :-)

> >         >
> >         > -Charles

> >         >

> >         >
> >         > Craig White wrote:
> >         > > That doesn't seem to work. I quoted the part of the man
> >         page that the
> >         > > '-' is used to pass only a single PDF into pdftk via
> >         stdin and thus the
> >         > > xargs thing seems not to fly.

> >         > >
> >         > > $ cat I-A-files.txt | xargs -0 pdftk cat output I-A.pdf
> >         verbose
> >         > > Error: No input files.  Exiting.
> >         > > Errors encountered.  No output created.
> >         > > Done.  Input errors, so no output created.

> >         > >
> >         > > Thanks

> >         > >
> >         > > Craig

> >         > >
> >         > > On Tue, 2008-03-04 at 17:24 -0700, Charles Jones wrote:

> >         > >
> >         > >> Give this a try:

> >         > >>
> >         > >> cat /path/to/filenames_file.xt |xargs pdftk

> >         > >>
> >         > >> -Charles

> >         > >>
> >         > >> Craig White wrote:

> >         > >>
> >         > >>> I have an awkward situation with pdftk

> >         > >>>
> >         > >>> I have a file with filenames that I want to pass to
> >         pdftk as input
> >         > >>> files.

> >         > >>>
> >         > >>> according to the man page...
> >         > >>> <input PDF files | - | PROMPT>
> >         > >>>   A list of the input PDF files. If you plan to
> >         combine these PDFs
> >         > >>>   (without using handles) then list files in the
> >          order  you  want
> >         > >>>   them combined.  Use - to pass a single PDF into
> >         pdftk via stdin.

> >         > >>>
> >         > >>> and thus, this doesn't work...

> >         > >>>
> >         > >>> pdftk `cat "/mypath/to/I-A-files.txt"` cat output
> >         I-A.pdf verbose

> >         > >>>
> >         > >>> fails on spaces within the paths/filenames in that
> >         file.

> >         > >>>
> >         > >>> I have tried both escaping the spaces with \ and
> >         enclosing each path
> >         > >>> within a double quote but neither works.

> >         > >>>
> >         > >>> I have also tried (which fails)...

> >         > >>>
> >         > >>> $ cat "/mypath/to/I-A-files.txt" | pdftk - cat output
> >         I-A.pdf verbose
> >         > >>> Error: Failed to open PDF file:
> >         > >>>    -
> >         > >>> Errors encountered.  No output created.
> >         > >>> Done.  Input errors, so no output created.
> >         > >>> sh-3.2$ ls -l
> >         > >>> total 4440
> >         > >>> -rw-r--r-- 1 craig administrative      10 2008-03-04
> >         15:15 doc_toc.html
> >         > >>> -rw-r--r-- 1 craig administrative    1898 2008-03-04
> >         15:30 I-A-files.txt

> >         > >>>
> >         > >>> Any suggestions on this?

> >         > >>>
> >         > >>> T
> >         > > ---------------------------------------------------
> >         > > PLUG-discuss mailing list -
> >         
> >         > > To subscribe, unsubscribe, or to change your mail
> >         settings:

> >         > >
> >         http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

> >         > >

> >         >
> >         > ---------------------------------------------------
> >         > PLUG-discuss mailing list -
> >         
> >         > To subscribe, unsubscribe, or to change your mail
> >         settings:

> >         >
> >         http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

> >
> >         ---------------------------------------------------
> >         PLUG-discuss mailing list -
> >         
> >         To subscribe, unsubscribe, or to change your mail settings:
> >         http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

> >
> >
> >
> >
> > --
> > "A man is defined by the questions that he asks; and the way he goes
> > about finding the answers to those questions is the way he goes
> > through life."
> >
> > ____________________________________________________________________
> >
> > ---------------------------------------------------
> > PLUG-discuss mailing list -
> > To subscribe, unsubscribe, or to change your mail settings:
> > http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss