Read pdf on terminal output 2 columns to one

257 Views Asked by At

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-
1

There are 1 best solutions below

3
On BEST ANSWER

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.