1

I like to read pdf with less command lately. less file.pdf

Would like to read a pdf book which is two columns format. There should be a command to output in one column, right?

Note: For each page changes with ^L

Something like pipe with awk? Would not mind to use vi or any other command.

Format example

                                                                9
^LAgradecimientos                                                                                                         Agradecimientos

maciones de la psiquiatría y la ciencia tradicional de Occi-           do al poder contar con la amistad personal de muchos de los
dente.                                                                 pioneros de este nuevo abordaje psicológico. Estas personas
   También debo agradecer el aliento y el apoyo de varios físi-        tan especiales han sido durante muchos años una fuente de ins-
xhienne
  • 5,738
  • 1
  • 15
  • 34
Cristo
  • 700
  • 1
  • 8
  • 20
  • I'm trying to find the code like pdf2text | split by ^L | awk colum ? – Cristo Jul 09 '20 at 19:24
  • 1
    [edit] your question to contain all relevant information including a [mcve] with concise, testable sample input, expected output and what you've tried so far to solve the problem yourself. Again, see [ask]. – Ed Morton Jul 09 '20 at 19:26

1 Answers1

1

Here's a start:

$ cat tst.sh
#!/usr/bin/env bash

awk -v ff='\f' -F'\n' '
    s = index($0,ff) {
        prt()
        indent = s - 1
        width  = length($0) - indent
        midway = int(width / 2)
        next
    }
    indent { sub("^ {"indent"}","") }
    /[^[:space:]]/ {
        left  = left substr($0,1,midway) ORS
        right = right substr($0,midway+indent) ORS
    }
    END { prt() }

    function prt() {
        printf "%s", left
        printf "%s", right

        left = right = ""
    }
' "${@:--}"

.

$ ./tst.sh file

                                                                    9
maciones de la psiquiatría y la ciencia tradicional de Occi-
dente.
   También debo agradecer el aliento y el apoyo de varios físi-
do al poder contar con la amistad personal de muchos de los
pioneros de este nuevo abordaje psicológico. Estas personas
tan especiales han sido durante muchos años una fuente de ins-

Try to enhance that to fully work for you and then post a new question if you aren't able to and have any specific questions.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • 1
    This was perfect, Mr. Morton. I did: pdftotext "mente.pdf" -layout then ./reader.sh mente.txt | less This was just too much beyond my bash skills. Thanks. – Cristo Jul 09 '20 at 22:22
  • You're welcome but to be clear that's an awk script not a bash script (other than the wrapper to call awk which I provided in case you wanted to make it `pdf2text | awk ...` or similar). – Ed Morton Jul 09 '20 at 22:25
  • Actually, my idea was a one liner in terminal, yes. But if it does the job I don't care about the tool or language. – Cristo Jul 10 '20 at 07:54